lib/insales_api/resource/paginated.rb in insales_api-0.1.3 vs lib/insales_api/resource/paginated.rb in insales_api-0.2.0
- old
+ new
@@ -9,16 +9,18 @@
end
end
def find_in_batches(options = {})
per_page = options[:per_page] || PER_PAGE_DEFAULT
- params = {per_page: per_page}.merge(options[:params] || {})
+ params = { per_page: per_page }.merge(options[:params] || {})
page = 1
loop do
items = all(params: params.merge(page: page))
return unless items.any?
+
yield items
return if items.count < per_page
+
page += 1
end
end
end
end