Sha256: 5cff03d708c165311d2d58bec30fa23676b23854d2fbd20378235dc49545fa75
Contents?: true
Size: 1020 Bytes
Versions: 2
Compression:
Stored size: 1020 Bytes
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: ) @n = 0 @client = client @list_property = list_property @page = page 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(url: @page.next_page_uri) self.n = 0 self.page = res get_next end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ngrok-api-0.12.0 | lib/ngrokapi/paged_iterator.rb |
ngrok-api-0.9.0 | lib/ngrokapi/paged_iterator.rb |