Class: RSolr::Connection::NetHttp
- Inherits:
-
Object
- Object
- RSolr::Connection::NetHttp
- Includes:
- Utils
- Defined in:
- lib/rsolr/connection/net_http.rb
Overview
Connection for standard HTTP Solr server
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 = {}) ⇒ NetHttp
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 Utils
#build_param, #bytesize, #escape, #hash_to_query
Constructor Details
#initialize(opts = {}) ⇒ NetHttp
opts can have:
:url => 'http://localhost:8080/solr'
14 15 16 17 18 |
# File 'lib/rsolr/connection/net_http.rb', line 14 def initialize opts={} opts[:url] ||= 'http://127.0.0.1:8983/solr' @opts = opts @uri = URI.parse opts[:url] end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
10 11 12 |
# File 'lib/rsolr/connection/net_http.rb', line 10 def opts @opts end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/rsolr/connection/net_http.rb', line 10 def uri @uri end |
Instance Method Details
#request(path, params = {}, *extra) ⇒ Object
send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rsolr/connection/net_http.rb', line 22 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(http_context[:body]) unless http_context[:status_code] == 200 http_context end |