Class: DHLEcommerceEU::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_baseObject (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

#connectionObject



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

#labelObject



28
29
30
# File 'lib/dhl_ecommerce_eu/client.rb', line 28

def label
  LabelResource.new(self)
end

#shipmentObject



24
25
26
# File 'lib/dhl_ecommerce_eu/client.rb', line 24

def shipment
  ShipmentResource.new(self)
end

#trackingObject



32
33
34
# File 'lib/dhl_ecommerce_eu/client.rb', line 32

def tracking
  TrackingResource.new(self)
end