Module: TableauRestApi::Pagination
- Included in:
- Client
- Defined in:
- lib/tableau_rest_api/util/pagination.rb
Instance Method Summary collapse
- #complete?(response) ⇒ Boolean
- #first_page? ⇒ Boolean
- #next_page ⇒ Object
- #paginate(pagination) ⇒ Object
- #read_pagination_header(pagination) ⇒ Object
- #retrieve_additional_pages(response, collection, endpoint, extract) ⇒ Object
- #single_page? ⇒ Boolean
Instance Method Details
#complete?(response) ⇒ Boolean
3 4 5 6 |
# File 'lib/tableau_rest_api/util/pagination.rb', line 3 def complete?(response) pagination = response.pagination pagination ? paginate(pagination) : true end |
#first_page? ⇒ Boolean
14 15 16 |
# File 'lib/tableau_rest_api/util/pagination.rb', line 14 def first_page? @page == 0 end |
#next_page ⇒ Object
28 29 30 |
# File 'lib/tableau_rest_api/util/pagination.rb', line 28 def next_page @page + 1 end |
#paginate(pagination) ⇒ Object
8 9 10 11 12 |
# 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) ⇒ Object
22 23 24 25 26 |
# 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) ⇒ Object
32 33 34 35 36 37 38 |
# 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? ⇒ Boolean
18 19 20 |
# File 'lib/tableau_rest_api/util/pagination.rb', line 18 def single_page? @total <= @per_page end |