Class: Extensiv::Client
- Inherits:
-
Object
- Object
- Extensiv::Client
- Defined in:
- lib/extensiv/client.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
"https://api.cartrover.com/v1/"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_user ⇒ Object
readonly
Returns the value of attribute api_user.
-
#auth_key ⇒ Object
readonly
Returns the value of attribute auth_key.
-
#stubs ⇒ Object
readonly
Returns the value of attribute stubs.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_user:, api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/extensiv/client.rb', line 10 def adapter @adapter end |
#api_key ⇒ Object (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_user ⇒ Object (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_key ⇒ Object (readonly)
Returns the value of attribute auth_key.
10 11 12 |
# File 'lib/extensiv/client.rb', line 10 def auth_key @auth_key end |
#stubs ⇒ Object (readonly)
Returns the value of attribute stubs.
10 11 12 |
# File 'lib/extensiv/client.rb', line 10 def stubs @stubs end |
Instance Method Details
#connection ⇒ Object
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 |