Module: Stripe::APIOperations::List::ClassMethods
- Defined in:
- lib/stripe/api_operations_list.rb
Overview
adds pagination methods to list objects in the Stripe API
Instance Method Summary collapse
- #each(filters = {}, opts = {}, &block) ⇒ Object
- #next(filters = {}, opts = {}) ⇒ Object
- #previous(filters = {}, opts = {}) ⇒ Object
Instance Method Details
#each(filters = {}, opts = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/stripe/api_operations_list.rb', line 4 def each(filters={}, opts={}, &block) return enum_for(__method__) unless block_given? @list_pointer = nil # reset to the start of the list while true page = self.next(filters, opts) page.each(&block) break unless page[:has_more] end @list_pointer = nil # reset to the start of the list end |
#next(filters = {}, opts = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/stripe/api_operations_list.rb', line 17 def next(filters={}, opts={}) results = all(filters.merge!(starting_after: @list_pointer), opts) results.data.length > 0 ? @list_pointer = results.data.last.id : nil results end |
#previous(filters = {}, opts = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/stripe/api_operations_list.rb', line 24 def previous(filters={}, opts={}) results = all(filters.merge!(ending_before: @list_pointer), opts) results.data.length > 0 ? @list_pointer = results.data.first.id : @list_pointer = nil results end |