Class: TuneupTechnology::Client
- Inherits:
-
Object
- Object
- TuneupTechnology::Client
- Defined in:
- lib/tuneuptechnology/client.rb
Overview
The Client initializes everything needed to use this client library
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.make_http_request(method, endpoint, data = nil) ⇒ Object
Build the HTTP client for the library.
Instance Method Summary collapse
- #customers ⇒ Object
-
#initialize(email = nil, api_key = nil, base_url = 'https://app.tuneuptechnology.com/api', timeout = 10) ⇒ Client
constructor
A new instance of Client.
- #inventory ⇒ Object
- #locations ⇒ Object
- #tickets ⇒ Object
Constructor Details
#initialize(email = nil, api_key = nil, base_url = 'https://app.tuneuptechnology.com/api', timeout = 10) ⇒ Client
Returns a new instance of Client.
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_key ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/tuneuptechnology/client.rb', line 9 def base_url @base_url end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
9 10 11 |
# File 'lib/tuneuptechnology/client.rb', line 9 def email @email end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/tuneuptechnology/client.rb', line 9 def headers @headers end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/tuneuptechnology/client.rb', line 9 def timeout @timeout end |
#version ⇒ Object (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
#customers ⇒ Object
21 22 23 |
# File 'lib/tuneuptechnology/client.rb', line 21 def customers TuneupTechnology::Customers.new(@base_url, :make_http_request) end |
#inventory ⇒ Object
25 26 27 |
# File 'lib/tuneuptechnology/client.rb', line 25 def inventory TuneupTechnology::Inventory.new(@base_url, :make_http_request) end |
#locations ⇒ Object
29 30 31 |
# File 'lib/tuneuptechnology/client.rb', line 29 def locations TuneupTechnology::Locations.new(@base_url, :make_http_request) end |
#tickets ⇒ Object
33 34 35 |
# File 'lib/tuneuptechnology/client.rb', line 33 def tickets TuneupTechnology::Tickets.new(@base_url, :make_http_request) end |