Sha256: 823557fb4f112c7aa09e85e59bfd45740690ca087cb32ca08defce4dad93baf8

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

module ActiveMerchant
  class Connection
    def request(method, body, headers = {})
      request_start = Time.now.to_f

      retry_exceptions(:max_retries => max_retries, :logger => logger, :tag => tag) do
        begin
          info "connection_http_method=#{method.to_s.upcase} connection_uri=#{endpoint}", tag

          result = nil

          realtime = Benchmark.realtime do
            result = case method
            when :get
              raise ArgumentError, "GET requests do not support a request body" if body
              http.get(endpoint.request_uri, headers)
            when :post
              debug body
              http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers))
            when :patch
              debug body
              http.patch(endpoint.request_uri, body, headers)
            when :put
              debug body
              http.put(endpoint.request_uri, body, headers)
            when :delete
              # It's kind of ambiguous whether the RFC allows bodies
              # for DELETE requests. But Net::HTTP's delete method
              # very unambiguously does not.
              raise ArgumentError, "DELETE requests do not support a request body" if body
              http.delete(endpoint.request_uri, headers)
            else
              raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
            end
          end

          info "--> %d %s (%d %.4fs)" % [result.code, result.message, result.body ? result.body.length : 0, realtime], tag
          debug result.body
          result
        end
      end

    ensure
      info "connection_request_total_time=%.4fs" % [Time.now.to_f - request_start], tag
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_komoju-0.1.4 lib/ext/activemerchant/connection.rb
spree_komoju-0.1.3 lib/ext/activemerchant/connection.rb
spree_komoju-0.1.2 lib/ext/activemerchant/connection.rb
spree_komoju-0.1.1 lib/ext/activemerchant/connection.rb
spree_komoju-0.1.0 lib/ext/activemerchant/connection.rb
spree_komoju-0.0.9 lib/ext/activemerchant/connection.rb
spree_komoju-0.0.8 lib/ext/activemerchant/connection.rb
spree_komoju-0.0.7 lib/ext/activemerchant/connection.rb
spree_komoju-0.0.6 lib/ext/activemerchant/connection.rb