Class: Pluggy::Lists::CursorList
- Defined in:
- lib/pluggy/lists/cursor_list.rb
Overview
The next envelope -- GET /v2/transactions only, the single cursor-paginated endpoint in the entire API.
next is a ready-to-use query string including the leading "?" and every
filter, e.g. "?accountId=562b...&after=MjAyMC0x...==", or null when
exhausted. We append it VERBATIM and never parse it back apart:
1. The spec says to. It also says that building the request manually
requires the URL-*decoded* `after` value -- and Ruby cannot decode it
losslessly, because URI.decode_www_form and CGI.parse both turn a "+"
into a space. (In practice Pluggy's date|uuid cursors don't seem to
produce a "+", but there is no reason to stand near that.)
2. The server has already baked every filter into the string, so
appending it makes filter propagation correct by construction -- our
`filters` hash cannot drift from the server's notion of the query.
Instance Attribute Summary
Attributes inherited from BaseList
#filters, #path, #raw, #results
Instance Method Summary collapse
- #more? ⇒ Boolean
-
#next_cursor ⇒ Object
The bare
aftervalue, for logging and debugging only. - #next_page ⇒ Object
-
#next_query ⇒ Object
(also: #next_token)
The resume token.
Methods inherited from BaseList
#auto_paging_each, #auto_paging_to_a, #each, #empty?, #initialize, #inspect, #length
Constructor Details
This class inherits a constructor from Pluggy::Lists::BaseList
Instance Method Details
#more? ⇒ Boolean
28 29 30 31 |
# File 'lib/pluggy/lists/cursor_list.rb', line 28 def more? query = next_query !query.nil? && !query.empty? end |
#next_cursor ⇒ Object
The bare after value, for logging and debugging only. Never used to
build a request -- see the class comment.
46 47 48 49 50 51 52 53 54 |
# File 'lib/pluggy/lists/cursor_list.rb', line 46 def next_cursor return nil unless more? encoded = next_query.delete_prefix("?") .split("&") .find { |pair| pair.start_with?("after=") } &.delete_prefix("after=") encoded && URI.decode_www_form_component(encoded) end |
#next_page ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pluggy/lists/cursor_list.rb', line 33 def next_page return nil unless more? query = next_query unless query.start_with?("?") raise Error, "malformed pagination cursor from Pluggy (expected a leading '?'): #{query.inspect}" end @requestor.list_raw("#{@path}#{query}", klass: @klass, client: @client) end |
#next_query ⇒ Object Also known as: next_token
The resume token. Persist THIS -- the whole "?..." string -- not a parsed cursor. See TransactionService#resume.
25 |
# File 'lib/pluggy/lists/cursor_list.rb', line 25 def next_query = @raw.is_a?(Hash) ? @raw["next"] : nil |