Allow abnormal page token cases for paging methods

Addresses https://github.com/googleapis/toolkit/issues/692.

Manual changes are in:
lib/google/apis/core/base_service.rb
spec/google/apis/core/service_spec.rb
This commit is contained in:
Thomas Coffee committed 2017-02-03 12:09:18 -08:00
1 parent e9d7e47c75
commit 16f0a768f7
120 files changed
+102767 -101146

No files matched your search

+7 -5
View File
@@ -42,11 +42,12 @@ module Google
# True (default) if results should be cached so multiple iterations can be used.
# @param [Symbol] items
# Name of the field in the result containing the items. Defaults to :items
def initialize(service, max: nil, items: :items, cache: true, &block)
def initialize(service, max: nil, items: :items, cache: true, response_page_token: :next_page_token, &block)
@service = service
@block = block
@max = max
@items_field = items
@response_page_token_field = response_page_token
if cache
@result_cache = Hash.new do |h, k|
h[k] = @block.call(k, @service)
@@ -75,8 +76,9 @@ module Google
yield items
end
break if @max && item_count >= @max
break if @last_result.next_page_token.nil? || @last_result.next_page_token == page_token
page_token = @last_result.next_page_token
next_page_token = @last_result.send(@response_page_token_field)
break if next_page_token.nil? || next_page_token == page_token
page_token = next_page_token
end
end
end
@@ -270,9 +272,9 @@ module Google
# @example Retrieve all files,
# file_list = service.fetch_all { |token, s| s.list_files(page_token: token) }
# file_list.each { |f| ... }
def fetch_all(max: nil, items: :items, cache: true, &block)
def fetch_all(max: nil, items: :items, cache: true, response_page_token: :next_page_token, &block)
fail "fetch_all may not be used inside a batch" if batch?
return PagedResults.new(self, max: max, items: items, cache: cache, &block)
return PagedResults.new(self, max: max, items: items, cache: cache, response_page_token: response_page_token, &block)
end
protected
+1 -1
View File
@@ -15,7 +15,7 @@
module Google
module Apis
# Client library version
VERSION = '0.9.26'
VERSION = '0.9.27'
# Current operating system
# @private