Class: K2AccessToken
- Inherits:
-
Object
- Object
- K2AccessToken
- Defined in:
- lib/k2-connect-ruby/k2_financial_entity/k2_token.rb
Overview
Class for Gaining Access Token
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Class Method Summary collapse
-
.make_hash(path_url, request, class_type, body) ⇒ Object
Create a Hash containing important details accessible for K2Connect.
Instance Method Summary collapse
-
#initialize(client_id, client_secret) ⇒ K2AccessToken
constructor
A new instance of K2AccessToken.
-
#request_token ⇒ Object
Method for sending the request to K2 sandbox or Mock Server (Receives the access_token).
- #validate_client_credentials(client_id, client_secret) ⇒ Object
Constructor Details
#initialize(client_id, client_secret) ⇒ K2AccessToken
Returns a new instance of K2AccessToken.
5 6 7 8 9 |
# File 'lib/k2-connect-ruby/k2_financial_entity/k2_token.rb', line 5 def initialize(client_id, client_secret) validate_client_credentials(client_id, client_secret) @client_id = client_id @client_secret = client_secret end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/k2-connect-ruby/k2_financial_entity/k2_token.rb', line 3 def access_token @access_token end |
Class Method Details
.make_hash(path_url, request, class_type, body) ⇒ Object
Create a Hash containing important details accessible for K2Connect
28 29 30 31 32 33 34 35 |
# File 'lib/k2-connect-ruby/k2_financial_entity/k2_token.rb', line 28 def make_hash(path_url, request, class_type, body) { path_url: path_url, request_type: request, class_type: class_type, params: body }.with_indifferent_access end |
Instance Method Details
#request_token ⇒ Object
Method for sending the request to K2 sandbox or Mock Server (Receives the access_token)
12 13 14 15 16 17 18 19 20 |
# File 'lib/k2-connect-ruby/k2_financial_entity/k2_token.rb', line 12 def request_token token_params = { client_id: @client_id, client_secret: @client_secret, grant_type: 'client_credentials' } token_hash = K2AccessToken.make_hash(K2Config.path_url('oauth_token'), 'post', 'Access Token', token_params) @access_token = K2Connect.make_request(token_hash) end |
#validate_client_credentials(client_id, client_secret) ⇒ Object
22 23 24 |
# File 'lib/k2-connect-ruby/k2_financial_entity/k2_token.rb', line 22 def validate_client_credentials(client_id, client_secret) raise ArgumentError, 'Nil or Empty Client Id or Secret!' if client_id.blank? || client_secret.blank? end |