Class: MxitApi::AuthToken
- Inherits:
-
Object
- Object
- MxitApi::AuthToken
- Defined in:
- lib/mxit_api/auth_token.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#refresh_token_expires_at ⇒ Object
readonly
Returns the value of attribute refresh_token_expires_at.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #has_expired? ⇒ Boolean
- #has_refresh_token_expired? ⇒ Boolean
- #has_scopes?(scopes) ⇒ Boolean
-
#initialize(token_response) ⇒ AuthToken
constructor
A new instance of AuthToken.
- #scope ⇒ Object
Constructor Details
#initialize(token_response) ⇒ AuthToken
Returns a new instance of AuthToken.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mxit_api/auth_token.rb', line 6 def initialize(token_response) @access_token = token_response['access_token'] @type = token_response['type'] @expires_in = token_response['expires_in'] @refresh_token = token_response['refresh_token'] @scope = token_response['scope'].split @expires_at = Time.now + expires_in.seconds # If there isn't a refresh token `has_refresh_token_expired?` must always return true. @refresh_token_expires_at = @refresh_token ? Time.now + 24.hours : Time.now end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def access_token @access_token end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def expires_at @expires_at end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def expires_in @expires_in end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def refresh_token @refresh_token end |
#refresh_token_expires_at ⇒ Object (readonly)
Returns the value of attribute refresh_token_expires_at.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def refresh_token_expires_at @refresh_token_expires_at end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/mxit_api/auth_token.rb', line 3 def type @type end |
Instance Method Details
#has_expired? ⇒ Boolean
22 23 24 25 |
# File 'lib/mxit_api/auth_token.rb', line 22 def has_expired? # For extreme latency check within 3 seconds. @expires_at - Time.now <= 3.0 end |
#has_refresh_token_expired? ⇒ Boolean
27 28 29 |
# File 'lib/mxit_api/auth_token.rb', line 27 def has_refresh_token_expired? @refresh_token_expires_at - Time.now <= 3.0 end |
#has_scopes?(scopes) ⇒ Boolean
31 32 33 |
# File 'lib/mxit_api/auth_token.rb', line 31 def has_scopes?(scopes) (scopes - @scope).empty? end |
#scope ⇒ Object
18 19 20 |
# File 'lib/mxit_api/auth_token.rb', line 18 def scope @scope.join(' ') end |