Class: RightSignature::TokenConnection
- Inherits:
-
Object
- Object
- RightSignature::TokenConnection
- Includes:
- HTTParty
- Defined in:
- lib/rightsignature/connection/token_connection.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
Instance Method Summary collapse
-
#initialize(api_token) ⇒ TokenConnection
constructor
Creates new instance of RightSignature::TokenConnection to make API calls * api_token: API Token.
-
#request(method, url, options) ⇒ Object
Generates HTTP request with token credentials.
Constructor Details
#initialize(api_token) ⇒ TokenConnection
Creates new instance of RightSignature::TokenConnection to make API calls
-
api_token: API Token.
Example:
@rs_token = RightSignature::TokenConnection.new("APITOKEN")
15 16 17 |
# File 'lib/rightsignature/connection/token_connection.rb', line 15 def initialize(api_token) @api_token = api_token end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
7 8 9 |
# File 'lib/rightsignature/connection/token_connection.rb', line 7 def api_token @api_token end |
Instance Method Details
#request(method, url, options) ⇒ Object
Generates HTTP request with token credentials. Require api_token to be set.
-
method: HTTP Method. Ex. (‘get’/‘post’/‘delete’/‘put’)
-
url: request path/url of request
-
options: HTTPary options to pass. Last option should be headers
24 25 26 27 28 29 30 31 32 |
# File 'lib/rightsignature/connection/token_connection.rb', line 24 def request(method, url, ) raise "Please set api_token" if @api_token.nil? || @api_token.empty? [:headers] ||= {} [:headers]['api-token'] = @api_token [:headers]["Accept"] ||= "*/*" [:headers]["content-type"] ||= "application/xml" self.class.__send__(method, url, ) end |