Class: TRMNLP::OAuth::TokenBundle
- Inherits:
-
Data
- Object
- Data
- TRMNLP::OAuth::TokenBundle
- Defined in:
- lib/trmnlp/oauth/token_bundle.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.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#token_type ⇒ Object
readonly
Returns the value of attribute token_type.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#merge_refresh(fresh) ⇒ Object
A refresh response often omits the rotated refresh_token (and sometimes other fields); the prior values remain valid, so carry them forward.
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token
5 6 7 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 5 def access_token @access_token end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at
5 6 7 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 5 def expires_at @expires_at end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token
5 6 7 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 5 def refresh_token @refresh_token end |
#token_type ⇒ Object (readonly)
Returns the value of attribute token_type
5 6 7 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 5 def token_type @token_type end |
Class Method Details
.from_h(hash) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 6 def self.from_h(hash) new( access_token: hash['access_token'], refresh_token: hash['refresh_token'], expires_at: hash['expires_at'], token_type: hash['token_type'] || 'Bearer' ) end |
Instance Method Details
#expired? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 15 def expired? return false unless expires_at # Treat as expired 5 minutes early so a token never dies mid-request. expires_at.to_i - 300 <= Time.now.to_i end |
#merge_refresh(fresh) ⇒ Object
A refresh response often omits the rotated refresh_token (and sometimes other fields); the prior values remain valid, so carry them forward.
24 25 26 27 28 29 30 31 |
# File 'lib/trmnlp/oauth/token_bundle.rb', line 24 def merge_refresh(fresh) with( access_token: fresh.access_token, refresh_token: fresh.refresh_token || refresh_token, expires_at: fresh.expires_at || expires_at, token_type: fresh.token_type || token_type ) end |