Class: CanadaPost::Client
- Inherits:
-
Object
- Object
- CanadaPost::Client
- Defined in:
- lib/canada_post/client.rb
Instance Method Summary collapse
- #create(options = {}) ⇒ Object
- #details(shipping_id) ⇒ Object
- #get_artifact(url) ⇒ Object
- #get_artifact_link(manifest) ⇒ Object
- #get_label(label_url) ⇒ Object
- #get_merchant_info(token) ⇒ Object
- #get_price(shipping_id, mobo = @credentials.customer_number) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #manifest(options = {}) ⇒ Object
- #rate(options = {}) ⇒ Object
- #registration_token ⇒ Object
- #shipment(options = {}) ⇒ Object
- #void_shipment(shipping_id, mobo = @credentials.customer_number) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
4 5 6 |
# File 'lib/canada_post/client.rb', line 4 def initialize(={}) @credentials = Credentials.new() end |
Instance Method Details
#create(options = {}) ⇒ Object
12 13 14 |
# File 'lib/canada_post/client.rb', line 12 def create( = {}) Request::Shipping.new(@credentials, ).process_request end |
#details(shipping_id) ⇒ Object
68 69 70 |
# File 'lib/canada_post/client.rb', line 68 def details(shipping_id) Request::Shipping.new(@credentials).details(shipping_id) end |
#get_artifact(url) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/canada_post/client.rb', line 40 def get_artifact(url) manifest = Request::Manifest.new(@credentials).get_manifest(url) if manifest[:errors].present? return { status: false, error: manifest[:errors] } else artifact_link = get_artifact_link(manifest[:manifest]) artifact = Request::Manifest.new(@credentials).get_artifact(artifact_link) return { status: true, artifact: artifact } end end |
#get_artifact_link(manifest) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/canada_post/client.rb', line 57 def get_artifact_link(manifest) links = manifest[:links] if links.present? links[:link].each do |link| if link[:rel] == 'artifact' return link[:href] end end end end |
#get_label(label_url) ⇒ Object
20 21 22 |
# File 'lib/canada_post/client.rb', line 20 def get_label(label_url) Request::Shipping.new(@credentials).get_label(label_url) end |
#get_merchant_info(token) ⇒ Object
36 37 38 |
# File 'lib/canada_post/client.rb', line 36 def get_merchant_info(token) Request::Registration.new(@credentials).merchant_info(token) end |
#get_price(shipping_id, mobo = @credentials.customer_number) ⇒ Object
16 17 18 |
# File 'lib/canada_post/client.rb', line 16 def get_price(shipping_id, mobo = @credentials.customer_number) Request::Shipping.new(@credentials).get_price(shipping_id, mobo) end |
#manifest(options = {}) ⇒ Object
28 29 30 |
# File 'lib/canada_post/client.rb', line 28 def manifest(={}) Request::Manifest.new(@credentials, ).process_request end |
#rate(options = {}) ⇒ Object
72 73 74 |
# File 'lib/canada_post/client.rb', line 72 def rate(={}) Request::Rate.new(@credentials, ).process_request end |
#registration_token ⇒ Object
32 33 34 |
# File 'lib/canada_post/client.rb', line 32 def registration_token Request::Registration.new(@credentials).get_token end |
#shipment(options = {}) ⇒ Object
8 9 10 |
# File 'lib/canada_post/client.rb', line 8 def shipment(={}) Request::Shipment.new(@credentials, ).process_request end |
#void_shipment(shipping_id, mobo = @credentials.customer_number) ⇒ Object
24 25 26 |
# File 'lib/canada_post/client.rb', line 24 def void_shipment(shipping_id, mobo = @credentials.customer_number) Request::Shipping.new(@credentials).void_shipping(shipping_id, mobo) end |