Class: Tracksale::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tracksale/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/tracksale/client.rb', line 9

def initialize
  if Tracksale.configuration.key.nil?
    raise 'API Key not found , please configure as explained in the readme.'
  end

  @key = Tracksale.configuration.key
  @default_path = '/v2/'
end

Instance Attribute Details

#default_pathObject

Returns the value of attribute default_path.



4
5
6
# File 'lib/tracksale/client.rb', line 4

def default_path
  @default_path
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/tracksale/client.rb', line 3

def key
  @key
end

Instance Method Details

#get(endpoint_path, extra_headers = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/tracksale/client.rb', line 18

def get(endpoint_path, extra_headers = {})
  headers = { 'authorization' => 'bearer ' + key }.merge(extra_headers)
  request_params = {
    headers: headers
  }
  request_params[:debug_output] = STDOUT if $DEBUG
  self.class.get(default_path + endpoint_path, request_params)
end

#post(endpoint_path, body, extra_headers = {}) ⇒ Object



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

def post(endpoint_path, body, extra_headers = {})
  headers = { 'authorization' => 'bearer ' + key,
              'Content-Type' => 'application/json' }.merge(extra_headers)

  headers[:debug_output] = STDOUT if $DEBUG

  endpoint = default_path + endpoint_path
  self.class.post(endpoint, headers: headers, body: body.to_json)
end