Class: TuneupTechnology::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tuneuptechnology/client.rb

Overview

The Client initializes everything needed to use this client library

Direct Known Subclasses

Customers, Inventory, Locations, Tickets

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email = nil, api_key = nil, base_url = 'https://app.tuneuptechnology.com/api', timeout = 10) ⇒ Client

Returns a new instance of Client.

Raises:

  • (NameError)


11
12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def base_url
  @base_url
end

#emailObject (readonly)

Returns the value of attribute email.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def email
  @email
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def headers
  @headers
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def timeout
  @timeout
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/tuneuptechnology/client.rb', line 9

def version
  @version
end

Class Method Details

.make_http_request(method, endpoint, data = nil) ⇒ Object

Build the HTTP client for the library



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

Instance Method Details

#customersObject



21
22
23
# File 'lib/tuneuptechnology/client.rb', line 21

def customers
  TuneupTechnology::Customers.new(@base_url, :make_http_request)
end

#inventoryObject



25
26
27
# File 'lib/tuneuptechnology/client.rb', line 25

def inventory
  TuneupTechnology::Inventory.new(@base_url, :make_http_request)
end

#locationsObject



29
30
31
# File 'lib/tuneuptechnology/client.rb', line 29

def locations
  TuneupTechnology::Locations.new(@base_url, :make_http_request)
end

#ticketsObject



33
34
35
# File 'lib/tuneuptechnology/client.rb', line 33

def tickets
  TuneupTechnology::Tickets.new(@base_url, :make_http_request)
end