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.
20 21 22 23 24 25 26 27 28 |
# File 'lib/tomba/client.rb', line 20 def initialize @headers = { 'content-type' => '', 'user-agent' => "#{RUBY_PLATFORM}:ruby-#{RUBY_VERSION}", 'x-sdk-version' => "tomba:ruby:v#{Tomba::VERSION}" } @endpoint = 'https://api.tomba.io/v1' end |
Instance Method Details
#add_header(key, value) ⇒ Object
48 49 50 51 52 |
# File 'lib/tomba/client.rb', line 48 def add_header(key, value) @headers[key.downcase] = value self end |
#call(method, path = '', headers = {}, params = {}) ⇒ Object
54 55 56 57 |
# File 'lib/tomba/client.rb', line 54 def call(method, path = '', headers = {}, params = {}) uri = URI.parse(@endpoint + path + (method == METHOD_GET && params.length ? "?#{encode(params)}" : '')) fetch(method, uri, headers, params) end |
#set_endpoint(endpoint) ⇒ Object
42 43 44 45 46 |
# File 'lib/tomba/client.rb', line 42 def set_endpoint(endpoint) @endpoint = endpoint self end |
#set_key(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/tomba/client.rb', line 30 def set_key(value) add_header('x-tomba-key', value) self end |
#set_secret(value) ⇒ Object
36 37 38 39 40 |
# File 'lib/tomba/client.rb', line 36 def set_secret(value) add_header('x-tomba-secret', value) self end |