Class: RightSignature::TokenConnection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rightsignature/connection/token_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tokenObject (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, options)
  raise "Please set api_token" if @api_token.nil? || @api_token.empty?
  
  options[:headers] ||= {}
  options[:headers]['api-token'] = @api_token
  options[:headers]["Accept"] ||= "*/*"
  options[:headers]["content-type"] ||= "application/xml"
  self.class.__send__(method, url, options)
end