class TuneupTechnology::Client

The Client initializes everything needed to use this client library

Attributes

api_key[R]
base_url[R]
email[R]
headers[R]
timeout[R]
version[R]

Public Class Methods

make_http_request(method, endpoint, data = nil) click to toggle source

Build the HTTP client for the library

# File lib/tuneuptechnology/client.rb, line 38
def self.make_http_request(method, endpoint, data = nil)
  headers = {
    'Accept' => 'application/json',
    'User-Agent' => "TuneupTechnologyApp/RubyClient/#{@version}",
    'Email' => @@email,
    'Api-Key' => @@api_key
  }

  begin
    response = RestClient::Request.execute(
      method: method,
      url: endpoint,
      payload: data.to_json,
      headers: headers,
      timeout: @timeout
    )

    JSON.parse(response.body)
  rescue RestClient::ExceptionWithResponse => e
    e.response
  end
end
new(email = nil, api_key = nil, base_url = 'https://app.tuneuptechnology.com/api', timeout = 10) click to toggle source
# File lib/tuneuptechnology/client.rb, line 11
def initialize(email = nil, api_key = nil, base_url = 'https://app.tuneuptechnology.com/api', timeout = 10)
  @@email = email
  @@api_key = api_key
  @base_url = base_url
  @timeout = timeout
  @version = '2.0.0'

  raise NameError, 'email and api_key are required to create a Client.' if @@email.nil? || @@api_key.nil?
end

Public Instance Methods

customers() click to toggle source
# File lib/tuneuptechnology/client.rb, line 21
def customers
  TuneupTechnology::Customers.new(@base_url, :make_http_request)
end
inventory() click to toggle source
# File lib/tuneuptechnology/client.rb, line 25
def inventory
  TuneupTechnology::Inventory.new(@base_url, :make_http_request)
end
locations() click to toggle source
# File lib/tuneuptechnology/client.rb, line 29
def locations
  TuneupTechnology::Locations.new(@base_url, :make_http_request)
end
tickets() click to toggle source
# File lib/tuneuptechnology/client.rb, line 33
def tickets
  TuneupTechnology::Tickets.new(@base_url, :make_http_request)
end