Module: Profitwell::Common

Includes:
HTTParty
Included in:
Client
Defined in:
lib/profitwell/common.rb

Constant Summary collapse

ERROR_CODES =
{
  400 => BadRequest,
  401 => Unauthorized,
  404 => NotFound,
  502 => BadGateway,
}.freeze

Instance Method Summary collapse

Instance Method Details

#request(http_method, endpoint, options: {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/profitwell/common.rb', line 18

def request(http_method, endpoint, options: {})
  response = HTTParty.send(http_method, endpoint, params(options).merge!(authorization_header))
  if response.success?
    parse_success response
  else
    parse_failed response
  end
end

#resource_path(path = nil, options = "") ⇒ Object



12
13
14
15
16
# File 'lib/profitwell/common.rb', line 12

def resource_path(path = nil, options = "")
  return "#{base_endpoint}/#{path}/?#{options}" if options.nil?

  "#{base_endpoint}/#{path}/"
end