Module: GSolr::Connection::Requestable
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Object
opts can have: :url => ‘localhost:8080/solr’.
-
#request(path, params = {}, *extra) ⇒ Object
send a request to the connection request ‘/select’, :q=>‘:’.
Methods included from Utils
#build_param, #build_url, #bytesize, #encode_utf8, #escape, #hash_to_query
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/gsolr/connection/requestable.rb', line 8 def opts @opts end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/gsolr/connection/requestable.rb', line 8 def uri @uri end |
Instance Method Details
#initialize(opts = {}) ⇒ Object
opts can have:
:url => 'http://localhost:8080/solr'
12 13 14 15 16 17 |
# File 'lib/gsolr/connection/requestable.rb', line 12 def initialize(opts={}) opts[:url] ||= 'http://127.0.0.1:8983/solr' @opts = opts @url = opts[:url] @uri = URI.parse @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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gsolr/connection/requestable.rb', line 27 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 GSolr::RequestError.new("Solr Response: #{http_context[:message]}") unless http_context[:status_code] == 200 return http_context end |