Class: Helpscout::Api::Auth::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/helpscout/api/auth/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tokenObject (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

#refreshObject



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_sObject



24
25
26
# File 'lib/helpscout/api/auth/token.rb', line 24

def to_s
  "Bearer #{@access_token}"
end