summaryrefslogtreecommitdiff
path: root/lib/github/collection.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-11 22:33:54 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commitfc42f3dffa364a360c76ff2785813d74f42016c7 (patch)
tree1bf7e3a340e910756ddde22bd4b8bdb1b6429048 /lib/github/collection.rb
parent7030eb3286613be919e12daf95c43061b49aa5f5 (diff)
downloadgitlab-ce-fc42f3dffa364a360c76ff2785813d74f42016c7.tar.gz
Add basic client for the GitHub API
Diffstat (limited to 'lib/github/collection.rb')
-rw-r--r--lib/github/collection.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/github/collection.rb b/lib/github/collection.rb
new file mode 100644
index 00000000000..bbca12a1c84
--- /dev/null
+++ b/lib/github/collection.rb
@@ -0,0 +1,26 @@
+module Github
+ class Collection
+ def initialize(url)
+ @url = url
+ end
+
+ def fetch(query = {})
+ return [] if @url.blank?
+
+ Enumerator.new do |yielder|
+ loop do
+ response = client.get(@url, query)
+ response.body.each { |item| yielder << item }
+ raise StopIteration unless response.rels.key?(:next)
+ @url = response.rels[:next]
+ end
+ end.lazy
+ end
+
+ private
+
+ def client
+ @client ||= Github::Client.new
+ end
+ end
+end