module SparkApi::PaginateHelper

Pagination Helpers

Helpers to create the pagination collection

Public Instance Methods

paginate_response(results, paging_hash) click to toggle source

Enable pagination

  • results – array of hashes representing api resources

  • paging_hash – the pagination response information from the api representing paging state.

:returns:

The result set decorated as a WillPaginate::Collection
# File lib/spark_api/paginate.rb, line 86
def paginate_response(results, paging_hash)
  pager = Pagination.new(paging_hash)
  paged_results = WillPaginate::Collection.create(pager.current_page, pager.page_size, pager.total_rows) do |p|
    p.replace(results)
  end
  paged_results.extend PaginateResponse
  paged_results.results = results
  paged_results
end