Class: Tiqets::Client

Inherits:
Object
  • Object
show all
Includes:
Resources::Product
Defined in:
lib/tiqets/client.rb

Constant Summary collapse

V2_ROOT =
'https://api.tiqets.com/v2/'.freeze

Instance Method Summary collapse

Methods included from Resources::Product

#find_product

Constructor Details

#initialize(root: V2_ROOT, api_key:) ⇒ Client

Returns a new instance of Client.



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

def initialize(root: V2_ROOT, api_key:)
  @root = root
  @api_key = api_key
end

Instance Method Details

#connectionObject



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

Raises:



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