grnhse / greenhouse_io

Ruby API wrapper for Greenhouse.io API
MIT License
44 stars 46 forks source link

Return last page of pagination #6

Open adarsh opened 9 years ago

adarsh commented 9 years ago

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 commented 9 years ago

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

capablemonkey commented 8 years ago

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 commented 8 years ago

Hi,

My PR #17 expose link header to the client.