Class: Tiqets::Client
- Inherits:
-
Object
- Object
- Tiqets::Client
- Includes:
- Resources::Product
- Defined in:
- lib/tiqets/client.rb
Constant Summary collapse
- V2_ROOT =
'https://api.tiqets.com/v2/'.freeze
Instance Method Summary collapse
- #connection ⇒ Object
- #get(url, params, response_key) ⇒ Object
- #handle_response(response, response_key) ⇒ Object
-
#initialize(root: V2_ROOT, api_key:) ⇒ Client
constructor
A new instance of Client.
Methods included from Resources::Product
Constructor Details
Instance Method Details
#connection ⇒ Object
16 17 18 |
# File 'lib/tiqets/client.rb', line 16 def connection @connection ||= HTTP.auth("Token #{@api_key}") end |
#get(url, params, response_key) ⇒ Object
20 21 22 23 24 |
# File 'lib/tiqets/client.rb', line 20 def get(url, params, response_key) response = connection.get(@root + url, params: params) handle_response(response, response_key) end |
#handle_response(response, response_key) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/tiqets/client.rb', line 26 def handle_response(response, response_key) response = JSON.parse(response) return response[response_key] if response['success'] == true raise Error.new(response['status'], response['message']) end |