class Whatconverts::HttpService

Constants

API_URL

Attributes

api_secret[RW]
api_token[RW]

Public Class Methods

new(api_token, api_secret) click to toggle source
# File lib/whatconverts/http_service.rb, line 7
def initialize(api_token, api_secret)
  @api_token = api_token
  @api_secret = api_secret
end

Public Instance Methods

connection() click to toggle source
# 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 = {}) click to toggle source
# 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