814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
# File 'lib/active_shipping/carriers/ups.rb', line 814
def parse_rate_response(origin, destination, packages, response, options = {})
xml = build_document(response, 'RatingServiceSelectionResponse')
success = response_success?(xml)
message = response_message(xml)
if success
rate_estimates = xml.root.css('> RatedShipment').map do |rated_shipment|
service_code = rated_shipment.at('Service/Code').text
days_to_delivery = rated_shipment.at('GuaranteedDaysToDelivery').text.to_i
days_to_delivery = nil if days_to_delivery == 0
warning_messages = rate_warning_messages(rated_shipment)
RateEstimate.new(origin, destination, @@name, service_name_for(origin, service_code),
:total_price => rated_shipment.at('TotalCharges/MonetaryValue').text.to_f,
:insurance_price => rated_shipment.at('ServiceOptionsCharges/MonetaryValue').text.to_f,
:currency => rated_shipment.at('TotalCharges/CurrencyCode').text,
:service_code => service_code,
:packages => packages,
:delivery_range => [timestamp_from_business_day(days_to_delivery)],
:negotiated_rate => rated_shipment.at('NegotiatedRates/NetSummaryCharges/GrandTotal/MonetaryValue').try(:text).to_f,
:messages => warning_messages
)
end
end
RateResponse.new(success, message, Hash.from_xml(response).values.first, :rates => rate_estimates, :xml => response, :request => last_request)
end
|