Class: RSolr::Connection::Adapter::HTTP
- Inherits:
-
Object
- Object
- RSolr::Connection::Adapter::HTTP
- Includes:
- HTTPClient::Util
- Defined in:
- lib/rsolr/connection/adapter/http.rb
Overview
Connection for standard HTTP Solr server
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(opts = {}, &block) ⇒ HTTP
constructor
opts can have: :url => ‘localhost:8080/solr’.
-
#request(path, params = {}, *extra) ⇒ Object
send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’.
Methods included from HTTPClient::Util
#build_param, #build_url, #escape, #hash_to_query
Constructor Details
#initialize(opts = {}, &block) ⇒ HTTP
opts can have:
:url => 'http://localhost:8080/solr'
12 13 14 15 |
# File 'lib/rsolr/connection/adapter/http.rb', line 12 def initialize(opts={}, &block) opts[:url] ||= 'http://127.0.0.1:8983/solr' @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/rsolr/connection/adapter/http.rb', line 8 def opts @opts end |
Instance Method Details
#connection ⇒ Object
17 18 19 |
# File 'lib/rsolr/connection/adapter/http.rb', line 17 def connection @connection ||= RSolr::HTTPClient.connect(@opts) end |
#request(path, params = {}, *extra) ⇒ Object
send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rsolr/connection/adapter/http.rb', line 23 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 = connection.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 = connection.post(path, data, params, {"Content-Type" => 'text/xml; charset=utf-8'}) else # standard GET http_context = connection.get(path, params) end end raise RSolr::RequestError.new(http_context[:body]) unless http_context[:status_code] == 200 http_context end |