module TableauRestApi::Pagination
Public Instance Methods
complete?(response)
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 3 def complete?(response) pagination = response.pagination pagination ? paginate(pagination) : true end
first_page?()
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 14 def first_page? @page == 0 end
next_page()
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 28 def next_page @page + 1 end
paginate(pagination)
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 8 def paginate(pagination) read_pagination_header(pagination) return single_page? if first_page? @total % ((@page) * @per_page) == @total end
read_pagination_header(pagination)
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 22 def read_pagination_header(pagination) @page = pagination.pageNumber.to_i @per_page = pagination.pageSize.to_i @total = pagination.totalAvailable.to_i end
retrieve_additional_pages(response, collection, endpoint, extract)
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 32 def retrieve_additional_pages(response, collection, endpoint, extract) until complete?(response) do response = (get build_url(endpoint, next_page)) collection = collection + extract.call(response) end collection end
single_page?()
click to toggle source
# File lib/tableau_rest_api/util/pagination.rb, line 18 def single_page? @total <= @per_page end