Class: TesoteSdk::Pagination::CursorEnumerator
- Inherits:
-
Object
- Object
- TesoteSdk::Pagination::CursorEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/tesote_sdk/pagination.rb
Overview
Cursor pagination (transactions index): walks ‘pagination.after_id` until has_more is false. Yields the raw page hash so callers can read the response envelope as needed.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(start_query: {}, &fetch_page) ⇒ CursorEnumerator
constructor
A new instance of CursorEnumerator.
Constructor Details
#initialize(start_query: {}, &fetch_page) ⇒ CursorEnumerator
Returns a new instance of CursorEnumerator.
12 13 14 15 16 17 |
# File 'lib/tesote_sdk/pagination.rb', line 12 def initialize(start_query: {}, &fetch_page) raise ArgumentError, 'block (fetch_page) is required' unless block_given? @start_query = start_query.dup @fetch_page = fetch_page end |
Instance Method Details
#each ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tesote_sdk/pagination.rb', line 19 def each return enum_for(:each) unless block_given? query = @start_query.dup loop do page = @fetch_page.call(query) yield page pagination = pagination_hash(page) break unless pagination['has_more'] after_id = pagination['after_id'] break if after_id.nil? || after_id.to_s.empty? query = query.merge(transactions_after_id: after_id) end end |