Class: AxTrack::Client
- Inherits:
-
Object
- Object
- AxTrack::Client
- 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
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #assets ⇒ Object
- #connection ⇒ Object
-
#initialize(api_key: ENV['AXTRACK_API_KEY'], adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #trackers ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/ax_track/client.rb', line 12 def adapter @adapter end |
#api_key ⇒ Object (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
#assets ⇒ Object
23 24 25 |
# File 'lib/ax_track/client.rb', line 23 def assets AssetResource.new(self) end |
#connection ⇒ Object
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 |
#trackers ⇒ Object
18 19 20 |
# File 'lib/ax_track/client.rb', line 18 def trackers TrackerResource.new(self) end |