Class: Fedex::Request::Rate

Inherits:
Base
  • Object
show all
Defined in:
lib/fedex/request/rate.rb

Constant Summary

Constants inherited from Base

Base::CLEARANCE_BROKERAGE_TYPE, Base::DROP_OFF_TYPES, Base::PACKAGING_TYPES, Base::PRODUCTION_URL, Base::RECIPIENT_CUSTOM_ID_TYPE, Base::SERVICE_TYPES, Base::TEST_URL

Instance Attribute Summary

Attributes inherited from Base

#debug

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Fedex::Request::Base

Instance Method Details

#process_requestObject

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
# 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_details = [response[:rate_reply][:rate_reply_details][:rated_shipment_details]].flatten.first[:shipment_rate_detail]
    Fedex::Rate.new(rate_details)
  else
    error_message = if response[:rate_reply]
      [response[:rate_reply][:notifications]].flatten.first[:message]
    else
      api_response["Fault"]["detail"]["fault"]["reason"]
    end rescue $1
    raise RateError, error_message
  end
end