# frozen_string_literal: true module ONEAccess module Http class HttpClient class << self def get(url, params = {}) RestClient.get(url, { params: params }.merge(auth_headers)) rescue RestClient::Exception => e raise create_api_error(e) end def post(url, body, headers = {}) RestClient.post(url, body.to_json, headers.merge(auth_headers)) rescue RestClient::Exception => e raise create_api_error(e) end private def create_api_error(error) api_error_data = Response::APIError.new Response::Representer::APIError.new(api_error_data).from_json(error.http_body) Error::APIError.new(error.http_code, api_error_data.api_status_code, api_error_data.api_status_message) end def auth_headers { "X-One-Access-Api-Key" => Configuration.api_key, "Authorization" => "X-One-Access-Master-Api-Key #{Configuration.master_api_key}" } end end end end end