2017-04-11 21:33:54 -04:00
|
|
|
module Github
|
|
|
|
class Collection
|
2017-04-12 21:43:38 -04:00
|
|
|
def fetch(url, query = {})
|
|
|
|
return [] if url.blank?
|
2017-04-11 21:33:54 -04:00
|
|
|
|
|
|
|
Enumerator.new do |yielder|
|
|
|
|
loop do
|
2017-04-12 21:43:38 -04:00
|
|
|
response = client.get(url, query)
|
2017-04-11 21:33:54 -04:00
|
|
|
response.body.each { |item| yielder << item }
|
|
|
|
raise StopIteration unless response.rels.key?(:next)
|
2017-04-12 21:43:38 -04:00
|
|
|
url = response.rels[:next]
|
2017-04-11 21:33:54 -04:00
|
|
|
end
|
|
|
|
end.lazy
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def client
|
|
|
|
@client ||= Github::Client.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|