class Elastictastic::NetHttpAdapter

Public Class Methods

new(host, options = {}) click to toggle source
Calls superclass method Elastictastic::Adapter::new
# File lib/elastictastic/adapter.rb, line 29
def initialize(host, options = {})
  super
  uri = URI.parse(host)
  @connection = Net::HTTP.new(uri.host, uri.port)
  @connection.read_timeout = @request_timeout
end

Public Instance Methods

request(method, path, body = nil) click to toggle source
# File lib/elastictastic/adapter.rb, line 36
def request(method, path, body = nil)
  response =
    case method
    when :head then @connection.head(path)
    when :get then @connection.get(path)
    when :post then @connection.post(path, body.to_s)
    when :put then @connection.put(path, body.to_s)
    when :delete then @connection.delete(path)
    else raise ArgumentError, "Unsupported method #{method.inspect}"
    end
  Response.new(response.code.to_i, response.to_hash, response.body)
rescue Errno::ECONNREFUSED, Timeout::Error, SocketError => e
  raise ConnectionFailed, e
end