Class: Doconomy::Api::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/doconomy/api/token.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, #errors

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_tokenObject (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

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/doconomy/api/token.rb', line 6

def error
  @error
end

#error_descriptionObject (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_atObject (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_inObject (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

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/doconomy/api/token.rb', line 6

def scope
  @scope
end

#token_typeObject (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

.createDoconomy::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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


23
24
25
# File 'lib/doconomy/api/token.rb', line 23

def expired?
  !expires_at.nil? && expires_at <= Time.current
end