Class: Tomba::Client
- Inherits:
-
Object
- Object
- Tomba::Client
- Defined in:
- lib/tomba/client.rb
Constant Summary collapse
- METHOD_GET =
'get'
- METHOD_POST =
'post'
- METHOD_PUT =
'put'
- METHOD_PATCH =
'patch'
- METHOD_DELETE =
'delete'
- METHOD_HEAD =
'head'
- METHOD_OPTIONS =
'options'
- METHOD_CONNECT =
'connect'
- METHOD_TRACE =
'trace'
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
- #call(method, path = '', headers = {}, params = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #set_endpoint(endpoint) ⇒ Object
- #set_key(value) ⇒ Object
- #set_secret(value) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 |
# File 'lib/tomba/client.rb', line 19 def initialize() @headers = { 'content-type' => '', 'user-agent' => RUBY_PLATFORM + ':ruby-' + RUBY_VERSION, 'x-sdk-version' => 'tomba:ruby:v1.0.1' } @endpoint = 'https://api.tomba.io/v1'; end |
Instance Method Details
#add_header(key, value) ⇒ Object
47 48 49 50 51 |
# File 'lib/tomba/client.rb', line 47 def add_header(key, value) @headers[key.downcase] = value return self end |
#call(method, path = '', headers = {}, params = {}) ⇒ Object
53 54 55 56 |
# File 'lib/tomba/client.rb', line 53 def call(method, path = '', headers = {}, params = {}) uri = URI.parse(@endpoint + path + ((method == METHOD_GET && params.length) ? '?' + encode(params) : '')) return fetch(method, uri, headers, params) end |
#set_endpoint(endpoint) ⇒ Object
41 42 43 44 45 |
# File 'lib/tomba/client.rb', line 41 def set_endpoint(endpoint) @endpoint = endpoint return self end |
#set_key(value) ⇒ Object
29 30 31 32 33 |
# File 'lib/tomba/client.rb', line 29 def set_key(value) add_header('x-tomba-key', value) return self end |
#set_secret(value) ⇒ Object
35 36 37 38 39 |
# File 'lib/tomba/client.rb', line 35 def set_secret(value) add_header('x-tomba-secret', value) return self end |