Class: Algolia::MultipleResponse

Inherits:
BaseResponse show all
Includes:
Enumerable
Defined in:
lib/algolia/responses/multiple_response.rb

Instance Method Summary collapse

Methods included from Helpers

#check_array, #check_object, #chunk, #deserialize_settings, #get_object_id, #get_option, #handle_params, #hash_includes_subset?, included, #json_to_hash, #path_encode, #symbolize_hash, #to_json, #to_query_string

Constructor Details

#initialize(responses = nil) ⇒ MultipleResponse

Returns a new instance of MultipleResponse.

Parameters:

  • responses (nil|Array) (defaults to: nil)

    array of raw responses, when provided



7
8
9
# File 'lib/algolia/responses/multiple_response.rb', line 7

def initialize(responses = nil)
  @raw_responses = responses || []
end

Instance Method Details

#eachObject

Iterates through the responses



39
40
41
42
43
# File 'lib/algolia/responses/multiple_response.rb', line 39

def each
  @raw_responses.each do |response|
    yield response
  end
end

#lastObject

Fetch the last element of the responses



13
14
15
# File 'lib/algolia/responses/multiple_response.rb', line 13

def last
  @raw_responses[@raw_responses.length - 1]
end

#push(response) ⇒ Object

Add a new response to responses



19
20
21
# File 'lib/algolia/responses/multiple_response.rb', line 19

def push(response)
  @raw_responses.push(response)
end

#wait(opts = {}) ⇒ Object

Wait for the task to complete

Parameters:

  • opts (Hash) (defaults to: {})

    contains extra parameters to send with your query



27
28
29
30
31
32
33
34
35
# File 'lib/algolia/responses/multiple_response.rb', line 27

def wait(opts = {})
  @raw_responses.each do |response|
    response.wait(opts)
  end

  @raw_responses = []

  self
end