Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return last page of pagination #6

Open
adarsh opened this issue Oct 15, 2015 · 3 comments
Open

Return last page of pagination #6

adarsh opened this issue Oct 15, 2015 · 3 comments

Comments

@adarsh
Copy link

adarsh commented Oct 15, 2015

Hi! I'm pulling down several pages of data, and currently having to do this:

    (1..Float::INFINITY).each do |page|
      retrieved_page = candidates(page)

      if retrieved_page.present?
        retrieved_page.each do |candidate|
          # ... do stuff
        end
      else
        break
      end
    end

It would be great to know the last page number, given some per_page value. Maybe client.candidates.last_page(per_page: 500) or whatnot.

@adarsh
Copy link
Author

adarsh commented Oct 15, 2015

By the way, this client gem is awesome - thank you for putting it together!

@capablemonkey
Copy link
Contributor

Hey @adarsh,

Thanks for pointing this out! @adrianbautista kindly transferred this repo over to Greenhouse, so we'll be maintaining this gem from now on. I'm taking a look at the active issues and pull requests now and In the coming weeks I'm planning to add better support for pagination and some new Harvest API endpoints which will likely require a major version bump.

To make pagination better, we can definitely use the Link response header which tells us what the URI of the next and last pages are.

Link: <https://harvest.greenhouse.io/v1/candidates?page=2&per_page=2>; rel="next",<https://harvest.greenhouse.io/v1/candidates?page=22&per_page=2>; rel="last"

I'll follow up soon with a solution!

@mariochavez
Copy link
Contributor

Hi,

My PR #17 expose link header to the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants