Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/auth0/internal/iterators/cursor_page_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ def next?

# Retrieves the next page from the API.
#
# @return [Boolean]
# @return [Object, nil]
def next_page
return if !@need_initial_load && @cursor.nil?

@need_initial_load = false
fetched_page = @get_next_page.call(@cursor)
result = @get_next_page.call(@cursor)
# The block returns either the parsed page directly, or a
# [parsed_page, raw_http_response] tuple. Unwrap accordingly.
fetched_page = if result.is_a?(Array)
result[0]
else
result
end
@cursor = fetched_page.send(@cursor_field)
fetched_page
end
Expand Down
18 changes: 16 additions & 2 deletions lib/auth0/internal/iterators/offset_page_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def next?
return @has_next_page unless @has_next_page.nil?
return true if @next_page

fetched_page = @get_next_page.call(@page_number)
fetched_page = fetch_page(@page_number)
fetched_page_items = fetched_page&.send(@item_field)
if fetched_page_items.nil? || fetched_page_items.empty?
@has_next_page = false
Expand All @@ -61,7 +61,7 @@ def next_page
this_page = @next_page
@next_page = nil
else
this_page = @get_next_page.call(@page_number)
this_page = fetch_page(@page_number)
end

@has_next_page = this_page&.send(@has_next_field) if @has_next_field
Expand All @@ -78,6 +78,20 @@ def next_page

this_page
end

private

# The block returns either the parsed page directly, or a
# [parsed_page, raw_http_response] tuple. Unwrap accordingly.
def fetch_page(page_number)
result = @get_next_page.call(page_number)
if result.is_a?(Array)
fetched_page, _raw_response = result
fetched_page
else
result
end
end
end
end
end