Sha256: 8ef3b58ff9988db3e36f4e332d4cc359a3a3a04fb8ef6ba4ce3a5f4be6b5a988

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

# 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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
oneaccess-1.0.0 lib/oneaccess/http/http_client.rb
oneaccess-0.5.0 lib/oneaccess/http/http_client.rb
oneaccess-0.4.5 lib/oneaccess/http/http_client.rb
oneaccess-0.4.4 lib/oneaccess/http/http_client.rb
oneaccess-0.4.3 lib/oneaccess/http/http_client.rb
oneaccess-0.4.2 lib/oneaccess/http/http_client.rb
oneaccess-0.4.1 lib/oneaccess/http/http_client.rb
oneaccess-0.4.0 lib/oneaccess/http/http_client.rb
oneaccess-0.3.0 lib/oneaccess/http/http_client.rb
oneaccess-0.2.0 lib/oneaccess/http/http_client.rb