Class: CanadaPost::Request::Rate
- Defined in:
- lib/canada_post/request/rate.rb
Constant Summary
Constants inherited from Base
Base::OPTION_CODES, Base::PRODUCTION_URL, Base::SERVICE_CODES, Base::TEST_CONTRACT_ID, Base::TEST_URL
Instance Attribute Summary collapse
-
#package ⇒ Object
Returns the value of attribute package.
-
#recipient ⇒ Object
Returns the value of attribute recipient.
-
#shipper ⇒ Object
Returns the value of attribute shipper.
Instance Method Summary collapse
-
#initialize(credentials, options = {}) ⇒ Rate
constructor
A new instance of Rate.
- #process_request ⇒ Object
Methods inherited from Base
#api_url, #client, #parse_response, #process_response, #sanitize_response_keys
Constructor Details
#initialize(credentials, options = {}) ⇒ Rate
Returns a new instance of Rate.
7 8 9 10 11 12 |
# File 'lib/canada_post/request/rate.rb', line 7 def initialize(credentials, ={}) requires!(, :shipper, :recipient, :package) @credentials = credentials @shipper, @recipient, @package, @service_type = [:shipper], [:recipient], [:package], [:service_type] super(credentials) end |
Instance Attribute Details
#package ⇒ Object
Returns the value of attribute package.
5 6 7 |
# File 'lib/canada_post/request/rate.rb', line 5 def package @package end |
#recipient ⇒ Object
Returns the value of attribute recipient.
5 6 7 |
# File 'lib/canada_post/request/rate.rb', line 5 def recipient @recipient end |
#shipper ⇒ Object
Returns the value of attribute shipper.
5 6 7 |
# File 'lib/canada_post/request/rate.rb', line 5 def shipper @shipper end |
Instance Method Details
#process_request ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/canada_post/request/rate.rb', line 14 def process_request api_response = client(rate_url, build_xml, rate_headers) response = parse_response(api_response) if success?(response) rate_reply_details = response[:price_quotes][:price_quote] || [] rate_reply_details = [rate_reply_details] if rate_reply_details.is_a? Hash rate_reply_details.map do |rate_reply| CanadaPost::Rate.new(rate_reply) end else = if response[:messages] response[:messages][:message][:description] else 'api_response.response' end raise RateError, end end |