Class: ActiveMerchant::Connection
- Inherits:
-
Object
- Object
- ActiveMerchant::Connection
- Includes:
- NetworkConnectionRetries
- Defined in:
- lib/active_utils/common/connection.rb
Constant Summary collapse
- MAX_RETRIES =
3
- OPEN_TIMEOUT =
60
- READ_TIMEOUT =
60
- VERIFY_PEER =
true
- CA_FILE =
(File.dirname(__FILE__) + '/../../certs/cacert.pem')
- CA_PATH =
nil
- 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.
-
#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_port ⇒ Object
Returns the value of attribute proxy_port.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#retry_safe ⇒ Object
Returns the value of attribute retry_safe.
-
#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
Constructor Details
#initialize(endpoint) ⇒ Connection
Returns a new instance of Connection.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_utils/common/connection.rb', line 37 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 @proxy_address = nil @proxy_port = nil end |
Instance Attribute Details
#ca_file ⇒ Object
Returns the value of attribute ca_file.
24 25 26 |
# File 'lib/active_utils/common/connection.rb', line 24 def ca_file @ca_file end |
#ca_path ⇒ Object
Returns the value of attribute ca_path.
25 26 27 |
# File 'lib/active_utils/common/connection.rb', line 25 def ca_path @ca_path end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
19 20 21 |
# File 'lib/active_utils/common/connection.rb', line 19 def endpoint @endpoint end |
#ignore_http_status ⇒ Object
Returns the value of attribute ignore_http_status.
32 33 34 |
# File 'lib/active_utils/common/connection.rb', line 32 def ignore_http_status @ignore_http_status end |
#logger ⇒ Object
Returns the value of attribute logger.
30 31 32 |
# File 'lib/active_utils/common/connection.rb', line 30 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
33 34 35 |
# File 'lib/active_utils/common/connection.rb', line 33 def max_retries @max_retries end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
20 21 22 |
# File 'lib/active_utils/common/connection.rb', line 20 def open_timeout @open_timeout end |
#pem ⇒ Object
Returns the value of attribute pem.
27 28 29 |
# File 'lib/active_utils/common/connection.rb', line 27 def pem @pem end |
#pem_password ⇒ Object
Returns the value of attribute pem_password.
28 29 30 |
# File 'lib/active_utils/common/connection.rb', line 28 def pem_password @pem_password end |
#proxy_address ⇒ Object
Returns the value of attribute proxy_address.
34 35 36 |
# File 'lib/active_utils/common/connection.rb', line 34 def proxy_address @proxy_address end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
35 36 37 |
# File 'lib/active_utils/common/connection.rb', line 35 def proxy_port @proxy_port end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
21 22 23 |
# File 'lib/active_utils/common/connection.rb', line 21 def read_timeout @read_timeout end |
#retry_safe ⇒ Object
Returns the value of attribute retry_safe.
26 27 28 |
# File 'lib/active_utils/common/connection.rb', line 26 def retry_safe @retry_safe end |
#ssl_version ⇒ Object
Returns the value of attribute ssl_version.
23 24 25 |
# File 'lib/active_utils/common/connection.rb', line 23 def ssl_version @ssl_version end |
#tag ⇒ Object
Returns the value of attribute tag.
31 32 33 |
# File 'lib/active_utils/common/connection.rb', line 31 def tag @tag end |
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
22 23 24 |
# File 'lib/active_utils/common/connection.rb', line 22 def verify_peer @verify_peer end |
#wiredump_device ⇒ Object
Returns the value of attribute wiredump_device.
29 30 31 |
# File 'lib/active_utils/common/connection.rb', line 29 def wiredump_device @wiredump_device end |
Instance Method Details
#request(method, body, headers = {}) ⇒ Object
52 53 54 55 56 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 |
# File 'lib/active_utils/common/connection.rb', line 52 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 :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., 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 |