Skip to content
Browse files

Added logger support

  • Loading branch information...
1 parent bd4d021 commit be42c7a408a17c014afddc10fd6d6333e5b3aa8d @AndrewO AndrewO committed Sep 20, 2011
View
6 lib/active_shipping/shipping/base.rb
@@ -1,3 +1,6 @@
+require 'logger'
+require 'forwardable'
+
module ActiveMerchant
module Shipping
module Base
@@ -8,6 +11,9 @@ def self.carrier(name)
ActiveMerchant::Shipping::Carriers.all.find {|c| c.name.downcase == name.to_s.downcase} ||
raise(NameError, "unknown carrier #{name}")
end
+
+ mattr_accessor :logger
+ self.logger = Logger.new(STDERR)
end
end
end
View
3 lib/active_shipping/shipping/carrier.rb
@@ -48,6 +48,9 @@ def maximum_weight
end
protected
+ def logger
+ Base.logger
+ end
def node_text_or_nil(xml_node)
xml_node ? xml_node.text : nil
View
20 lib/active_shipping/shipping/carriers/ups.rb
@@ -119,18 +119,24 @@ def generate_label(origin, destination, packages, options = {})
options = @options.merge(options)
ship_confirm_response = do_ship_confirm(origin, destination, packages, options)
xml = REXML::Document.new(ship_confirm_response)
+ logger.debug("#{self.class.to_s}#generate_label: ship confirm response: #{ship_confirm_response}")
success = response_success?(xml)
- if not success
- warn(ship_confirm_response)
+ if success
+ logger.debug("#{self.class.to_s}#generate_label: ship confirm request was successful")
+ else
+ logger.warn(ship_confirm_response)
raise xml.get_text('ShipmentConfirmResponse/Response/Error/ErrorDescription').to_s
end
-
+
ship_accept_response = do_ship_accept(ship_confirm_response, options)
xml = REXML::Document.new(ship_accept_response)
+ logger.debug("#{self.class.to_s}#generate_label: ship accept response: #{ship_accept_response}")
success = response_success?(xml)
message = response_message(xml)
- if not success
- warn(ship_accept_response)
+ if success
+ logger.debug("#{self.class.to_s}#generate_label: ship accept request was successful: #{message}")
+ else
+ logger.warn(ship_accept_response)
raise xml.get_text('ShipmentConfirmResponse/Response/Error/ErrorDescription').to_s
end
@@ -144,12 +150,16 @@ def do_ship_confirm(origin, destination, packages, options)
options = @options.update(options)
packages = Array(packages)
label_request = build_access_request + build_label_request(origin, destination, packages, options)
+ logger.debug("#{self.class.to_s}#do_ship_confirm label_request: #{label_request}")
+
commit(:label_request, label_request, (options[:test] || false))
end
def do_ship_accept(ship_confirm_response, options)
digest = parse_label_response(ship_confirm_response, options)
label_accept_request = build_label_accept_request(digest, options)
+ logger.debug("#{self.class.to_s}#do_ship_accept label_accept_request: #{label_accept_request}")
+
commit(:label_accept, save_request(build_access_request + label_accept_request), (options[:test] || false))
end

0 comments on commit be42c7a

Please sign in to comment.
Something went wrong with that request. Please try again.