class Elasticsearch::Client::Base

Public Class Methods

new(host = 'localhost', port = 9200, logger = Logger.new(STDOUT)) click to toggle source
# 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

Public Instance Methods

_get(uri, params = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Protected Instance Methods

_build_url(uri) click to toggle source
# File lib/elasticsearch/client/base.rb, line 64
def _build_url(uri)
  "http://#{@host}:#{@port}#{uri}"
end