Class: RSolr::ClientCert::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rsolr/client_cert/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
# File 'lib/rsolr/client_cert/connection.rb', line 10

def initialize opts = {}
  @ssl_client_cert = extract_client_cert(opts)
  @ssl_client_key = extract_client_key(opts)
end

Instance Attribute Details

#ssl_client_certObject (readonly)

Returns the value of attribute ssl_client_cert.



8
9
10
# File 'lib/rsolr/client_cert/connection.rb', line 8

def ssl_client_cert
  @ssl_client_cert
end

#ssl_client_keyObject (readonly)

Returns the value of attribute ssl_client_key.



8
9
10
# File 'lib/rsolr/client_cert/connection.rb', line 8

def ssl_client_key
  @ssl_client_key
end

Instance Method Details

#execute(client, request_context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rsolr/client_cert/connection.rb', line 15

def execute client, request_context
  old_proxy = RestClient.proxy
  begin
    RestClient.proxy = request_context[:proxy]
    resource = RestClient::Resource.new(
      request_context[:uri].to_s,
      :open_timeout     =>  request_context[:open_timeout],
      :timeout          =>  request_context[:read_timeout],
      :ssl_client_cert  =>  ssl_client_cert,
      :ssl_client_key   =>  ssl_client_key
    )
    result = {}
    signature = [request_context[:method], request_context[:data], request_context[:headers]].compact
    resource.send(*signature) { |response, request, http_result, &block|
      result = {
        :status => response.net_http_res.code.to_i,
        :headers => response.net_http_res.to_hash,
        :body => response.net_http_res.body
      }
    }
    result
  ensure
    RestClient.proxy = old_proxy
  end
end