Class: AxTrack::Client
- Inherits:
-
Object
- Object
- AxTrack::Client
- Defined in:
- lib/ax_track/client.rb
Constant Summary collapse
- APIKeyMissing =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
- #connection ⇒ Object
Instance Method Summary collapse
- #assets ⇒ Object
-
#initialize(api_key: nil, adapter: nil, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #trackers ⇒ Object
Constructor Details
#initialize(api_key: nil, adapter: nil, stubs: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# File 'lib/ax_track/client.rb', line 12 def initialize(api_key: nil, adapter: nil, stubs: nil) @api_key = api_key&.strip || ENV['AXTRACK_API_KEY']&.strip @adapter = adapter || Faraday.default_adapter @stubs = stubs raise APIKeyMissing, "No API key provided" if !defined?(api_key) || api_key.nil? || api_key.empty? end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/ax_track/client.rb', line 9 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/ax_track/client.rb', line 9 def api_key @api_key end |
#connection ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ax_track/client.rb', line 29 def connection @connection ||= Faraday.new(AxTrack.base_url_api) do |conn| #conn.request :url_encoded conn.request :json conn.response :json, content_type: 'application/json' conn.adapter adapter, @stubs conn.headers['Authorization'] = "Token #{api_key}" unless api_key.empty? conn..timeout = 20 end end |
Instance Method Details
#assets ⇒ Object
25 26 27 |
# File 'lib/ax_track/client.rb', line 25 def assets AssetResource.new(self) end |
#trackers ⇒ Object
20 21 22 |
# File 'lib/ax_track/client.rb', line 20 def trackers TrackerResource.new(self) end |