module DeskApi::Resource::Pagination
{DeskApi::Resource::Pagination} is responsible for pagination helper methods like `#each_page` or `#all`
@author Thomas Stachl <tstachl@salesforce.com> @copyright Copyright © 2013-2016 Salesforce.com @license BSD 3-Clause License
@example search for cases {DeskApi::Resource}
DeskApi.cases.each_page{ |page, num| do_something(page) }
Public Instance Methods
Paginate through all the resources on a give page {DeskApi::Resource}
@raise [NoMethodError] if self is not a page resource @raise [ArgumentError] if no block is given @yield [DeskApi::Resource] the current resource @yield [Integer] the current page number
# File lib/desk_api/resource/pagination.rb, line 48 def all raise ArgumentError, "Block must be given for #all" unless block_given? each_page do |page, page_num| page.entries.each { |resource| yield resource, page_num } end end
Paginate through each page on a give page {DeskApi::Resource}
@raise [NoMethodError] if self is not a page resource @raise [ArgumentError] if no block is given @yield [DeskApi::Resource] the current page resource @yield [Integer] the current page number
# File lib/desk_api/resource/pagination.rb, line 61 def each_page raise ArgumentError, "Block must be given for #each_page" unless block_given? begin page = self.first.per_page(self.query_params['per_page'] || 1000).dup rescue NoMethodError => err raise NoMethodError, "#each_page and #all are only available on resources which offer pagination" end begin yield page, page.page end while page.next! end