Class: RSolr::Connection::NetHttp

Inherits:
Object
  • Object
show all
Includes:
Requestable
Defined in:
lib/rsolr/connection/net_http.rb

Overview

Connection for standard HTTP Solr server

Instance Attribute Summary

Attributes included from Requestable

#opts, #uri

Instance Method Summary collapse

Methods included from Requestable

#initialize, #request

Methods included from Utils

#build_param, #bytesize, #encode_utf8, #escape, #hash_to_query

Instance Method Details

#build_url(path, params = {}) ⇒ Object

accepts a path/string and optional hash of query params



43
44
45
46
# File 'lib/rsolr/connection/net_http.rb', line 43

def build_url path, params={}
  full_path = @uri.path + path
  super full_path, params, @uri.query
end

#connectionObject



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

def connection
  @connection ||= Net::HTTP.new(@uri.host, @uri.port)
end

#create_http_context(net_http_response, url, path, params, data = nil, headers = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rsolr/connection/net_http.rb', line 26

def create_http_context net_http_response, url, path, params, data=nil, headers={}
  full_url = "#{@uri.scheme}://#{@uri.host}"
  full_url += @uri.port ? ":#{@uri.port}" : ''
  full_url += url
  {
    :status_code=>net_http_response.code.to_i,
    :url=>full_url,
    :body=> encode_utf8(net_http_response.body),
    :path=>path,
    :params=>params,
    :data=>data,
    :headers=>headers,
    :message => net_http_response.message
  }
end

#get(path, params = {}) ⇒ Object



14
15
16
17
18
# File 'lib/rsolr/connection/net_http.rb', line 14

def get path, params={}
  url = self.build_url path, params
  net_http_response = self.connection.get url
  create_http_context net_http_response, url, path, params
end

#post(path, data, params = {}, headers = {}) ⇒ Object



20
21
22
23
24
# File 'lib/rsolr/connection/net_http.rb', line 20

def post path, data, params={}, headers={}
  url = self.build_url path, params
  net_http_response = self.connection.post url, data, headers
  create_http_context net_http_response, url, path, params, data, headers
end