Class: Net::Hippie::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/net/hippie/connection.rb

Overview

A connection to a specific host

Instance Method Summary collapse

Constructor Details

#initialize(scheme, host, port, options = {}) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
12
13
14
15
16
# File 'lib/net/hippie/connection.rb', line 7

def initialize(scheme, host, port, options = {})
  http = Net::HTTP.new(host, port)
  http.read_timeout = options.fetch(:read_timeout, 10)
  http.open_timeout = options.fetch(:open_timeout, 10)
  http.use_ssl = scheme == 'https'
  http.verify_mode = options.fetch(:verify_mode, Net::Hippie.verify_mode)
  http.set_debug_output(options.fetch(:logger, Net::Hippie.logger))
  apply_client_tls_to(http, options)
  @http = http
end

Instance Method Details

#build_url_for(path) ⇒ Object



22
23
24
25
26
# File 'lib/net/hippie/connection.rb', line 22

def build_url_for(path)
  return path if path.start_with?('http')

  "#{@http.use_ssl? ? 'https' : 'http'}://#{@http.address}#{path}"
end

#run(request) ⇒ Object



18
19
20
# File 'lib/net/hippie/connection.rb', line 18

def run(request)
  @http.request(request)
end