Class: Elastic::API::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic/api/response.rb

Overview

Elastic client API Response object. Receives an Elastic::Transport::Transport::Response in the initializer and behaves like a Hash, except when status or headers are called upon it, in which case it returns the original object’s status and headers. This class is based on Elasticsearch::API::Response in the Elasticsearch client. For future versions, we’ll want this to live in elastic-transport instead.

Constant Summary collapse

RESPONSE_METHODS =
[:status, :body, :headers].freeze

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



30
31
32
# File 'lib/elastic/api/response.rb', line 30

def initialize(response)
  @response = response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/elastic/api/response.rb', line 34

def method_missing(method, *args, &block)
  if RESPONSE_METHODS.include? method
    @response.send method.to_sym
  else
    @response.body.send(method.to_sym, *args, &block)
  end
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/elastic/api/response.rb', line 42

def respond_to_missing?(method_name, include_private = false)
  @response.body.respond_to?(method_name, include_private) ||
    RESPONSE_METHODS.include?(method_name)
end

#to_sObject



47
48
49
# File 'lib/elastic/api/response.rb', line 47

def to_s
  @response.body.to_s
end