Class: DHLEcommerceEU::Client
- Inherits:
-
Object
- Object
- DHLEcommerceEU::Client
- Defined in:
- lib/dhl_ecommerce_eu/client.rb
Constant Summary collapse
- TEST_URL_BASE =
'https://api-sandbox.dhl.com/'
- PROD_URL_BASE =
'https://api.dhl.com/'
Instance Attribute Summary collapse
-
#url_base ⇒ Object
readonly
Returns the value of attribute url_base.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(client_id, client_secret, env = nil) ⇒ Client
constructor
A new instance of Client.
- #label ⇒ Object
- #shipment ⇒ Object
- #tracking ⇒ Object
Constructor Details
#initialize(client_id, client_secret, env = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 8 def initialize(client_id, client_secret, env = nil) @client_id = client_id @client_secret = client_secret @url_base = if env.nil? && defined?(Rails) && Rails.env.production? PROD_URL_BASE else env == :production ? PROD_URL_BASE : TEST_URL_BASE end end |
Instance Attribute Details
#url_base ⇒ Object (readonly)
Returns the value of attribute url_base.
6 7 8 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 6 def url_base @url_base end |
Instance Method Details
#connection ⇒ Object
18 19 20 21 22 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 18 def connection @connection ||= HTTP.headers(content_type: 'application/json', accept: 'application/json') .auth("Bearer #{bearer_token}") .timeout(10) end |
#label ⇒ Object
28 29 30 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 28 def label LabelResource.new(self) end |
#shipment ⇒ Object
24 25 26 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 24 def shipment ShipmentResource.new(self) end |
#tracking ⇒ Object
32 33 34 |
# File 'lib/dhl_ecommerce_eu/client.rb', line 32 def tracking TrackingResource.new(self) end |