0.01
No commit activity in last 3 years
No release in over 3 years
Makes Her aware of APIs that return pagination headers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0.9.0, ~> 0.9.0
>= 2.6.1, ~> 2.6.1
>= 2.3.2, ~> 2.3.2
~> 5.0
>= 0.10.1, ~> 0.10.1
~> 10.0

Runtime

>= 0.7.2, ~> 0.7
>= 0.16.1, ~> 0.16.1
 Project Readme

Her::Kaminari

Gem Version Build Status Code Climate Coverage Status

Makes Her aware of APIs that return pagination headers like grape-kaminari gem.

Her models can now query these APIs like any other kaminari model:

  User.page(1).per(10)

IMPORTANT: Pagination is done by the API not by this gem, this gem just parses the response data and creates a Kaminari compatible collection that you can use in your views.

Gem Dependencies

Installation

Add this line to your application's Gemfile:

gem 'her-kaminari'

And then execute:

$ bundle

Or install it yourself as:

$ gem install her-kaminari

Usage

First include Her::Kaminari::HeaderParser in your Her setup like this:

Her::API.setup url: 'https://api.example.com' do |c|
  #...

  # Response
  c.use Her::Kaminari::HeaderParser

  # ...
end

HeaderParser expects that the API request returns the following headers:

X-Total: Total number of records.
X-Page: Current page number.
X-Per-Page: Number of records per page.
X-Offset: (optional) the starting point for the return data.

Then include Her::Kaminari::Collection in your Her model like this:

class User
  include Her::Model
  include Her::Kaminari::Collection
end

Now you can use your Her model like any other Kaminari model.

History

After reading How to pass pagination headers with Kaminari, Her and Grape? post by Artur Hebda I decided that it was a good idea to create a gem with his code.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/her-kaminari/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request