Class: Tolq::Api::Client
- Inherits:
-
Object
- Object
- Tolq::Api::Client
- Defined in:
- lib/tolq-api/client.rb
Overview
Client handles and encapsulates API requests
Constant Summary collapse
- BASE_URL =
'https://%{key}:%{secret}@api.tolq.com/v1'.freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #delete(path, data = nil) ⇒ Object
- #get(path, data = nil) ⇒ Object
-
#initialize(key, secret) ⇒ Client
constructor
Creates a client to interface with the Tolq API.
- #post(path, data = nil) ⇒ Object
- #put(path, data = nil) ⇒ Object
-
#translation_requests ⇒ TranslationRequestApi
Via this method you can make requests to the Tolq API.
-
#valid_signature?(signature, payload) ⇒ Boolean
Verifies a signature on a callback payload You can find the signature in the X-Tolq-Signature header.
Constructor Details
#initialize(key, secret) ⇒ Client
Creates a client to interface with the Tolq API.
14 15 16 17 |
# File 'lib/tolq-api/client.rb', line 14 def initialize(key, secret) @key = key @secret = secret end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/tolq-api/client.rb', line 8 def key @key end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/tolq-api/client.rb', line 8 def secret @secret end |
Instance Method Details
#delete(path, data = nil) ⇒ Object
47 48 49 50 |
# File 'lib/tolq-api/client.rb', line 47 def delete(path, data = nil) response = do_request(:delete, path, data) handle_response(response) end |
#get(path, data = nil) ⇒ Object
37 38 39 40 |
# File 'lib/tolq-api/client.rb', line 37 def get(path, data = nil) response = do_request(:get, path, data) handle_response(response) end |
#post(path, data = nil) ⇒ Object
42 43 44 45 |
# File 'lib/tolq-api/client.rb', line 42 def post(path, data = nil) response = do_request(:post, path, data) handle_response(response) end |
#put(path, data = nil) ⇒ Object
52 53 54 55 |
# File 'lib/tolq-api/client.rb', line 52 def put(path, data = nil) response = do_request(:put, path, data) handle_response(response) end |
#translation_requests ⇒ TranslationRequestApi
Via this method you can make requests to the Tolq API
22 23 24 |
# File 'lib/tolq-api/client.rb', line 22 def translation_requests TranslationRequestApi.new(self) end |
#valid_signature?(signature, payload) ⇒ Boolean
Verifies a signature on a callback payload You can find the signature in the X-Tolq-Signature header
32 33 34 35 |
# File 'lib/tolq-api/client.rb', line 32 def valid_signature?(signature, payload) payload_signature = 'sha1=' + OpenSSL::HMAC.digest('sha1', self.key, payload) payload_signature == signature end |