Method: EasyPost::Client#make_request

Defined in:
lib/easypost/client.rb

#make_request(method, endpoint, body = nil, api_version = EasyPost::InternalUtilities::Constants::API_VERSION) ⇒ Hash

Make an HTTP request

Parameters:

  • method (Symbol)

    the HTTP Verb (get, method, put, post, etc.)

  • endpoint (String)

    URI path of the resource

  • body (Object) (defaults to: nil)

    (nil) object to be dumped to JSON

  • api_version (String) (defaults to: EasyPost::InternalUtilities::Constants::API_VERSION)

    the version of API to hit

Returns:

  • (Hash)

    JSON object parsed from the response body

Raises:

  • (EasyPost::Error)

    if the response has a non-2xx status code



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/easypost/client.rb', line 79

def make_request(
  method,
  endpoint,
  body = nil,
  api_version = EasyPost::InternalUtilities::Constants::API_VERSION
)
  response = @http_client.request(method, endpoint, nil, body, api_version)

  potential_error = EasyPost::Errors::ApiError.handle_api_error(response)
  raise potential_error unless potential_error.nil?

  EasyPost::InternalUtilities::Json.parse_json(response.body)
end