Skip to content

Commit

Permalink
Add the ability to get more logging when doing status requests by pas…
Browse files Browse the repository at this point in the history
…sing in a logger
  • Loading branch information
jeffrafter committed Apr 11, 2012
1 parent f210a61 commit 793c14a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
17 changes: 17 additions & 0 deletions lib/endicia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module HTTParty
class Request
alias_method :parse_response_without_hack, :parse_response
def parse_response(body)
Rails.logger.info("RESPONSE>")
Rails.logger.info(body)
Rails.logger.info("<RESPONSE")

parse_response_without_hack(
body.sub(/xmlns=("|')(www.envmgr.com|LabelServer.Endicia.com)/, 'xmlns=\1https://\2'))
end
Expand Down Expand Up @@ -207,6 +211,13 @@ def self.status_request(tracking_number, options = {})
xml.StatusList { |xml| xml.PICNumber(tracking_number) }
end

if options[:logger]
options[:logger].info("ENDICIA REQUEST: #{tracking_number}")
options[:logger].info("\n[REQUEST]")
options[:logger].info(xml)
options[:logger].info("[ENDREQUEST]")
end

params = { :method => 'StatusRequest', :XMLInput => URI.encode(xml) }
result = self.get(els_service_url(params))
response_body = result.body
Expand All @@ -218,6 +229,12 @@ def self.status_request(tracking_number, options = {})
:response_body => response_body
}

if options[:logger]
options[:logger].info("\n[RESPONSE]")
options[:logger].info(xml)
options[:logger].info("[ENDRESPONSE]")
end

# TODO: It is possible to make a batch status request, currently this only
# supports one at a time. The response that comes back is not parsed
# well by HTTParty. So we have to assume there is only one tracking
Expand Down

0 comments on commit 793c14a

Please sign in to comment.