Class: Myparcel::Client
- Inherits:
-
Object
- Object
- Myparcel::Client
- Defined in:
- lib/myparcel/client.rb
Overview
Represents a client for the API
Instance Attribute Summary collapse
-
#authentication ⇒ Object
Returns the value of attribute authentication.
Instance Method Summary collapse
-
#delivery_options ⇒ Object
Get delivery options for an address.
-
#initialize(api_key = nil) ⇒ Client
constructor
A new instance of Client.
-
#shipments ⇒ Object
Shipments management endpoint.
- #tracktraces ⇒ Object
- #webhooks ⇒ Object
Constructor Details
#initialize(api_key = nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/myparcel/client.rb', line 6 def initialize(api_key = nil) @authentication = Myparcel::Authentication.new(api_key) raise 'No credentials provided' if @authentication.invalid? end |
Instance Attribute Details
#authentication ⇒ Object
Returns the value of attribute authentication.
4 5 6 |
# File 'lib/myparcel/client.rb', line 4 def authentication @authentication end |
Instance Method Details
#delivery_options ⇒ Object
Get delivery options for an address
Usage:
“‘ruby client.delivery_options.find(…) “`
18 19 20 |
# File 'lib/myparcel/client.rb', line 18 def @delivery_options ||= Myparcel::API::DeliveryOptions.new(authentication) end |
#shipments ⇒ Object
Shipments management endpoint
Usage:
Create shipments:
“‘ruby client = Myparcel.client(’api_key’) client.shipments.create(shipments: […]) “‘
Find shipments:
“‘ruby # returns all available shipments: client.shipments.find
# returns shipments by id client.shipments.find(shipment_ids: [1, 2]) “‘
42 43 44 |
# File 'lib/myparcel/client.rb', line 42 def shipments @shipments ||= Myparcel::API::Shipments.new(authentication) end |
#tracktraces ⇒ Object
46 47 48 |
# File 'lib/myparcel/client.rb', line 46 def tracktraces @tracktraces ||= Myparcel::API::Tracktraces.new(authentication) end |
#webhooks ⇒ Object
50 51 52 |
# File 'lib/myparcel/client.rb', line 50 def webhooks @webhooks ||= Myparcel::API::WebhookSubscriptions.new(authentication) end |