Class: Maventa::AccessToken
- Inherits:
-
Object
- Object
- Maventa::AccessToken
- Defined in:
- lib/maventa/access_token.rb
Constant Summary collapse
- EXPIRATION_MARGIN =
60
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_type ⇒ Object
Returns the value of attribute token_type.
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #expired_or_about_to_expire? ⇒ Boolean
-
#initialize(token:, expires_in:, token_type:, scope:) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #scopes ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(token:, expires_in:, token_type:, scope:) ⇒ AccessToken
Returns a new instance of AccessToken.
7 8 9 10 11 12 13 |
# File 'lib/maventa/access_token.rb', line 7 def initialize(token:, expires_in:, token_type:, scope:) @token = token @expires_in = expires_in @expires_at = Time.now.to_i + expires_in @token_type = token_type @scope = scope end |
Instance Attribute Details
#expires_at ⇒ Object
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/maventa/access_token.rb', line 3 def expires_at @expires_at end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/maventa/access_token.rb', line 3 def expires_in @expires_in end |
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/maventa/access_token.rb', line 3 def scope @scope end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/maventa/access_token.rb', line 3 def token @token end |
#token_type ⇒ Object
Returns the value of attribute token_type.
3 4 5 |
# File 'lib/maventa/access_token.rb', line 3 def token_type @token_type end |
Instance Method Details
#expired? ⇒ Boolean
19 20 21 |
# File 'lib/maventa/access_token.rb', line 19 def expired? Time.now.to_i > @expires_at end |
#expired_or_about_to_expire? ⇒ Boolean
27 28 29 |
# File 'lib/maventa/access_token.rb', line 27 def expired_or_about_to_expire? Time.now.to_i > (@expires_at - EXPIRATION_MARGIN) end |
#scopes ⇒ Object
15 16 17 |
# File 'lib/maventa/access_token.rb', line 15 def scopes @scope.split " " end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/maventa/access_token.rb', line 23 def valid? !expired? end |