Class: Basecamp::Oauth::Token
- Inherits:
-
Data
- Object
- Data
- Basecamp::Oauth::Token
- Defined in:
- lib/basecamp/oauth/token.rb
Overview
OAuth 2 access token response.
Instance Attribute Summary collapse
-
#access_token ⇒ String
readonly
The access token string.
-
#expires_at ⇒ Time?
readonly
Calculated expiration time.
-
#expires_in ⇒ Integer?
readonly
Lifetime of the access token in seconds.
-
#refresh_token ⇒ String?
readonly
The refresh token string.
-
#scope ⇒ String?
readonly
OAuth scope granted.
-
#token_type ⇒ String
readonly
Token type (usually "Bearer").
Instance Method Summary collapse
-
#expired?(buffer_seconds = 60) ⇒ Boolean
Checks if the token is expired or about to expire.
-
#initialize(access_token:, token_type: "Bearer", refresh_token: nil, expires_in: nil, expires_at: nil, scope: nil) ⇒ Token
constructor
A new instance of Token.
Constructor Details
#initialize(access_token:, token_type: "Bearer", refresh_token: nil, expires_in: nil, expires_at: nil, scope: nil) ⇒ Token
Returns a new instance of Token.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/basecamp/oauth/token.rb', line 21 def initialize( access_token:, token_type: "Bearer", refresh_token: nil, expires_in: nil, expires_at: nil, scope: nil ) # Calculate expires_at from expires_in if not provided calculated_expires_at = expires_at || (expires_in ? Time.now + expires_in : nil) super( access_token: access_token, token_type: token_type, refresh_token: refresh_token, expires_in: expires_in, expires_at: calculated_expires_at, scope: scope ) end |
Instance Attribute Details
#access_token ⇒ String (readonly)
The access token string
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def access_token @access_token end |
#expires_at ⇒ Time? (readonly)
Calculated expiration time
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def expires_at @expires_at end |
#expires_in ⇒ Integer? (readonly)
Lifetime of the access token in seconds
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def expires_in @expires_in end |
#refresh_token ⇒ String? (readonly)
The refresh token string
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def refresh_token @refresh_token end |
#scope ⇒ String? (readonly)
OAuth scope granted
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def scope @scope end |
#token_type ⇒ String (readonly)
Token type (usually "Bearer")
13 14 15 |
# File 'lib/basecamp/oauth/token.rb', line 13 def token_type @token_type end |
Instance Method Details
#expired?(buffer_seconds = 60) ⇒ Boolean
Checks if the token is expired or about to expire.
45 46 47 48 49 |
# File 'lib/basecamp/oauth/token.rb', line 45 def expired?(buffer_seconds = 60) return false unless expires_at Time.now + buffer_seconds >= expires_at end |