Class: Enginn::Client
- Inherits:
-
Object
- Object
- Enginn::Client
- Defined in:
- lib/enginn/client.rb
Constant Summary collapse
- BASE_URL =
'https://app.enginn.tech/api/v1'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
Instance Method Summary collapse
-
#connection {|connection| ... } ⇒ Faraday::Connection
Get a connection to the API.
-
#initialize(api_token:, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
-
#projects ⇒ Enginn::ProjectsIndex
Retrieve the projects the account have access to.
Constructor Details
#initialize(api_token:, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/enginn/client.rb', line 13 def initialize(api_token:, adapter: Faraday.default_adapter) @api_token = api_token @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/enginn/client.rb', line 9 def adapter @adapter end |
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
9 10 11 |
# File 'lib/enginn/client.rb', line 9 def api_token @api_token end |
Instance Method Details
#connection {|connection| ... } ⇒ Faraday::Connection
Get a connection to the API.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/enginn/client.rb', line 22 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.adapter @adapter conn.request :authorization, 'Bearer', -> { @api_token } conn.request :json conn.response :json conn.response :enginn_raise_error end yield(@connection) if block_given? @connection end |
#projects ⇒ Enginn::ProjectsIndex
Retrieve the projects the account have access to.
37 38 39 |
# File 'lib/enginn/client.rb', line 37 def projects ProjectsIndex.new(self) end |