Class: Smileback::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/smileback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, refresh_token:, expires_at:, expires: true) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
# File 'lib/smileback.rb', line 15

def initialize(token:, refresh_token:, expires_at:, expires: true)
  self.class.base_uri Smileback.configuration.api_base_url

  @access_token = OAuth2::AccessToken.new(
    oauth2_client,
    token, { expires_at: expires_at, refresh_token: refresh_token }
  )
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



13
14
15
# File 'lib/smileback.rb', line 13

def access_token
  @access_token
end

Instance Method Details

#credentialsHash

Latest OAuth2 credentials based on access_token. The original token may need to be refreshed during usage, so always check here for the latest values when finished.

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
# File 'lib/smileback.rb', line 28

def credentials
  {
    token: access_token.token,
    refresh_token: access_token.refresh_token,
    expires_at: access_token.expires_at,
    expires: true
  }
end

#get(path, query = {}) ⇒ HTTParty::Response

Make a GET request to the API.

Parameters:

  • path (String)

    endpoint; ā€˜/v3/reviews/ā€™

  • query (Hash) (defaults to: {})

    query params; { modified_since: ā€˜2017-10-27T07:43:15Zā€™ }

Returns:

  • (HTTParty::Response)


42
43
44
45
46
47
48
49
# File 'lib/smileback.rb', line 42

def get(path, query = {})
  refresh_access_token

  self.class.get(path, {
    headers: { Authorization: "Bearer #{access_token.token}" },
    query: query
  })
end