Class: Solr::Connection
- Inherits:
-
Object
- Object
- Solr::Connection
- Defined in:
- lib/solr/connection.rb
Overview
low-level connection that can do network requests to Solr
Constant Summary collapse
- INSTRUMENT_KEY =
'request.solrb'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #get(_) ⇒ Object
-
#initialize(url, faraday_options: Solr.configuration.faraday_options, faraday_configuration: Solr.configuration.faraday_configuration) ⇒ Connection
constructor
A new instance of Connection.
- #post(data) ⇒ Object
Constructor Details
#initialize(url, faraday_options: Solr.configuration.faraday_options, faraday_configuration: Solr.configuration.faraday_configuration) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 |
# File 'lib/solr/connection.rb', line 6 def initialize(url, faraday_options: Solr.configuration., faraday_configuration: Solr.configuration.faraday_configuration) # Allow mock the connection for testing @raw_connection = Solr.configuration.test_connection @raw_connection ||= build_faraday_connection(url, , faraday_configuration) freeze end |
Class Method Details
.call(url:, method:, body:) ⇒ Object
14 15 16 17 |
# File 'lib/solr/connection.rb', line 14 def self.call(url:, method:, body:) raise "HTTP method not supported: #{method}" unless [:get, :post].include?(method.to_sym) new(url).public_send(method, body) end |
Instance Method Details
#get(_) ⇒ Object
19 20 21 |
# File 'lib/solr/connection.rb', line 19 def get(_) Solr.instrument(name: INSTRUMENT_KEY) { @raw_connection.get } end |
#post(data) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/solr/connection.rb', line 23 def post(data) Solr.instrument(name: INSTRUMENT_KEY, data: data) do @raw_connection.post do |req| req.headers['Content-Type'] = 'application/json'.freeze req.body = JSON.generate(data) end end end |