Class: TCGPlayerSDK::BearerToken

Inherits:
Object
  • Object
show all
Defined in:
lib/tcg-player-sdk/bearer_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BearerToken

Returns a new instance of BearerToken.



4
5
6
7
8
9
# File 'lib/tcg-player-sdk/bearer_token.rb', line 4

def initialize(params = {})
  self.expires_in = params['expires_in']
  self.token = params['access_token']
  self.issued = DateTime.parse(params['.issued'])
  self.expiration = DateTime.parse(params['.expires'])
end

Instance Attribute Details

#expirationObject

Returns the value of attribute expiration.



2
3
4
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2

def expiration
  @expiration
end

#expires_inObject

Returns the value of attribute expires_in.



2
3
4
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2

def expires_in
  @expires_in
end

#issuedObject

Returns the value of attribute issued.



2
3
4
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2

def issued
  @issued
end

#tokenObject

Returns the value of attribute token.



2
3
4
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2

def token
  @token
end

Instance Method Details

#expired?Boolean

Returns true if the bearer token is within five minutes of expiring.

Returns:

  • (Boolean)

    true if the bearer token is within five minutes of expiring



13
14
15
# File 'lib/tcg-player-sdk/bearer_token.rb', line 13

def expired?
  return expiration.nil? || (DateTime.now >= expiration)
end

#to_jsonObject



21
22
23
24
25
26
27
28
29
# File 'lib/tcg-player-sdk/bearer_token.rb', line 21

def to_json
  h = {
    access_token: token,
    token_type: 'bearer',
    expires_in: expires_in,
    '.issued' => issued.to_s,
    '.expires' => expiration.to_s,
  }.to_json
end

#to_sObject



17
18
19
# File 'lib/tcg-player-sdk/bearer_token.rb', line 17

def to_s
  ap self, indent: -2
end