Skip to content
Browse files

Merge branch 'pagination' of https://github.com/jdsn/github-v3-api in…

…to jdsn-pagination

* 'pagination' of https://github.com/jdsn/github-v3-api:
  support github api pagination
  • Loading branch information...
2 parents 527b78f + 0912765 commit 011ac895f24a59ba91a82290094695b5eade466d @jwilger committed Mar 22, 2013
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/github_v3_api.rb
View
13 lib/github_v3_api.rb
@@ -74,7 +74,18 @@ def get(path, params={}) #:nodoc:
result = RestClient.get("https://api.github.com" + path,
{:accept => :json,
:authorization => "token #{@access_token}"}.merge({:params => params}))
- JSON.parse(result)
+ result_data = JSON.parse(result)
+ # check for pagination
+ link = result.headers[:link]
+ if link then
+ re_relnext = /<https:\/\/api.github.com([^>]*)>; *rel="next"/
+ relnext_path = link.match re_relnext
+ if relnext_path && relnext_path[1] then
+ next_data = self.get(relnext_path[1], params)
+ result_data += next_data
+ end
+ end
+ result_data
rescue RestClient::Unauthorized
raise Unauthorized, "The access token is invalid according to GitHub"
end

0 comments on commit 011ac89

Please sign in to comment.
Something went wrong with that request. Please try again.