diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-25 23:06:10 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-25 23:06:10 +0300 |
commit | ebd8e4333a263138abf2113dd315a97352851cbe (patch) | |
tree | 4e4975eab778d490c20c9252785761a1d78fae26 /lib/bitbucket_server/paginator.rb | |
parent | 2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff) |
WIP: Add support for Bitbucket Server imports
Diffstat (limited to 'lib/bitbucket_server/paginator.rb')
-rw-r--r-- | lib/bitbucket_server/paginator.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/bitbucket_server/paginator.rb b/lib/bitbucket_server/paginator.rb new file mode 100644 index 00000000000..c995cf4c3bd --- /dev/null +++ b/lib/bitbucket_server/paginator.rb @@ -0,0 +1,36 @@ +module BitbucketServer + class Paginator + PAGE_LENGTH = 25 # The minimum length is 10 and the maximum is 100. + + def initialize(connection, url, type) + @connection = connection + @type = type + @url = url + @page = nil + end + + def items + raise StopIteration unless has_next_page? + + @page = fetch_next_page + @page.items + end + + private + + attr_reader :connection, :page, :url, :type + + def has_next_page? + page.nil? || page.next? + end + + def next_url + page.nil? ? url : page.next + end + + def fetch_next_page + parsed_response = connection.get(next_url, pagelen: PAGE_LENGTH, sort: :created_on) + Page.new(parsed_response, type) + end + end +end |