Class: PersistentConnectionAdapter

Inherits:
HTTParty::ConnectionAdapter
  • Object
show all
Defined in:
lib/resthome/httparty/persistent_connection_adapter.rb

Defined Under Namespace

Classes: PersistentHTTP

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(uri, options) ⇒ Object



55
56
57
# File 'lib/resthome/httparty/persistent_connection_adapter.rb', line 55

def self.call(uri, options)
  self.start uri, options
end

.closeObject



44
45
46
47
48
49
# File 'lib/resthome/httparty/persistent_connection_adapter.rb', line 44

def self.close
  if @conn
    @conn.finish if @conn.started?
    @conn = nil
  end
end

.connObject



51
52
53
# File 'lib/resthome/httparty/persistent_connection_adapter.rb', line 51

def self.conn
  @conn
end

.start(uri, options) ⇒ Object



40
41
42
# File 'lib/resthome/httparty/persistent_connection_adapter.rb', line 40

def self.start(uri, options)
  @conn ||= new(uri, options).connection.tap { |c| c.start }
end

Instance Method Details

#connectionObject

copied from HTTParty::ConnectionAdapter



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/resthome/httparty/persistent_connection_adapter.rb', line 19

def connection
  PersistentHTTP.new(clean_host(uri.host), uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass]).tap do |http|
    http.use_ssl = ssl_implied?(uri)

    attach_ssl_certificates(http, options)

    if options[:timeout] && (options[:timeout].is_a?(Integer) || options[:timeout].is_a?(Float))
      http.open_timeout = options[:timeout]
      http.read_timeout = options[:timeout]
    end

    if options[:debug_output]
      http.set_debug_output(options[:debug_output])
    end

    if options[:ciphers]
      http.ciphers = options[:ciphers]
    end
  end
end