lib/amazon_flex_pay/api.rb
def submit(request)
      url = request.to_url
      ActiveSupport::Notifications.instrument("amazon_flex_pay.api", :action => request.action_name, :request => url) do |payload|
        begin
          http = RestClient.get(url)

          payload[:response] = http.body
          payload[:code] = http.code

          response = request.class::Response.from_xml(http.body)
          response.request = request
          response

        rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::Forbidden => e
          payload[:response] = e.http_body
          payload[:code] = e.http_code

          er = AmazonFlexPay::API::BaseRequest::ErrorResponse.from_xml(e.response.body)
          klass = AmazonFlexPay::API.const_get(er.errors.first.code)
          raise klass.new(er.errors.first.code, er.errors.first.message, er.request_id, request)
        end
      end
    end
def submit(request)
      url = request.to_url
      ActiveSupport::Notifications.instrument("amazon_flex_pay.api", :action => request.action_name, :request => url) do |payload|
        begin
          http = RestClient.get(url)

          payload[:response] = http.body
          payload[:code] = http.code

          response = request.class::Response.from_xml(http.body)
          response.request = request
          response

        rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::Forbidden => e
          payload[:response] = e.http_body
          payload[:code] = e.http_code

          er = AmazonFlexPay::API::BaseRequest::ErrorResponse.from_xml(e.response.body)
          klass = AmazonFlexPay::API.const_get(er.errors.first.code)
          raise klass.new(er.errors.first.code, er.errors.first.message, er.request_id, request)
        end
      end
    end
This compiles an API request object into a URL, sends it to Amazon, and processes
 the response.