class Tracksale::Client

Attributes

default_path[RW]
key[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

get(endpoint_path, extra_headers = {}) click to toggle source
# 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 = {}) click to toggle source
# 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