class AmexEnhancedAuthorization::Request

Amex requests use extended headers and a JSON body.

Attributes

authorization[R]
client_id[R]

Public Class Methods

new(method, path, client_id, logger) click to toggle source
# File lib/amex_enhanced_authorization/request.rb, line 8
def initialize(method, path, client_id, logger)
  super(method, path, logger)
  @client_id = client_id
end

Public Instance Methods

fail_unless_expected_response(response, *allowed_responses) click to toggle source
# File lib/amex_enhanced_authorization/request.rb, line 41
def fail_unless_expected_response(response, *allowed_responses)
  unless allowed_responses.any? { |allowed| response.is_a?(allowed) }
    logger.error "#{response.inspect}: #{response.body}"
    raise UnexpectedHttpResponse, response
  end
  response
end
headers() click to toggle source
# File lib/amex_enhanced_authorization/request.rb, line 22
def headers
  Hash[
    'Content-Type' => 'application/json; charset=utf-8',
    'Content-Language' => 'en-US',
    'x-amex-api-key' => client_id,
    'x-amex-request-id' => SecureRandom.uuid,
    'authorization' => authorization,
  ]
end
send(data, authorization) click to toggle source

Return response on success or log failure and throw error.

# File lib/amex_enhanced_authorization/request.rb, line 14
def send(data, authorization)
  @authorization = authorization
  request.body = data if data
  response = super(data)
  fail_unless_expected_response response, Net::HTTPSuccess
  response.body
end