Class: Hashblue::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/hashblue/access_token.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ AccessToken

Returns a new instance of AccessToken.



3
4
5
# File 'lib/hashblue/access_token.rb', line 3

def initialize(access_token)
  @access_token = access_token
end

Instance Method Details

#clientObject



29
30
31
# File 'lib/hashblue/access_token.rb', line 29

def client
  @client ||= Client.new(self)
end

#refresh_with(client_identifier, client_secret, refresh_token) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/hashblue/access_token.rb', line 18

def refresh_with(client_identifier, client_secret, refresh_token)
  response = client.post '/oauth/access_token', {
    'grant_type' => 'refresh_token',
    'refresh_token' => refresh_token,
    'client_id' => client_identifier,
    'client_secret' => client_secret
  }, nil
  @access_token = response["access_token"]
  response
end

#to_sObject



7
8
9
# File 'lib/hashblue/access_token.rb', line 7

def to_s
  @access_token
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/hashblue/access_token.rb', line 11

def valid?
  client.head '/account'
  true
rescue Client::RequestError
  false
end