Class: TCGPlayerSDK::BearerToken
- Inherits:
-
Object
- Object
- TCGPlayerSDK::BearerToken
- Defined in:
- lib/tcg-player-sdk/bearer_token.rb
Instance Attribute Summary collapse
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#issued ⇒ Object
Returns the value of attribute issued.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
True if the bearer token is within five minutes of expiring.
-
#initialize(params = {}) ⇒ BearerToken
constructor
A new instance of BearerToken.
- #to_json ⇒ Object
- #to_s ⇒ Object
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
#expiration ⇒ Object
Returns the value of attribute expiration.
2 3 4 |
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2 def expiration @expiration end |
#expires_in ⇒ Object
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 |
#issued ⇒ Object
Returns the value of attribute issued.
2 3 4 |
# File 'lib/tcg-player-sdk/bearer_token.rb', line 2 def issued @issued end |
#token ⇒ Object
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.
13 14 15 |
# File 'lib/tcg-player-sdk/bearer_token.rb', line 13 def expired? return expiration.nil? || (DateTime.now >= expiration) end |
#to_json ⇒ Object
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_s ⇒ Object
17 18 19 |
# File 'lib/tcg-player-sdk/bearer_token.rb', line 17 def to_s ap self, indent: -2 end |