module RequestVia::NetHTTP

Constants

Build
IsNetHTTP

Public Instance Methods

call(uri, port = nil, open_timeout = nil, read_timeout = nil, net_http = nil) click to toggle source
# File lib/request_via/net_http.rb, line 15
def call(uri, port = nil, open_timeout = nil, read_timeout = nil, net_http = nil)
  return net_http if IsNetHTTP.(net_http)

  net_http = build!(uri, port, net_http)

  net_http.open_timeout = Integer(open_timeout) unless open_timeout.nil?
  net_http.read_timeout = Integer(read_timeout) unless read_timeout.nil?

  return net_http unless uri.instance_of?(URI::HTTPS)

  set_https!(net_http)
end

Private Instance Methods

build!(uri, port, net_http) click to toggle source
# File lib/request_via/net_http.rb, line 30
def build!(uri, port, net_http)
  strategy = net_http.is_a?(Proc) ? net_http : Build

  http = strategy.(uri.host, (port || uri.port))

  return http if IsNetHTTP.(http)

  fail TypeError, 'net_http proc must return a Net:HTTP instance'
end
set_https!(net_http) click to toggle source
# File lib/request_via/net_http.rb, line 40
def set_https!(net_http)
  net_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  net_http.use_ssl = true
  net_http
end