Class: MoonropeClient::Responses::PaginatedCollection

Inherits:
Success show all
Defined in:
lib/moonrope_client/responses/paginated_collection.rb

Instance Method Summary collapse

Methods inherited from Success

#creation?, #deletion?, #modification?, #success?

Methods inherited from MoonropeClient::Response

#data, #exception_message, #flags, #initialize, #status, #success?, #time

Constructor Details

This class inherits a constructor from MoonropeClient::Response

Instance Method Details

#next_pageMoonropeClient::Responses::PaginatedCollection

Returns the collection for the next page.

Returns:



50
51
52
53
54
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 50

def next_page
  request = @request.dup
  request.params[:page] = page + 1
  request.make
end

#pageInteger

Returns the current page.

Returns:

  • (Integer)

    the current page



15
16
17
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 15

def page
  pagination_properties['page']
end

#pagination_propertiesHash

Returns all properties regarding pagination.

Returns:

  • (Hash)

    all properties regarding pagination



8
9
10
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 8

def pagination_properties
  flags['paginated']
end

#per_pageInteger

Returns the total records per page.

Returns:

  • (Integer)

    the total records per page



22
23
24
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 22

def per_page
  pagination_properties['per_page']
end

#previous_pageMoonropeClient::Responses::PaginatedCollection

Returns the collection for the previous page.

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 59

def previous_page
  if page > 1
    request = @request.dup
    request.params[:page] = page - 1
    request.make
  else
    raise Error, "Cannot return the previous page as there is no page before page #{page}"
  end
end

#recordsArray

Returns all the items.

Returns:

  • (Array)

    all the items



43
44
45
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 43

def records
  data
end

#total_pagesInteger

Returns the total number of pages.

Returns:

  • (Integer)

    the total number of pages



29
30
31
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 29

def total_pages
  pagination_properties['total_pages']
end

#total_recordsInteger

Returns the total number of records.

Returns:

  • (Integer)

    the total number of records



36
37
38
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 36

def total_records
  pagination_properties['total_records']
end