lib/active_shipping/carriers/fedex.rb in active_shipping-1.9.2 vs lib/active_shipping/carriers/fedex.rb in active_shipping-1.10.1
- old
+ new
@@ -588,26 +588,46 @@
success = response_success?(xml)
message = response_message(xml)
if success
- origin = nil
+ tracking_details_root = xml.at('CompletedTrackDetails')
+ success = response_success?(tracking_details_root)
+ message = response_message(tracking_details_root)
+ end
+
+ if success
delivery_signature = nil
shipment_events = []
all_tracking_details = xml.root.xpath('CompletedTrackDetails/TrackDetails')
tracking_details = case all_tracking_details.length
when 1
all_tracking_details.first
when 0
- raise ActiveShipping::Error, "The response did not contain tracking details"
+ message = "The response did not contain tracking details"
+ return TrackingResponse.new(
+ false,
+ message,
+ Hash.from_xml(response),
+ carrier: @@name,
+ xml: response,
+ request: last_request
+ )
else
all_unique_identifiers = xml.root.xpath('CompletedTrackDetails/TrackDetails/TrackingNumberUniqueIdentifier').map(&:text)
- raise ActiveShipping::Error, "Multiple matches were found. Specify a unqiue identifier: #{all_unique_identifiers.join(', ')}"
+ message = "Multiple matches were found. Specify a unqiue identifier: #{all_unique_identifiers.join(', ')}"
+ return TrackingResponse.new(
+ false,
+ message,
+ Hash.from_xml(response),
+ carrier: @@name,
+ xml: response,
+ request: last_request
+ )
end
-
first_notification = tracking_details.at('Notification')
severity = first_notification.at('Severity').text
if severity == 'ERROR' || severity == 'FAILURE'
message = first_notification.try(:text)
code = first_notification.at('Code').try(:text)
@@ -632,15 +652,15 @@
if status_code == 'DL' && tracking_details.at('AvailableImages').try(:text) == 'SIGNATURE_PROOF_OF_DELIVERY'
delivery_signature = tracking_details.at('DeliverySignatureName').try(:text)
end
end
- if origin_node = tracking_details.at('OriginLocationAddress')
- origin = Location.new(
- :country => origin_node.at('CountryCode').text,
- :province => origin_node.at('StateOrProvinceCode').text,
- :city => origin_node.at('City').text
+ origin = if origin_node = tracking_details.at('OriginLocationAddress')
+ Location.new(
+ country: origin_node.at('CountryCode').text,
+ province: origin_node.at('StateOrProvinceCode').text,
+ city: origin_node.at('City').text
)
end
destination = extract_address(tracking_details, DELIVERY_ADDRESS_NODE_NAMES)
shipper_address = extract_address(tracking_details, SHIPPER_ADDRESS_NODE_NAMES)
@@ -665,30 +685,33 @@
time = Time.parse(event.at('Timestamp').text)
zoneless_time = time.utc
shipment_events << ShipmentEvent.new(description, zoneless_time, location, description, type_code)
end
- shipment_events = shipment_events.sort_by(&:time)
+ shipment_events = shipment_events.sort_by(&:time)
end
- TrackingResponse.new(success, message, Hash.from_xml(response),
- :carrier => @@name,
- :xml => response,
- :request => last_request,
- :status => status,
- :status_code => status_code,
- :status_description => status_description,
- :ship_time => ship_time,
- :scheduled_delivery_date => scheduled_delivery_time,
- :actual_delivery_date => actual_delivery_time,
- :delivery_signature => delivery_signature,
- :shipment_events => shipment_events,
- :shipper_address => (shipper_address.nil? || shipper_address.unknown?) ? nil : shipper_address,
- :origin => origin,
- :destination => destination,
- :tracking_number => tracking_number
+ TrackingResponse.new(
+ success,
+ message,
+ Hash.from_xml(response),
+ carrier: @@name,
+ xml: response,
+ request: last_request,
+ status: status,
+ status_code: status_code,
+ status_description: status_description,
+ ship_time: ship_time,
+ scheduled_delivery_date: scheduled_delivery_time,
+ actual_delivery_date: actual_delivery_time,
+ delivery_signature: delivery_signature,
+ shipment_events: shipment_events,
+ shipper_address: (shipper_address.nil? || shipper_address.unknown?) ? nil : shipper_address,
+ origin: origin,
+ destination: destination,
+ tracking_number: tracking_number
)
end
def ship_timestamp(delay_in_hours)
delay_in_hours ||= 0
@@ -699,16 +722,16 @@
delay_in_hours ||= 0
(Time.now + delay_in_hours.hours).to_date
end
def response_success?(document)
- highest_severity = document.root.at('HighestSeverity')
+ highest_severity = document.at('HighestSeverity')
return false if highest_severity.nil?
%w(SUCCESS WARNING NOTE).include?(highest_severity.text)
end
def response_message(document)
- notifications = document.root.at('Notifications')
+ notifications = document.at('Notifications')
return "" if notifications.nil?
"#{notifications.at('Severity').text} - #{notifications.at('Code').text}: #{notifications.at('Message').text}"
end