Class: Extensiv::Client

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

Direct Known Subclasses

CartClient

Constant Summary collapse

BASE_URL =
"https://api.cartrover.com/v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_user:, api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



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

def initialize(api_user:, api_key:, adapter: Faraday.default_adapter, stubs: nil)
  @api_user = api_user
  @api_key = api_key
  @adapter = adapter
  @stubs = stubs
  @auth_key = Base64.strict_encode64("#{@api_user}:#{@api_key}")
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/extensiv/client.rb', line 10

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/extensiv/client.rb', line 10

def api_key
  @api_key
end

#api_userObject (readonly)

Returns the value of attribute api_user.



10
11
12
# File 'lib/extensiv/client.rb', line 10

def api_user
  @api_user
end

#auth_keyObject (readonly)

Returns the value of attribute auth_key.



10
11
12
# File 'lib/extensiv/client.rb', line 10

def auth_key
  @auth_key
end

#stubsObject (readonly)

Returns the value of attribute stubs.



10
11
12
# File 'lib/extensiv/client.rb', line 10

def stubs
  @stubs
end

Instance Method Details

#connectionObject



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

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.headers = { Authorization: "Basic #{@auth_key}" }
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter, @stubs
  end
end