class Esearch::Command
Abstract base class for elasticsearch commands
Constants
- EXPECTED_STATI
- JSON_CONTENT_TYPE
Public Class Methods
run(*args)
click to toggle source
Run command
@return [Object]
@api private
# File lib/esearch/command.rb, line 17 def self.run(*args) new(*args).result end
Public Instance Methods
result()
click to toggle source
Return result of request
@return [Presenter]
@api private
# File lib/esearch/command.rb, line 27 def result assert_success presenter.new(parsed_json) end
Private Instance Methods
assert_success()
click to toggle source
Test for success
@return [undefined]
@api private
# File lib/esearch/command.rb, line 104 def assert_success unless expected_response_stati.include?(response.status) raise_status_error end end
connection()
click to toggle source
Return connection
@return [Faraday::Connection]
@api private
# File lib/esearch/command.rb, line 64 def connection context.connection end
content_type()
click to toggle source
Return response content type
@return [String]
@api private
# File lib/esearch/command.rb, line 84 def content_type response.headers['content-type'] end
context_path()
click to toggle source
Return context path
@return [Pathname]
@api private
# File lib/esearch/command.rb, line 74 def context_path context.path end
expected_response_stati()
click to toggle source
Return expected response stati
@return [Enumerable<Fixnum>]
@api private
# File lib/esearch/command.rb, line 94 def expected_response_stati self.class::EXPECTED_STATI end
json_content_type?()
click to toggle source
Test for json content type
@return [true]
if content type is json
@return [false]
otherwise
@api private
# File lib/esearch/command.rb, line 44 def json_content_type? content_type.eql?(JSON_CONTENT_TYPE) end
parsed_json()
click to toggle source
Return parsed json
@return [Hash]
@api private
# File lib/esearch/command.rb, line 146 def parsed_json unless json_content_type? fail ProtocolError, "Expected json content type, but got: #{content_type.inspect}" end MultiJson.load(response.body) end
presenter()
click to toggle source
Return presenter
@return [Class:Presenter]
@api private
# File lib/esearch/command.rb, line 54 def presenter self.class::PRESENTER end
raise_status_error()
click to toggle source
Raise remote status error
@return [undefined]
@api private
# File lib/esearch/command.rb, line 116 def raise_status_error message = format( 'expected response stati: %s but got: %s, remote message: %s', expected_response_stati, response.status, remote_message.inspect ) fail ProtocolError, message end
remote_message()
click to toggle source
Return remote message
@return [String]
@api private
# File lib/esearch/command.rb, line 132 def remote_message if json_content_type? parsed_json else response.body end end
response()
click to toggle source
Return response
@return [Faraday::Response]
@api private
# File lib/esearch/command.rb, line 160 def response connection.run(request) end