Class: Elasticshell::Client
- Inherits:
-
Object
- Object
- Elasticshell::Client
- Defined in:
- lib/elasticshell/client.rb
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #request(verb, params = {}, options = {}, body = '') ⇒ Object
- #safely(verb, params = {}, options = {}, body = '') ⇒ Object
- #safely_connect(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/elasticshell/client.rb', line 8 def initialize ={} @options = end |
Instance Method Details
#connected? ⇒ Boolean
18 19 20 |
# File 'lib/elasticshell/client.rb', line 18 def connected? @client end |
#request(verb, params = {}, options = {}, body = '') ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/elasticshell/client.rb', line 26 def request verb, params={}, ={}, body='' raise ClientError.new("Not connected to any Elasticsearch servers.") unless connected? safe = .delete(:safely) safe_return = .delete(:return) # Log by default log_request(verb, params, ) unless .delete(:log) == false begin perform_request(verb, params, , body) rescue ElasticSearch::RequestError, ArgumentError => e if safe safe_return else raise ClientError.new(e.) end end end |
#safely(verb, params = {}, options = {}, body = '') ⇒ Object
22 23 24 |
# File 'lib/elasticshell/client.rb', line 22 def safely verb, params={}, ={}, body='' request(verb, params, .merge(:safely => true), body) end |
#safely_connect(options = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/elasticshell/client.rb', line 12 def safely_connect ={} servers = @options.merge()[:servers] raise ClientError.new("Must provide at least one server to connect to.") if servers.empty? connect(servers.dup, first_attempt=true) end |