2017-04-11 21:33:54 -04:00
|
|
|
module Github
|
|
|
|
class Collection
|
2017-04-19 19:04:58 -04:00
|
|
|
attr_reader :options
|
|
|
|
|
|
|
|
def initialize(options)
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
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 }
|
2017-04-25 12:30:08 -04:00
|
|
|
|
2017-04-11 21:33:54 -04:00
|
|
|
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
|
2017-04-19 19:04:58 -04:00
|
|
|
@client ||= Github::Client.new(options)
|
2017-04-11 21:33:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|