Class: Doconomy::Api::Token
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_description ⇒ Object
readonly
Returns the value of attribute error_description.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#token_type ⇒ Object
readonly
Returns the value of attribute token_type.
Attributes inherited from Base
Class Method Summary collapse
-
.create ⇒ Doconomy::Api::Token
Creates new token.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true if token has error.
-
#expired? ⇒ Boolean
Returns true if token has been expired.
-
#initialize(attributes = {}) ⇒ Token
constructor
A new instance of Token.
Methods inherited from Base
Constructor Details
#initialize(attributes = {}) ⇒ Token
Returns a new instance of Token.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/doconomy/api/token.rb', line 8 def initialize(attributes = {}) @attributes = attributes.deep_symbolize_keys @access_token = @attributes[:access_token] @scope = @attributes[:scope] @token_type = @attributes[:token_type] @expires_in = @attributes[:expires_in] @expires_at = Time.current + @expires_in.to_i if @expires_in @error_description = @attributes[:error_description] @error = @attributes[:error] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def access_token @access_token end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def error @error end |
#error_description ⇒ Object (readonly)
Returns the value of attribute error_description.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def error_description @error_description end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def expires_at @expires_at end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def expires_in @expires_in end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def scope @scope end |
#token_type ⇒ Object (readonly)
Returns the value of attribute token_type.
6 7 8 |
# File 'lib/doconomy/api/token.rb', line 6 def token_type @token_type end |
Class Method Details
.create ⇒ Doconomy::Api::Token
Creates new token
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/doconomy/api/token.rb', line 40 def create scope = Doconomy::Api.configuration.scope scope = scope.join(',') if scope.is_a?(Array) payload = { grant_type: 'client_credentials', scope: scope, client_id: Doconomy::Api.configuration.client_id, client_secret: Doconomy::Api.configuration.client_secret } new(client.post('/oidc/v1.0/token', payload, { 'Content-Type' => 'application/x-www-form-urlencoded' }, with_authorization: false)) end |
Instance Method Details
#error? ⇒ Boolean
Returns true if token has error
31 32 33 |
# File 'lib/doconomy/api/token.rb', line 31 def error? !error.nil? end |
#expired? ⇒ Boolean
Returns true if token has been expired
23 24 25 |
# File 'lib/doconomy/api/token.rb', line 23 def expired? !expires_at.nil? && expires_at <= Time.current end |