Class: Elastictastic::NetHttpAdapter
- Defined in:
- lib/elastictastic/adapter.rb
Instance Method Summary collapse
-
#initialize(host, options = {}) ⇒ NetHttpAdapter
constructor
A new instance of NetHttpAdapter.
- #request(method, path, body = nil) ⇒ Object
Methods inherited from Adapter
Methods included from TransportMethods
#delete, #get, #head, #post, #put
Constructor Details
#initialize(host, options = {}) ⇒ NetHttpAdapter
Returns a new instance of NetHttpAdapter.
29 30 31 32 33 34 |
# File 'lib/elastictastic/adapter.rb', line 29 def initialize(host, = {}) super uri = URI.parse(host) @connection = Net::HTTP.new(uri.host, uri.port) @connection.read_timeout = @request_timeout end |
Instance Method Details
#request(method, path, body = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 |