Class: TorqueAPI::Client

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

Constant Summary collapse

LIVE_BASE_URL =
"https://wms-api.torque.eu/torqueapi/api/v1/"
TEST_BASE_URL =
"https://wms-api.torque.eu/torqueapitest/api/v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, client_defaults: {}, sandbox: false, adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/torque_api/client.rb', line 10

def initialize(api_key:, client_defaults: {}, sandbox: false, adapter: Faraday.default_adapter)
  @api_key = api_key
  @client_defaults = client_defaults
  @sandbox = sandbox
  @adapter = adapter
end

Instance Attribute Details

#adapter ⇒ Object (readonly)

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

#api_key ⇒ Object (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#client_defaults ⇒ Object (readonly)

Returns the value of attribute client_defaults.



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

def client_defaults
  @client_defaults
end

Instance Method Details

#connection ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/torque_api/client.rb', line 25

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = sandbox? ? TEST_BASE_URL : LIVE_BASE_URL
    conn.headers["Authorization"] = "Basic #{api_key}"
    conn.headers["Accept"] = "application/json"
    client_defaults.each { |key, value| conn.headers[key.to_s] = value.to_s }
    conn.request :json
    conn.response :json, content_type: /\bjson/
    conn.adapter adapter
  end
end

#pre_advice ⇒ Object



17
18
19
# File 'lib/torque_api/client.rb', line 17

def pre_advice
  @pre_advice ||= PreAdviceResource.new(self)
end

#return_rma ⇒ Object



21
22
23
# File 'lib/torque_api/client.rb', line 21

def return_rma
  @return_rma ||= ReturnRmaResource.new(self)
end