Module: RSolr::Connection::Requestable

Includes:
Utils
Included in:
NetHttp
Defined in:
lib/rsolr/connection/requestable.rb

Overview

A module that defines the interface and top-level logic for http based connection classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#build_param, #build_url, #bytesize, #create_base_string, #create_signature, #encode_utf8, #escape, #hash_to_query, #normalize_params

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/rsolr/connection/requestable.rb', line 6

def opts
  @opts
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/rsolr/connection/requestable.rb', line 6

def uri
  @uri
end

Instance Method Details

#initialize(opts = {}) ⇒ Object

opts can have:

:url => 'http://localhost:8080/solr'


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

def initialize opts={}
  opts[:url] ||= 'http://127.0.0.1:8983/solr'
  @opts = opts
  @uri = URI.parse opts[:url]
end

#request(path, params = {}, *extra) ⇒ Object

send a request to the connection request ‘/select’, :q=>‘:

request ‘/update’, :wt=>:xml, ‘</commit>’

force a post where the post body is the param query request ‘/update’, “<optimize/>”, :method=>:post



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

def request path, params={}, *extra
  opts = extra[-1].kind_of?(Hash) ? extra.pop : {}
  data = extra[0]
  # force a POST, use the query string as the POST body
  if opts[:method] == :post and data.to_s.empty?
    http_context = self.post(path, hash_to_query(params), {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
  else
    if data
      # standard POST, using "data" as the POST body
      http_context = self.post(path, data, params, {"Content-Type" => 'text/xml; charset=utf-8'})
    else
      # standard GET
      http_context = self.get(path, params)
    end
  end
  raise RSolr::RequestError.new("Solr Response: #{http_context[:message]}") unless http_context[:status_code] == 200
  http_context
end