Class: CanadaPost::Request::Shipping
- Defined in:
- lib/canada_post/request/shipping.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
-
#contract_id ⇒ Object
Returns the value of attribute contract_id.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#mailing_date ⇒ Object
Returns the value of attribute mailing_date.
-
#notification ⇒ Object
Returns the value of attribute notification.
-
#package ⇒ Object
Returns the value of attribute package.
-
#preferences ⇒ Object
Returns the value of attribute preferences.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#settlement_info ⇒ Object
Returns the value of attribute settlement_info.
Instance Method Summary collapse
- #details(shipping_id, mobo = @credentials.customer_number) ⇒ Object
- #get_label(label_url) ⇒ Object
- #get_price(shipping_id, mobo = @credentials.customer_number) ⇒ Object
-
#initialize(credentials, options = {}) ⇒ Shipping
constructor
A new instance of Shipping.
- #process_request ⇒ Object
- #void_shipping(shipping_id, mobo = @credentials.customer_number) ⇒ Object
Methods inherited from Base
#client, #parse_response, #process_response, #sanitize_response_keys
Constructor Details
#initialize(credentials, options = {}) ⇒ Shipping
Returns a new instance of Shipping.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/canada_post/request/shipping.rb', line 8 def initialize(credentials, ={}) @credentials = credentials if .present? @sender = [:sender] @destination = [:destination] @package = [:package] @notification = [:notification] @preferences = [:preferences] @settlement_info = [:settlement_info] @group_id = [:group_id] @mobo = [:mobo] if @mobo.present? && @mobo[:customer_number].present? @mobo_customer = @mobo[:customer_number] @shipping_auth = {username: @mobo[:username], password: @mobo[:password]} else @mobo_customer = @credentials.customer_number @shipping_auth = {username: credentials.username, password: credentials.password} end @customer_number = @credentials.customer_number @mailing_date = [:mailing_date] @contract_id = [:contract_id] @service_code = [:service_code] end super(credentials) end |
Instance Attribute Details
#contract_id ⇒ Object
Returns the value of attribute contract_id.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def contract_id @contract_id end |
#destination ⇒ Object
Returns the value of attribute destination.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def destination @destination end |
#group_id ⇒ Object
Returns the value of attribute group_id.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def group_id @group_id end |
#mailing_date ⇒ Object
Returns the value of attribute mailing_date.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def mailing_date @mailing_date end |
#notification ⇒ Object
Returns the value of attribute notification.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def notification @notification end |
#package ⇒ Object
Returns the value of attribute package.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def package @package end |
#preferences ⇒ Object
Returns the value of attribute preferences.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def preferences @preferences end |
#sender ⇒ Object
Returns the value of attribute sender.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def sender @sender end |
#settlement_info ⇒ Object
Returns the value of attribute settlement_info.
6 7 8 |
# File 'lib/canada_post/request/shipping.rb', line 6 def settlement_info @settlement_info end |
Instance Method Details
#details(shipping_id, mobo = @credentials.customer_number) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/canada_post/request/shipping.rb', line 66 def details(shipping_id, mobo = @credentials.customer_number) details_url = api_url + "/rs/#{@credentials.customer_number}/#{mobo}/shipment/#{shipping_id}/details" api_response = self.class.get( details_url, headers: shipping_header, basic_auth: @authorization ) process_response(api_response) end |
#get_label(label_url) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/canada_post/request/shipping.rb', line 76 def get_label(label_url) self.class.get( label_url, headers: { 'Content-type' => 'application/pdf', 'Accept' => 'application/pdf' }, basic_auth: @authorization ) end |
#get_price(shipping_id, mobo = @credentials.customer_number) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/canada_post/request/shipping.rb', line 56 def get_price(shipping_id, mobo = @credentials.customer_number) price_url = api_url + "/rs/#{@credentials.customer_number}/#{mobo}/shipment/#{shipping_id}/price" api_response = self.class.get( price_url, headers: shipping_header, basic_auth: @authorization ) process_response(api_response) end |
#process_request ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/canada_post/request/shipping.rb', line 34 def process_request shipment_response = Hash.new api_response = self.class.post( shipping_url, body: build_xml, headers: shipping_header, basic_auth: @shipping_auth ) shipping_response = process_response(api_response) shipment_response[:create_shipping] = shipping_response unless shipping_response[:errors].present? manifest_params = { destination: @destination, phone: @sender[:phone], group_id: @group_id } manifest_response = CanadaPost::Request::Manifest.new(@credentials, manifest_params).process_request shipment_response[:transmit_shipping] = manifest_response end shipment_response end |
#void_shipping(shipping_id, mobo = @credentials.customer_number) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/canada_post/request/shipping.rb', line 87 def void_shipping(shipping_id, mobo = @credentials.customer_number) void_url = api_url + "/rs/#{@credentials.customer_number}/#{mobo}/shipment/#{shipping_id}" api_response = self.class.delete( void_url, headers: shipping_header, basic_auth: @authorization ) process_response(api_response) end |