Class: Trustpilot::ApiResource
- Inherits:
-
Object
- Object
- Trustpilot::ApiResource
- Defined in:
- lib/trustpilot/api_resource.rb
Direct Known Subclasses
Constant Summary collapse
- MUTEX =
Mutex.new
Instance Method Summary collapse
-
#request(path, auth_method:, params: {}, verb: 'get') ⇒ Object
Sends a request to the API.
Instance Method Details
#request(path, auth_method:, params: {}, verb: 'get') ⇒ Object
Sends a request to the API
This method will take care of authentication before calling the API, requesting a new access token if necessary.
args:
path: string
auth_method: 'oauth' | 'key'
params: { [key: string]: string }
verb: 'delete', 'get', 'patch', 'post', 'put'
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trustpilot/api_resource.rb', line 17 def request path, auth_method:, params: {}, verb: 'get' is_oauth = auth_method.to_s == 'oauth' MUTEX.synchronize do renew_token if is_oauth && Auth::Token.expired? call_api path, verb, auth_method, params rescue AuthenticationError # Invalid token/session, try again renew_token call_api path, verb, auth_method, params end end |