class Doconomy::Api::Token
Attributes
access_token[R]
error[R]
error_description[R]
expires_at[R]
expires_in[R]
scope[R]
token_type[R]
Public Class Methods
create()
click to toggle source
Creates new token
@return [Doconomy::Api::Token]
# 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
new(attributes = {})
click to toggle source
# 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
Public Instance Methods
error?()
click to toggle source
Returns true if token has error
@return [Boolean]
# File lib/doconomy/api/token.rb, line 31 def error? !error.nil? end
expired?()
click to toggle source
Returns true if token has been expired
@return [Boolean]
# File lib/doconomy/api/token.rb, line 23 def expired? !expires_at.nil? && expires_at <= Time.current end