Skip to content

Instantly share code, notes, and snippets.

@kytrinyx
Last active June 26, 2017 21:01
Show Gist options
  • Save kytrinyx/624c2e3243f5e4ab9532c5c0ad37c7a2 to your computer and use it in GitHub Desktop.
Save kytrinyx/624c2e3243f5e4ab9532c5c0ad37c7a2 to your computer and use it in GitHub Desktop.
require 'octokit'
def with_each(client, path)
response = client.agent.call(:get, URI::Parser.new.escape(path.to_s), nil, {})
response.data.each do |org|
yield org
end
last_response = response
while last_response.rels[:next] && client.rate_limit.remaining > 0
response = last_response.rels[:next].get
response.data.each do |org|
yield org
end
last_response = response
end
end
client = Octokit::Client.new(:access_token => ENV["A_TOKEN"])
with_each(client, "/user/orgs") do |org|
# do stuff
end
require 'octokit'
client = Octokit::Client.new(:access_token => ENV['A_TOKEN'])
# prime the client
client.get("/orgs/exercism/teams", :per_page => 100)
response = client.last_response
while true
# do stuff with the data here
break if response.rels[:next].nil?
# handle rate limit
if response.headers["x-ratelimit-remaining"].to_i.zero?
seconds = response.headers["x-ratelimit-reset"].to_i - Time.now.utc.to_i
sleep seconds
end
# get the next batch of data
response = response.rels[:next].get
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment