class ConnectorKit::HTTPClient

Simple HTTP client wrapper for HTTParty

Public Class Methods

new(target_uri) click to toggle source
# File lib/connector_kit/httpclient.rb, line 10
def initialize(target_uri)
  self.class.base_uri(target_uri)
end

Public Instance Methods

get(url, response_mapper) click to toggle source
# File lib/connector_kit/httpclient.rb, line 14
def get(url, response_mapper)
  response = self.class.get(url)

  raise make_api_error(response) unless response.code == 200

  response_mapper.map(response.parsed_response['data'])
end

Private Instance Methods

make_api_error(response) click to toggle source
# File lib/connector_kit/httpclient.rb, line 24
def make_api_error(response)
  # For the time being, the first error received is enough
  error = response.parsed_response['errors'].first
  APIError.new(error['title'], error['detail'], error['status'])
end