Class: DhlFreightApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dhl_freight_api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_key, prod: false) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/dhl_freight_api/client.rb', line 7

def initialize(client_key, prod: false)
  @client_key = client_key
  @prod = prod
end

Instance Method Details

#base_url ⇒ Object



12
13
14
15
16
17
18
# File 'lib/dhl_freight_api/client.rb', line 12

def base_url
  if @prod
    "https://api.freight-logistics.dhl.com"
  else
    "https://test-api.freight-logistics.dhl.com"
  end
end

#connection ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/dhl_freight_api/client.rb', line 20

def connection
  @connection ||= Faraday.new do |f|
    f.request :json
    f.response :json
    f.headers["client-key"] = @client_key
    f.headers["Content-Type"] = "application/json"
  end
end


33
34
35
# File 'lib/dhl_freight_api/client.rb', line 33

def print
  Resources::Print.new(self)
end

#shipment_booking ⇒ Object



29
30
31
# File 'lib/dhl_freight_api/client.rb', line 29

def shipment_booking
  Resources::ShipmentBooking.new(self)
end