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