Module: Castle::Core::GetConnection

Defined in:
lib/castle/core/get_connection.rb

Overview

this module returns a new configured Net::HTTP object

Constant Summary collapse

HTTPS_SCHEME =
'https'

Class Method Summary collapse

Class Method Details

.call(config = nil) ⇒ Net::HTTP

Parameters:

Returns:

  • (Net::HTTP)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/castle/core/get_connection.rb', line 12

def call(config = nil)
  config ||= Castle.config
  http = Net::HTTP.new(config.base_url.host, config.base_url.port)
  http.read_timeout = config.request_timeout / 1000.0

  if config.base_url.scheme == HTTPS_SCHEME
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  end

  http
end