Class: ES::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/es/connection.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

OK_HTTP_CODES =
[200, 201]

Instance Method Summary collapse

Constructor Details

#initialize(host, driver) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
# File 'lib/es/connection.rb', line 5

def initialize(host, driver)
  @host = host
  @driver = driver
end

Instance Method Details

#request(method, path, data = nil) ⇒ Object

Raises:



10
11
12
13
14
# File 'lib/es/connection.rb', line 10

def request(method, path, data = nil)
  response = translate_request(method, "#{@host}/#{path}", data)
  raise Error.new(response) unless OK_HTTP_CODES.include?(response.response_code)
  response.body_str
end