gitlab-ruby 0.1.0.pre → 0.1.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bae0303d813deb88c096599308727f3f078b3b6c2f57de3546446f037ba1eba4
4
- data.tar.gz: a4a9222fd8c8ac606ff47b082345f1f084cb8df5af0cf9ae38730b1bd17b7d7a
3
+ metadata.gz: 69eaed3eb91232c2aecbb26b98be4cd5a29fde24248e10a852f659516bb247d0
4
+ data.tar.gz: 1725f8b68db38f3f053e27ff55337401c052b88d01e84831ffd8992389b6b3bc
5
5
  SHA512:
6
- metadata.gz: bfacc95fb95804577dfe04bb5c8b610278cd6dddd8eb398b8b79a47673f881dff0766118c25a93cb707a6be3b13998c1f51f627f0fab2958886f5e35ba00de23
7
- data.tar.gz: ff14425d09ab5dc94ed2e77b3ff0a88869b7a312639c60dc961fbe8f9c903bae22368776791e0d1b3dc39c614aadc122948103af868f1c7353e527ad92e92fc8
6
+ metadata.gz: 82624e6e5b3c2ea05b39741e860b28c002ad9d1e1da63143987c7737cfed894521a65732f2feaabcf011f706fdf4edfd5746e1cfc04305ab5f0cb327229f9680
7
+ data.tar.gz: 86991c0381614452da9f14f7f7e1e8ff250a82bc4286060b222f069a72b2a23f3107f7f13f64ab160245284d5462dafc7460bf3642fbd3e3d5d03f09c3dad216
data/README.md CHANGED
@@ -33,15 +33,11 @@ end
33
33
 
34
34
  #### Pagination
35
35
  ```ruby
36
- loop do
37
- page = 1
38
- response = client.issues.list(page: 1)
39
- response.body.each do |issue|
40
- # Do Something
41
- end
42
-
43
- page = response.next_page
44
- break if page.zero?
36
+ client = Gitlab::Client.new(private_token: 'secret')
37
+ response = client.issues.list
38
+
39
+ while (response = response.next_page) do
40
+ # Do something with next page
45
41
  end
46
42
  ```
47
43
 
@@ -9,8 +9,18 @@ module Gitlab
9
9
 
10
10
  protected
11
11
 
12
- def handle_response(response)
13
- Gitlab::Response.new(response)
12
+ def handle_action(action)
13
+ response = action.call
14
+ Gitlab::Response.new(response, action)
15
+ end
16
+
17
+ private
18
+
19
+ def with_pagination(args)
20
+ proc do |page = nil|
21
+ args[:page] = page unless page.nil?
22
+ yield
23
+ end
14
24
  end
15
25
  end
16
26
  end
@@ -4,18 +4,18 @@ module Gitlab
4
4
  PATH = 'issues'
5
5
 
6
6
  def list(args = {})
7
- response = connection.get(PATH, args)
8
- handle_response(response)
7
+ action = with_pagination(args) { connection.get(PATH, args) }
8
+ handle_action(action)
9
9
  end
10
10
 
11
11
  def list_group(group, args = {})
12
- response = connection.get(group_path(group), args)
13
- handle_response(response)
12
+ action = with_pagination(args) { connection.get(group_path(group), args) }
13
+ handle_action(action)
14
14
  end
15
15
 
16
16
  def list_project(project, args = {})
17
- response = connection.get(project_path(project), args)
18
- handle_response(response)
17
+ action = with_pagination(args) { connection.get(project_path(project), args) }
18
+ handle_action(action)
19
19
  end
20
20
 
21
21
  private
@@ -1,14 +1,14 @@
1
1
  module Gitlab
2
2
  module Pagination
3
- def current_page
3
+ def current_page_number
4
4
  headers['x-page'].to_i
5
5
  end
6
6
 
7
- def next_page
7
+ def next_page_number
8
8
  headers['x-next-page'].to_i
9
9
  end
10
10
 
11
- def prev_page
11
+ def prev_page_number
12
12
  headers['x-prev-page'].to_i
13
13
  end
14
14
 
@@ -24,8 +24,11 @@ module Gitlab
24
24
  headers['x-per-page'].to_i
25
25
  end
26
26
 
27
- def request_next_page
28
- raise NotMethodError
27
+ def next_page
28
+ return nil if next_page_number.zero?
29
+
30
+ response = @action.call(next_page_number)
31
+ self.class.new(response, @action)
29
32
  end
30
33
  end
31
34
  end
@@ -2,11 +2,12 @@ module Gitlab
2
2
  class Response < Faraday::Response
3
3
  include Gitlab::Pagination
4
4
 
5
- attr_reader :gateway
5
+ attr_reader :gateway, :action
6
6
 
7
- def initialize(response)
7
+ def initialize(response, action = proc {})
8
8
  super()
9
9
  finish(response.env)
10
+ @action = action
10
11
  end
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module Gitlab
2
- VERSION = "0.1.0.pre"
2
+ VERSION = "0.1.1.pre"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
4
+ version: 0.1.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Scott
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler