Class: Net::Hippie::Connection
- Inherits:
-
Object
- Object
- Net::Hippie::Connection
- Defined in:
- lib/net/hippie/connection.rb
Overview
A connection to a specific host
Instance Method Summary collapse
- #build_url_for(path) ⇒ Object
-
#initialize(scheme, host, port, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #run(request, &block) ⇒ Object
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, = {}) http = Net::HTTP.new(host, port) http.read_timeout = .fetch(:read_timeout, 10) http.open_timeout = .fetch(:open_timeout, 10) http.use_ssl = scheme == 'https' http.verify_mode = .fetch(:verify_mode, Net::Hippie.verify_mode) http.set_debug_output([:logger]) if [:logger] apply_client_tls_to(http, ) @http = http end |
Instance Method Details
#build_url_for(path) ⇒ Object
26 27 28 29 30 |
# File 'lib/net/hippie/connection.rb', line 26 def build_url_for(path) return path if path.start_with?('http') "#{@http.use_ssl? ? 'https' : 'http'}://#{@http.address}#{path}" end |
#run(request, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/net/hippie/connection.rb', line 18 def run(request, &block) if block_given? @http.request(request, &block) else @http.request(request) end end |