Class: MoonropeClient::Responses::PaginatedCollection
- Inherits:
-
Success
- Object
- MoonropeClient::Response
- Success
- MoonropeClient::Responses::PaginatedCollection
- Defined in:
- lib/moonrope_client/responses/paginated_collection.rb
Instance Method Summary collapse
-
#next_page ⇒ MoonropeClient::Responses::PaginatedCollection
The collection for the next page.
-
#page ⇒ Integer
The current page.
-
#pagination_properties ⇒ Hash
All properties regarding pagination.
-
#per_page ⇒ Integer
The total records per page.
-
#previous_page ⇒ MoonropeClient::Responses::PaginatedCollection
The collection for the previous page.
-
#records ⇒ Array
All the items.
-
#total_pages ⇒ Integer
The total number of pages.
-
#total_records ⇒ Integer
The total number of records.
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_page ⇒ MoonropeClient::Responses::PaginatedCollection
Returns the collection for the next page.
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 |
#page ⇒ Integer
Returns the current page.
15 16 17 |
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 15 def page pagination_properties['page'] end |
#pagination_properties ⇒ Hash
Returns all properties regarding pagination.
8 9 10 |
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 8 def pagination_properties flags['paginated'] end |
#per_page ⇒ Integer
Returns 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_page ⇒ MoonropeClient::Responses::PaginatedCollection
Returns the collection for the previous page.
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 |
#records ⇒ Array
Returns all the items.
43 44 45 |
# File 'lib/moonrope_client/responses/paginated_collection.rb', line 43 def records data end |
#total_pages ⇒ Integer
Returns 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_records ⇒ Integer
Returns 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 |