Class: Fedex::Request::Rate
Constant Summary
Constants inherited from Base
Base::CARRIER_CODES, Base::CLEARANCE_BROKERAGE_TYPE, Base::DROP_OFF_TYPES, Base::PACKAGING_TYPES, Base::PAYMENT_TYPE, Base::PRODUCTION_URL, Base::RECIPIENT_CUSTOM_ID_TYPE, Base::SERVICE_TYPES, Base::TEST_URL
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#process_request ⇒ Object
Sends post request to Fedex web service and parse the response, a Rate object is created if the response is successful.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Fedex::Request::Base
Instance Method Details
#process_request ⇒ Object
Sends post request to Fedex web service and parse the response, a Rate object is created if the response is successful
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fedex/request/rate.rb', line 7 def process_request api_response = self.class.post(api_url, :body => build_xml) puts api_response if @debug response = parse_response(api_response) if success?(response) rate_reply_details = response[:rate_reply][:rate_reply_details] || [] rate_reply_details = [rate_reply_details] if rate_reply_details.is_a?(Hash) rate_reply_details.map do |rate_reply| rate_details = [rate_reply[:rated_shipment_details]].flatten.first[:shipment_rate_detail] rate_details.merge!(service_type: rate_reply[:service_type]) rate_details.merge!(transit_time: rate_reply[:transit_time]) Fedex::Rate.new(rate_details) end else = if response[:rate_reply] [response[:rate_reply][:notifications]].flatten.first[:message] else "#{api_response["Fault"]["detail"]["fault"]["reason"]}\n--#{api_response["Fault"]["detail"]["fault"]["details"]["ValidationFailureDetail"]["message"].join("\n--")}" end rescue $1 raise RateError, end end |