class Solr4R::Request
Constants
- DEFAULT_METHOD
- DEFAULT_USER_AGENT
Attributes
base_uri[RW]
client[R]
http[RW]
http_options[RW]
last_response[RW]
Public Class Methods
new(client, base_uri, http_options = {})
click to toggle source
# File lib/solr4r/request.rb, line 39 def initialize(client, base_uri, http_options = {}) @client, self.base_uri, self.http_options = client, URI(base_uri).extend(BaseUriExtension), http_options end
Public Instance Methods
execute(path, options = {}, &block)
click to toggle source
# File lib/solr4r/request.rb, line 64 def execute(path, options = {}, &block) start unless started? self.last_response = nil req = prepare_request(path, options, &block) res = http.request(req) self.last_response = Response.new(self, req, res) end
finish()
click to toggle source
# File lib/solr4r/request.rb, line 55 def finish http.finish if started? self end
inspect()
click to toggle source
# File lib/solr4r/request.rb, line 79 def inspect '#<%s:0x%x %s>' % [self.class, object_id, request_line] end
request_line()
click to toggle source
# File lib/solr4r/request.rb, line 75 def request_line last_response ? last_response.request_line : "[#{base_uri}]" end
start()
click to toggle source
# File lib/solr4r/request.rb, line 48 def start self.http = Net::HTTP.start(base_uri.hostname, base_uri.port, { use_ssl: base_uri.scheme == 'https' }.merge(http_options)) self end
started?()
click to toggle source
# File lib/solr4r/request.rb, line 60 def started? http && http.started? end
Private Instance Methods
make_request(uri, method)
click to toggle source
# File lib/solr4r/request.rb, line 101 def make_request(uri, method) req = Net::HTTP.const_get(method.to_s.capitalize).new(uri) req.uri.extend(RequestUriExtension).params = uri.params req end
make_uri(path, params)
click to toggle source
# File lib/solr4r/request.rb, line 97 def make_uri(path, params) base_uri.merge(path).extend(RequestUriExtension).with_params(params) end
prepare_request(path, options) { |req| ... }
click to toggle source
# File lib/solr4r/request.rb, line 85 def prepare_request(path, options) uri = make_uri(path, options.fetch(:params, {})) req = make_request(uri, options.fetch(:method, DEFAULT_METHOD)) set_data(req, options.fetch(:data, {})) if req.request_body_permitted? set_headers(req, options.fetch(:headers, {})) yield req if block_given? req end
set_data(req, data)
click to toggle source
# File lib/solr4r/request.rb, line 114 def set_data(req, data) data.is_a?(String) ? req.body = data : req.form_data = data end
set_headers(req, headers)
click to toggle source
# File lib/solr4r/request.rb, line 107 def set_headers(req, headers) req['User-Agent'] = DEFAULT_USER_AGENT headers.each { |key, value| Array(value).each { |val| req.add_field(key, val) } } end