Class: AxTrack::Client

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

Constant Summary collapse

BASE_URL =

include HttpStatusCodes include ApiExceptions

'https://prod.api.ax-track.ch/api/v1'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: ENV['AXTRACK_API_KEY'], adapter: Faraday.default_adapter) ⇒ Client

Returns a new instance of Client.



13
14
15
16
# File 'lib/ax_track/client.rb', line 13

def initialize(api_key: ENV['AXTRACK_API_KEY'], adapter: Faraday.default_adapter)
  @api_key = api_key
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/ax_track/client.rb', line 12

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/ax_track/client.rb', line 12

def api_key
  @api_key
end

Instance Method Details

#assetsObject



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

def assets
  AssetResource.new(self)
end

#connectionObject



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

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    #conn.request :url_encoded
    conn.request :json
    conn.response :json, content_type: 'application/json'
    conn.adapter Faraday.default_adapter
    conn.headers['Authorization'] = "Token #{api_key}" unless api_key.empty?
  end
end

#trackersObject



18
19
20
# File 'lib/ax_track/client.rb', line 18

def trackers
  TrackerResource.new(self)
end