Class: Smileback::Client
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#credentials ⇒ Hash
Latest OAuth2 credentials based on access_token.
-
#get(path, query = {}) ⇒ HTTParty::Response
Make a GET request to the API.
-
#initialize(token:, refresh_token:, expires_at:, expires: true) ⇒ Client
constructor
A new instance of Client.
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_token ⇒ Object
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
#credentials ⇒ Hash
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.
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.
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 |