Class: Helpscout::Api::Auth::Token
- Inherits:
-
Object
- Object
- Helpscout::Api::Auth::Token
- Defined in:
- lib/helpscout/api/auth/token.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#initialize(endpoint: 'https://api.helpscout.net/v2/oauth2/token', client_id:, client_secret:, expires_in: 300) ⇒ Token
constructor
A new instance of Token.
- #refresh ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(endpoint: 'https://api.helpscout.net/v2/oauth2/token', client_id:, client_secret:, expires_in: 300) ⇒ Token
Returns a new instance of Token.
12 13 14 15 16 17 |
# File 'lib/helpscout/api/auth/token.rb', line 12 def initialize(endpoint: 'https://api.helpscout.net/v2/oauth2/token', client_id:, client_secret:, expires_in: 300) @endpoint = endpoint @expires_in = Time.now + expires_in @credentials = URI.encode_www_form(client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials') get_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/helpscout/api/auth/token.rb', line 10 def access_token @access_token end |
Instance Method Details
#refresh ⇒ Object
19 20 21 22 |
# File 'lib/helpscout/api/auth/token.rb', line 19 def refresh get_token if is_expired? || @access_token.nil? @access_token end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/helpscout/api/auth/token.rb', line 24 def to_s "Bearer #{@access_token}" end |