lib/braintree/resource_collection.rb in braintree-3.1.0 vs lib/braintree/resource_collection.rb in braintree-3.2.0

- old
+ new

@@ -20,12 +20,17 @@ def empty? @ids.empty? end - # Returns the first item in the collection or nil if the collection is empty - def first - @paging_block.call([@ids.first]).first + # Returns the first or the first N items in the collection or nil if the collection is empty + def first(amount = 1) + return nil if @ids.empty? + return @paging_block.call([@ids.first]).first if amount == 1 + + @ids.first(amount).each_slice(@page_size).flat_map do |page_of_ids| + @paging_block.call(page_of_ids) + end end # Only the maximum size of a resource collection can be determined since the data on the server can change while # fetching blocks of results for iteration. For example, customers can be deleted while iterating, so the number # of results iterated over may be less than the maximum_size. In general, this method should be avoided.