Class: Ecologi::Client

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

Constant Summary collapse

BASE_URL =
"https://public.ecologi.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/ecologi/client.rb', line 7

def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
  @api_key = api_key
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/ecologi/client.rb', line 5

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/ecologi/client.rb', line 5

def api_key
  @api_key
end

Instance Method Details

#carbon_offsetsObject



19
20
21
# File 'lib/ecologi/client.rb', line 19

def carbon_offsets
  CarbonOffsetsResource.new(self)
end

#connectionObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/ecologi/client.rb', line 27

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :authorization, :Bearer, api_key
    conn.request :json

    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#reportingObject



23
24
25
# File 'lib/ecologi/client.rb', line 23

def reporting
  ReportingResource.new(self)
end

#treesObject



15
16
17
# File 'lib/ecologi/client.rb', line 15

def trees
  TreesResource.new(self)
end