Class: Elasticsearch::Client::Base
- Inherits:
-
Object
- Object
- Elasticsearch::Client::Base
- Defined in:
- lib/elasticsearch/client/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #_get(uri, params = nil) ⇒ Object
- #_prep_opts(params) ⇒ Object
- #_put(uri, body, params = nil) ⇒ Object
- #get(uri, params = nil) ⇒ Object
-
#initialize(host = 'localhost', port = 9200, logger = Logger.new(STDOUT)) ⇒ Base
constructor
A new instance of Base.
- #put(uri, body, params = nil) ⇒ Object
Constructor Details
#initialize(host = 'localhost', port = 9200, logger = Logger.new(STDOUT)) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 |
# File 'lib/elasticsearch/client/base.rb', line 8 def initialize(host = 'localhost', port = 9200, logger = Logger.new(STDOUT)) @host = host @port = port @logger = logger end |
Instance Method Details
#_get(uri, params = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/elasticsearch/client/base.rb', line 32 def _get(uri, params = nil) url = _build_url(uri) opts = _prep_opts(params) begin return RestClient.get url, opts rescue Exception => e raise Elasticsearch::Manager::ApiError.new "Unable to complete get request: #{e}" end end |
#_prep_opts(params) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/elasticsearch/client/base.rb', line 54 def _prep_opts(params) unless params.nil? {:params => params} else {} end end |
#_put(uri, body, params = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/elasticsearch/client/base.rb', line 43 def _put(uri, body, params = nil) url = _build_url(uri) opts = _prep_opts(params) begin return RestClient.put url, body, opts rescue Exception => e raise Elasticsearch::Manager::ApiError.new "Unable to complete put request: #{e}" end end |
#get(uri, params = nil) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/elasticsearch/client/base.rb', line 14 def get(uri, params = nil) raw = _get(uri, params) if !raw.headers[:content_type].nil? && raw.headers[:content_type][/json/] JSON.parse(raw) else raw end end |
#put(uri, body, params = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/elasticsearch/client/base.rb', line 23 def put(uri, body, params = nil) raw = _put(uri, body, params) if !raw.headers[:content_type].nil? && raw.headers[:content_type][/json/] JSON.parse(raw) else raw end end |