Class: Enginn::Client

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

Constant Summary collapse

BASE_URL =
'https://app.enginn.tech/api/v1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token:, adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_token (String)

    The API token to use

  • adapter (Symbol) (defaults to: Faraday.default_adapter)

    The Faraday adapter to use



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

#adapterObject (readonly)

Returns the value of attribute adapter.



9
10
11
# File 'lib/enginn/client.rb', line 9

def adapter
  @adapter
end

#api_tokenObject (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.

Yield Parameters:

  • connection (Faraday::Connection)

    if a block is given

Returns:

  • (Faraday::Connection)


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

#projectsEnginn::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