Class: RubyPsigate::Connection
- Inherits:
-
Object
- Object
- RubyPsigate::Connection
- Defined in:
- lib/ruby_psigate/connection.rb
Constant Summary collapse
- MAX_RETRIES =
3
- RETRY_SAFE =
true
- READ_TIMEOUT =
> Values in seconds
60
- OPEN_TIMEOUT =
30
- VERIFY_PEER =
true
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#retry_safe ⇒ Object
Returns the value of attribute retry_safe.
-
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
Instance Method Summary collapse
-
#initialize(endpoint) ⇒ Connection
constructor
A new instance of Connection.
- #post(params) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 18 19 |
# File 'lib/ruby_psigate/connection.rb', line 13 def initialize(endpoint) @endpoint = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint) @retry_safe = RETRY_SAFE @read_timeout = READ_TIMEOUT @open_timeout = OPEN_TIMEOUT @verify_peer = VERIFY_PEER end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
21 22 23 |
# File 'lib/ruby_psigate/connection.rb', line 21 def endpoint @endpoint end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
24 25 26 |
# File 'lib/ruby_psigate/connection.rb', line 24 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
23 24 25 |
# File 'lib/ruby_psigate/connection.rb', line 23 def read_timeout @read_timeout end |
#retry_safe ⇒ Object
Returns the value of attribute retry_safe.
22 23 24 |
# File 'lib/ruby_psigate/connection.rb', line 22 def retry_safe @retry_safe end |
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
25 26 27 |
# File 'lib/ruby_psigate/connection.rb', line 25 def verify_peer @verify_peer end |
Instance Method Details
#post(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_psigate/connection.rb', line 27 def post(params) retry_exceptions do begin uri = @endpoint psigate = Net::HTTP.new(uri.host, uri.port) # Configure Timeouts psigate.open_timeout = open_timeout psigate.read_timeout = read_timeout # Configure SSL psigate.use_ssl = true if verify_peer psigate.verify_mode = OpenSSL::SSL::VERIFY_PEER psigate.ca_file = ca_file else psigate.verify_mode = OpenSSL::SSL::VERIFY_NONE end raw_response = psigate.post(uri.path, params) response = handle_response(raw_response) response rescue EOFError => e raise ConnectionError, "The remote server dropped the connection" rescue Errno::ECONNRESET => e raise ConnectionError, "The remote server reset the connection" rescue Errno::ECONNREFUSED => e raise RetriableConnectionError, "The remote server refused the connection" rescue Timeout::Error, Errno::ETIMEDOUT => e raise ConnectionError, "The connection to the remote server timed out" end # begin end # retry_exceptions end |