Class: Crm::Core::ConnectionManager
- Inherits:
-
Object
- Object
- Crm::Core::ConnectionManager
- Defined in:
- lib/crm/core/connection_manager.rb
Constant Summary collapse
- SOCKET_ERRORS =
[ EOFError, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EINVAL, Errno::EPIPE, Errno::ETIMEDOUT, IOError, SocketError, Timeout::Error, ].freeze
- DEFAULT_TIMEOUT =
10.freeze
Instance Attribute Summary collapse
- #ca_file ⇒ Object readonly
- #cert_store ⇒ Object readonly
- #uri ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(uri) ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
- #request(request, timeout = DEFAULT_TIMEOUT) ⇒ Object
Constructor Details
#initialize(uri) ⇒ ConnectionManager
Returns a new instance of ConnectionManager.
22 23 24 25 26 27 28 29 30 |
# File 'lib/crm/core/connection_manager.rb', line 22 def initialize(uri) @uri = uri @ca_file = File.('../../../../config/ca-bundle.crt', __FILE__) @cert_store = OpenSSL::X509::Store.new.tap do |store| store.set_default_paths store.add_file(@ca_file) end @connection = nil end |
Instance Attribute Details
#ca_file ⇒ Object (readonly)
19 20 21 |
# File 'lib/crm/core/connection_manager.rb', line 19 def ca_file @ca_file end |
#cert_store ⇒ Object (readonly)
20 21 22 |
# File 'lib/crm/core/connection_manager.rb', line 20 def cert_store @cert_store end |
#uri ⇒ Object (readonly)
18 19 20 |
# File 'lib/crm/core/connection_manager.rb', line 18 def uri @uri end |
Instance Method Details
#request(request, timeout = DEFAULT_TIMEOUT) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/crm/core/connection_manager.rb', line 32 def request(request, timeout=DEFAULT_TIMEOUT) request['User-Agent'] = user_agent ensure_started(timeout) begin @connection.request(request) rescue *SOCKET_ERRORS => e ensure_finished raise Errors::NetworkError.new(e., e) end end |