Class: ActiveMerchant::Connection
- Inherits:
-
Object
- Object
- ActiveMerchant::Connection
- Includes:
- NetworkConnectionRetries
- Defined in:
- lib/active_merchant/connection.rb
Direct Known Subclasses
Constant Summary collapse
- MAX_RETRIES =
3
- OPEN_TIMEOUT =
60
- READ_TIMEOUT =
60
- VERIFY_PEER =
true
- CA_FILE =
File.('../certs/cacert.pem', File.dirname(__FILE__))
- CA_PATH =
nil
- MIN_VERSION =
:TLS1_1
- RETRY_SAFE =
false
- RUBY_184_POST_HEADERS =
{ 'Content-Type' => 'application/x-www-form-urlencoded' }
Constants included from NetworkConnectionRetries
NetworkConnectionRetries::DEFAULT_CONNECTION_ERRORS, NetworkConnectionRetries::DEFAULT_RETRIES
Instance Attribute Summary collapse
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#ca_path ⇒ Object
Returns the value of attribute ca_path.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#ignore_http_status ⇒ Object
Returns the value of attribute ignore_http_status.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#max_version ⇒ Object
Returns the value of attribute max_version.
-
#min_version ⇒ Object
Returns the value of attribute min_version.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#pem ⇒ Object
Returns the value of attribute pem.
-
#pem_password ⇒ Object
Returns the value of attribute pem_password.
-
#proxy_address ⇒ Object
Returns the value of attribute proxy_address.
-
#proxy_password ⇒ Object
Returns the value of attribute proxy_password.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#ssl_connection ⇒ Object
readonly
Returns the value of attribute ssl_connection.
-
#ssl_version ⇒ Object
Returns the value of attribute ssl_version.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
-
#wiredump_device ⇒ Object
Returns the value of attribute wiredump_device.
Instance Method Summary collapse
-
#initialize(endpoint) ⇒ Connection
constructor
A new instance of Connection.
- #request(method, body, headers = {}) ⇒ Object
Methods included from NetworkConnectionRetries
included, log, #retry_exceptions
Constructor Details
#initialize(endpoint) ⇒ Connection
Returns a new instance of Connection.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_merchant/connection.rb', line 29 def initialize(endpoint) @endpoint = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint) @open_timeout = OPEN_TIMEOUT @read_timeout = READ_TIMEOUT @retry_safe = RETRY_SAFE @verify_peer = VERIFY_PEER @ca_file = CA_FILE @ca_path = CA_PATH @max_retries = MAX_RETRIES @ignore_http_status = false @ssl_version = nil if Net::HTTP.instance_methods.include?(:min_version=) @min_version = MIN_VERSION @max_version = nil end @ssl_connection = {} @proxy_address = :ENV @proxy_port = nil @proxy_user = nil @proxy_password = nil end |
Instance Attribute Details
#ca_file ⇒ Object
Returns the value of attribute ca_file.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def ca_file @ca_file end |
#ca_path ⇒ Object
Returns the value of attribute ca_path.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def ca_path @ca_path end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def endpoint @endpoint end |
#ignore_http_status ⇒ Object
Returns the value of attribute ignore_http_status.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def ignore_http_status @ignore_http_status end |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def max_retries @max_retries end |
#max_version ⇒ Object
Returns the value of attribute max_version.
25 26 27 |
# File 'lib/active_merchant/connection.rb', line 25 def max_version @max_version end |
#min_version ⇒ Object
Returns the value of attribute min_version.
24 25 26 |
# File 'lib/active_merchant/connection.rb', line 24 def min_version @min_version end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def open_timeout @open_timeout end |
#pem ⇒ Object
Returns the value of attribute pem.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def pem @pem end |
#pem_password ⇒ Object
Returns the value of attribute pem_password.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def pem_password @pem_password end |
#proxy_address ⇒ Object
Returns the value of attribute proxy_address.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def proxy_address @proxy_address end |
#proxy_password ⇒ Object
Returns the value of attribute proxy_password.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def proxy_password @proxy_password end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def proxy_user @proxy_user end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def read_timeout @read_timeout end |
#ssl_connection ⇒ Object (readonly)
Returns the value of attribute ssl_connection.
27 28 29 |
# File 'lib/active_merchant/connection.rb', line 27 def ssl_connection @ssl_connection end |
#ssl_version ⇒ Object
Returns the value of attribute ssl_version.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def ssl_version @ssl_version end |
#tag ⇒ Object
Returns the value of attribute tag.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def tag @tag end |
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
21 22 23 |
# File 'lib/active_merchant/connection.rb', line 21 def verify_peer @verify_peer end |
#wiredump_device ⇒ Object
Returns the value of attribute wiredump_device.
27 28 29 |
# File 'lib/active_merchant/connection.rb', line 27 def wiredump_device @wiredump_device end |
Instance Method Details
#request(method, body, headers = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_merchant/connection.rb', line 57 def request(method, body, headers = {}) request_start = Process.clock_gettime(Process::CLOCK_MONOTONIC) headers = headers.dup headers['connection'] ||= 'close' retry_exceptions(max_retries: max_retries, logger: logger, tag: tag) do info "connection_http_method=#{method.to_s.upcase} connection_uri=#{endpoint}", tag result = nil realtime = Benchmark.realtime do http.start unless http.started? @ssl_connection = http.ssl_connection info "connection_ssl_version=#{ssl_connection[:version]} connection_ssl_cipher=#{ssl_connection[:cipher]}", tag result = case method when :get http.get(endpoint.request_uri, headers) when :post debug body http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers)) when :put debug body http.put(endpoint.request_uri, body, headers) when :patch debug body http.patch(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. if body debug body req = Net::HTTP::Delete.new(endpoint.request_uri, headers) req.body = body http.request(req) else http.delete(endpoint.request_uri, headers) end else raise ArgumentError, "Unsupported request method #{method.to_s.upcase}" end end info '--> %d %s (%d %.4fs)' % [result.code, result., result.body ? result.body.length : 0, realtime], tag debug result.body result end ensure info 'connection_request_total_time=%.4fs' % [Process.clock_gettime(Process::CLOCK_MONOTONIC) - request_start], tag http.finish if http.started? end |