Sha256: 37f02e0f59413171462aa6a89f032243214d051aee01562c9a48750573b34e5a
Contents?: true
Size: 1.06 KB
Versions: 5
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module NgrokAPI ## # Low level class which allows the user to iterate through the results of a list API call class PagedIterator attr_accessor :page, :n attr_reader :client, :list_property def initialize( client:, page:, list_property:, danger: false ) @n = 0 @client = client @list_property = list_property @page = page @danger = danger end ## # Iterate through the result set, returning the next instance if we already have one, or make # a new API call to next_page_uri to get more results and return the next one from that call. # # @return [object] Returns an instance of a class. def get_next item = @page.result[@list_property][@n] raise "None" if item.nil? self.n += 1 item rescue if @page.next_page_uri res = @client.list(danger: @danger, url: @page.next_page_uri) self.n = 0 self.page = res get_next end end end end
Version data entries
5 entries across 5 versions & 1 rubygems