Class: Crm::Core::ConnectionManager

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.expand_path('../../../../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_fileObject (readonly)



19
20
21
# File 'lib/crm/core/connection_manager.rb', line 19

def ca_file
  @ca_file
end

#cert_storeObject (readonly)



20
21
22
# File 'lib/crm/core/connection_manager.rb', line 20

def cert_store
  @cert_store
end

#uriObject (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.message, e)
  end
end