Class: Whatconverts::HttpService
- Inherits:
-
Object
- Object
- Whatconverts::HttpService
- Defined in:
- lib/whatconverts/http_service.rb
Constant Summary collapse
- API_URL =
'https://app.whatconverts.com/api/v1/'.freeze
Instance Attribute Summary collapse
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#api_token ⇒ Object
Returns the value of attribute api_token.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_token, api_secret) ⇒ HttpService
constructor
A new instance of HttpService.
- #make_request(endpoint, params = {}) ⇒ Object
Constructor Details
#initialize(api_token, api_secret) ⇒ HttpService
Returns a new instance of HttpService.
7 8 9 10 |
# File 'lib/whatconverts/http_service.rb', line 7 def initialize(api_token, api_secret) @api_token = api_token @api_secret = api_secret end |
Instance Attribute Details
#api_secret ⇒ Object
Returns the value of attribute api_secret.
5 6 7 |
# File 'lib/whatconverts/http_service.rb', line 5 def api_secret @api_secret end |
#api_token ⇒ Object
Returns the value of attribute api_token.
5 6 7 |
# File 'lib/whatconverts/http_service.rb', line 5 def api_token @api_token end |
Instance Method Details
#connection ⇒ Object
20 21 22 23 24 |
# File 'lib/whatconverts/http_service.rb', line 20 def connection conn = Faraday.new(url: API_URL) conn.basic_auth(api_token, api_secret) conn end |
#make_request(endpoint, params = {}) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/whatconverts/http_service.rb', line 12 def make_request(endpoint, params = {}) method = params.delete(:method) { :get } response = connection.send(method, endpoint, params) error = ErrorChecker.new(response).error_if_appropriate raise error if error JSON.parse(response.body) end |