Class: ExportoAPI::Client

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

Constant Summary collapse

LIVE_BASE_URL =
"https://api.exporto.de/v1/"
TEST_BASE_URL =
"https://staging.api.exporto.de/v1/"
DEFAULT_OPEN_TIMEOUT =
5
DEFAULT_TIMEOUT =
15

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, sandbox: false, adapter: Faraday.default_adapter, open_timeout: DEFAULT_OPEN_TIMEOUT, timeout: DEFAULT_TIMEOUT) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
# File 'lib/exporto_api/client.rb', line 14

def initialize(access_token:, sandbox: false, adapter: Faraday.default_adapter,
  open_timeout: DEFAULT_OPEN_TIMEOUT, timeout: DEFAULT_TIMEOUT)
  @access_token = access_token
  @sandbox = sandbox
  @adapter = adapter
  @open_timeout = open_timeout
  @timeout = timeout
end

Instance Attribute Details

#access_token ⇒ Object (readonly)

Returns the value of attribute access_token.



12
13
14
# File 'lib/exporto_api/client.rb', line 12

def access_token
  @access_token
end

#adapter ⇒ Object (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/exporto_api/client.rb', line 12

def adapter
  @adapter
end

#open_timeout ⇒ Object (readonly)

Returns the value of attribute open_timeout.



12
13
14
# File 'lib/exporto_api/client.rb', line 12

def open_timeout
  @open_timeout
end

#timeout ⇒ Object (readonly)

Returns the value of attribute timeout.



12
13
14
# File 'lib/exporto_api/client.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#connection ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/exporto_api/client.rb', line 31

def connection
  @connection ||= Faraday.new do |connection|
    connection.url_prefix = sandbox? ? TEST_BASE_URL : LIVE_BASE_URL
    connection.options.open_timeout = open_timeout
    connection.options.timeout = timeout
    connection.headers["Authorization"] = "Bearer #{access_token}"
    connection.headers["Accept"] = "application/json"
    connection.request :json
    connection.response :json, content_type: /\bjson/
    connection.adapter adapter
  end
end

#label ⇒ Object



44
45
46
# File 'lib/exporto_api/client.rb', line 44

def label
  @label ||= LabelResource.new(self)
end

#label_method ⇒ Object



23
24
25
# File 'lib/exporto_api/client.rb', line 23

def label_method
  @label_method ||= LabelMethodResource.new(self)
end

#return_shipment ⇒ Object



48
49
50
# File 'lib/exporto_api/client.rb', line 48

def return_shipment
  @return_shipment ||= ReturnShipmentResource.new(self)
end

#shipment ⇒ Object



27
28
29
# File 'lib/exporto_api/client.rb', line 27

def shipment
  @shipment ||= ShipmentResource.new(self)
end