124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/cloud-queues/client.rb', line 124
def request_all(collection_key, options = {})
begin
absolute_limit = options[:query][:limit]
limit = [absolute_limit, 10].min
options[:query][:limit] = limit if options[:query][:limit]
rescue
absolute_limit = Float::INFINITY
limit = 10
end
first_response = response = request(options)
if collection_key and first_response.status != 204
options.delete :query
collection = first_response.body[collection_key]
last_links = first_response.body["links"]
while response.body[collection_key].count >= limit and collection.count < absolute_limit
next_link = response.body["links"].select{|l| l["rel"] == "next" }[0]["href"]
options[:path] = set_query_from(options[:path], next_link)
response = request(options)
break if response.status == 204
collection += response.body[collection_key]
last_links = response.body["links"]
end
first_response.body[collection_key] = collection
first_response.body["links"] = last_links
end
return first_response
end
|