github_api 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -1
- data/features/cassettes/pagination/repos.yml +174 -0
- data/features/cassettes/pagination/repos/commits.yml +181 -0
- data/features/cassettes/pagination/repos/commits/next.yml +175 -0
- data/features/cassettes/pagination/repos/commits/sha.yml +135 -0
- data/features/cassettes/pagination/repos/commits/sha/next.yml +136 -0
- data/features/cassettes/pagination/repos/diff.yml +169 -0
- data/features/cassettes/pagination/repos/diff/next.yml +132 -0
- data/features/cassettes/pagination/repos/next.yml +172 -0
- data/features/cassettes/repos/tags.yml +35 -0
- data/features/pagination.feature +62 -5
- data/features/repos.feature +6 -4
- data/features/step_definitions/common_steps.rb +8 -0
- data/features/step_definitions/github_api_steps.rb +19 -3
- data/lib/github_api/api.rb +2 -2
- data/lib/github_api/constants.rb +10 -0
- data/lib/github_api/page_iterator.rb +28 -9
- data/lib/github_api/page_uri_processor.rb +21 -0
- data/lib/github_api/paged_request.rb +1 -1
- data/lib/github_api/repos/watching.rb +8 -7
- data/lib/github_api/request.rb +2 -2
- data/lib/github_api/result.rb +13 -5
- data/lib/github_api/version.rb +1 -1
- data/spec/github/page_iterator_spec.rb +73 -5
- data/spec/github/repos/watching_spec.rb +2 -2
- data/spec/github/result_spec.rb +31 -7
- metadata +11 -2
@@ -0,0 +1,21 @@
|
|
1
|
+
module Github
|
2
|
+
class PageUriProcessor
|
3
|
+
include Github::Constants
|
4
|
+
include Github::Utils::Url
|
5
|
+
|
6
|
+
attr_reader :link, :query_string
|
7
|
+
|
8
|
+
def initialize(uri)
|
9
|
+
@link = uri.split(QUERY_STR_SEP).first
|
10
|
+
@query_string = uri.split(QUERY_STR_SEP).last
|
11
|
+
end
|
12
|
+
|
13
|
+
def resource_link
|
14
|
+
query_string
|
15
|
+
end
|
16
|
+
|
17
|
+
def query_hash
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -26,7 +26,7 @@ module Github
|
|
26
26
|
if params[PARAM_PER_PAGE] == NOT_FOUND
|
27
27
|
params[PARAM_PER_PAGE] = default_page_size
|
28
28
|
end
|
29
|
-
if
|
29
|
+
if params[PARAM_PAGE] && params[PARAM_PAGE] == NOT_FOUND
|
30
30
|
params[PARAM_PAGE] = default_page
|
31
31
|
end
|
32
32
|
|
@@ -11,7 +11,7 @@ module Github
|
|
11
11
|
# @github.repos.watchers
|
12
12
|
# @github.repos.watchers { |watcher| ... }
|
13
13
|
#
|
14
|
-
def watchers(user_name
|
14
|
+
def watchers(user_name, repo_name, params={})
|
15
15
|
_update_user_repo_params(user_name, repo_name)
|
16
16
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
17
17
|
_normalize_params_keys(params)
|
@@ -24,8 +24,8 @@ module Github
|
|
24
24
|
# List repos being watched by a user
|
25
25
|
#
|
26
26
|
# = Examples
|
27
|
-
# @github = Github.new
|
28
|
-
# @github.repos.watched
|
27
|
+
# @github = Github.new
|
28
|
+
# @github.repos.watched :user => 'user-name'
|
29
29
|
#
|
30
30
|
# List repos being watched by the authenticated user
|
31
31
|
#
|
@@ -33,12 +33,13 @@ module Github
|
|
33
33
|
# @github = Github.new :oauth_token => '...'
|
34
34
|
# @github.repos.watched
|
35
35
|
#
|
36
|
-
def watched(
|
37
|
-
|
36
|
+
def watched(*args)
|
37
|
+
params = args.last.is_a?(Hash) ? args.pop : {}
|
38
38
|
_normalize_params_keys(params)
|
39
|
+
_merge_user_into_params!(params) unless params.has_key?('user')
|
39
40
|
|
40
|
-
response = if user
|
41
|
-
get("/users/#{
|
41
|
+
response = if (user_name = params.delete('user'))
|
42
|
+
get("/users/#{user_name}/watched", params)
|
42
43
|
else
|
43
44
|
get("/user/watched", params)
|
44
45
|
end
|
data/lib/github_api/request.rb
CHANGED
@@ -63,8 +63,8 @@ module Github
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def _extract_mime_type(params, options) # :nodoc:
|
66
|
-
options['resource'] = params.delete('resource')
|
67
|
-
options['mime_type'] = params.delete('mime_type')
|
66
|
+
options['resource'] = params['resource'] ? params.delete('resource') : ''
|
67
|
+
options['mime_type'] = params['resource'] ? params.delete('mime_type') : ''
|
68
68
|
end
|
69
69
|
|
70
70
|
# no need for this smizzle
|
data/lib/github_api/result.rb
CHANGED
@@ -23,6 +23,14 @@ module Github
|
|
23
23
|
loaded? ? @env[:response_headers][CONTENT_LENGTH] : nil
|
24
24
|
end
|
25
25
|
|
26
|
+
def etag
|
27
|
+
loaded? ? @env[:response_headers][ETAG] : nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def server
|
31
|
+
loaded? ? @env[:response_headers][SERVER] : nil
|
32
|
+
end
|
33
|
+
|
26
34
|
def status
|
27
35
|
loaded? ? @env[:status] : nil
|
28
36
|
end
|
@@ -59,7 +67,7 @@ module Github
|
|
59
67
|
def first_page
|
60
68
|
first_request = page_iterator.first
|
61
69
|
self.instance_eval { @env = first_request.env } if first_request
|
62
|
-
|
70
|
+
self.body
|
63
71
|
end
|
64
72
|
|
65
73
|
# Retrives the result of the next page. Returns <tt>nil</tt> if there is
|
@@ -67,7 +75,7 @@ module Github
|
|
67
75
|
def next_page
|
68
76
|
next_request = page_iterator.next
|
69
77
|
self.instance_eval { @env = next_request.env } if next_request
|
70
|
-
|
78
|
+
self.body
|
71
79
|
end
|
72
80
|
|
73
81
|
# Retrives the result of the previous page. Returns <tt>nil</tt> if there is
|
@@ -75,7 +83,7 @@ module Github
|
|
75
83
|
def prev_page
|
76
84
|
prev_request = page_iterator.prev
|
77
85
|
self.instance_eval { @env = prev_request.env } if prev_request
|
78
|
-
|
86
|
+
self.body
|
79
87
|
end
|
80
88
|
alias :previous_page :prev_page
|
81
89
|
|
@@ -85,7 +93,7 @@ module Github
|
|
85
93
|
def last_page
|
86
94
|
last_request = page_iterator.last
|
87
95
|
self.instance_eval { @env = last_request.env } if last_request
|
88
|
-
|
96
|
+
self.body
|
89
97
|
end
|
90
98
|
|
91
99
|
# Retrives a specific result for a page given page number.
|
@@ -95,7 +103,7 @@ module Github
|
|
95
103
|
def page(page_number)
|
96
104
|
request = page_iterator.get_page(page_number)
|
97
105
|
self.instance_eval { @env = request.env } if request
|
98
|
-
|
106
|
+
self.body
|
99
107
|
end
|
100
108
|
|
101
109
|
# Returns <tt>true</tt> if there is another page in the result set,
|
data/lib/github_api/version.rb
CHANGED
@@ -5,14 +5,23 @@ describe Github::PageIterator do
|
|
5
5
|
let(:link) {
|
6
6
|
"<https://api.github.com/users/wycats/repos?page=4&per_page=20>; rel=\"next\", <https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\", <https://api.github.com/users/wycats/repos?page=2&per_page=20>; rel=\"prev\""
|
7
7
|
}
|
8
|
-
let(:
|
9
|
-
|
8
|
+
let(:sha_link) {
|
9
|
+
"<https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"next\", <https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"first\""
|
10
|
+
}
|
11
|
+
let(:env) { { :response_headers => {'Link' => link } } }
|
12
|
+
let(:sha_env) { { :response_headers => {'Link' => sha_link } } }
|
13
|
+
let(:first) { "https://api.github.com/users/wycats/repos?page=1&per_page=20" }
|
10
14
|
let(:nexxt) { "https://api.github.com/users/wycats/repos?page=4&per_page=20" }
|
11
|
-
let(:prev)
|
12
|
-
let(:last)
|
13
|
-
let(:user)
|
15
|
+
let(:prev) { "https://api.github.com/users/wycats/repos?page=2&per_page=20" }
|
16
|
+
let(:last) { "https://api.github.com/users/wycats/repos?page=6&per_page=20" }
|
17
|
+
let(:user) { 'wycats' }
|
18
|
+
let(:last_sha) { "d1e503c02fa770859895dd0d12aedefa28b95723"}
|
14
19
|
|
15
20
|
let(:instance) { Github::PageIterator.new(env) }
|
21
|
+
let(:sha_instance) { Github::PageIterator.new(sha_env) }
|
22
|
+
let(:sha_links) { Github::PageLinks.new(sha_env)}
|
23
|
+
let(:sha_first) { "https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
|
24
|
+
let(:sha_next) { "https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd"}
|
16
25
|
|
17
26
|
it { described_class::ATTRIBUTES.should_not be_nil }
|
18
27
|
|
@@ -27,6 +36,15 @@ describe Github::PageIterator do
|
|
27
36
|
it { instance.last_page.should eql 6 }
|
28
37
|
it { instance.last_page_uri.should eq last }
|
29
38
|
|
39
|
+
it { sha_instance.first_page.should eq -1 }
|
40
|
+
it { sha_instance.first_page_uri.should eq sha_first }
|
41
|
+
it { sha_instance.next_page.should eq -1 }
|
42
|
+
it { sha_instance.next_page_uri.should eq sha_next }
|
43
|
+
it { sha_instance.prev_page.should eq -1 }
|
44
|
+
it { sha_instance.prev_page_uri.should be_nil }
|
45
|
+
it { sha_instance.last_page.should eql -1 }
|
46
|
+
it { sha_instance.last_page_uri.should be_nil }
|
47
|
+
|
30
48
|
end
|
31
49
|
|
32
50
|
context 'has_next?' do
|
@@ -67,6 +85,31 @@ describe Github::PageIterator do
|
|
67
85
|
and_return link
|
68
86
|
instance.first
|
69
87
|
end
|
88
|
+
|
89
|
+
context 'no pagination params' do
|
90
|
+
before do
|
91
|
+
Github.new
|
92
|
+
sha_instance.stub(:has_next?).and_return true
|
93
|
+
sha_instance.stub(:next_page).and_return -1
|
94
|
+
|
95
|
+
stub_get("/repos/peter-murach/github/commits").
|
96
|
+
to_return(:body => '', :status => 200,
|
97
|
+
:headers => {
|
98
|
+
:content_type => "application/json; charset=utf-8",
|
99
|
+
'Link' => sha_link
|
100
|
+
}
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'receives sha params' do
|
105
|
+
sha_link.stub(:links).and_return sha_links
|
106
|
+
sha_instance.stub(:udpate_page_links)
|
107
|
+
sha_instance.should_receive(:page_request).
|
108
|
+
with("https://api.github.com/repos/peter-murach/github/commits",
|
109
|
+
'sha' => 'master', 'per_page' => 30).and_return sha_link
|
110
|
+
sha_instance.first
|
111
|
+
end
|
112
|
+
end
|
70
113
|
end # first
|
71
114
|
|
72
115
|
context 'next' do
|
@@ -96,6 +139,31 @@ describe Github::PageIterator do
|
|
96
139
|
'page' => 4,'per_page' => 20).and_return link
|
97
140
|
instance.next
|
98
141
|
end
|
142
|
+
|
143
|
+
context 'no pagination params' do
|
144
|
+
before do
|
145
|
+
Github.new
|
146
|
+
sha_instance.stub(:has_next?).and_return true
|
147
|
+
sha_instance.stub(:next_page).and_return -1
|
148
|
+
|
149
|
+
stub_get("/repos/peter-murach/github/commits").
|
150
|
+
to_return(:body => '', :status => 200,
|
151
|
+
:headers => {
|
152
|
+
:content_type => "application/json; charset=utf-8",
|
153
|
+
'Link' => sha_link
|
154
|
+
}
|
155
|
+
)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'receives sha params' do
|
159
|
+
sha_link.stub(:links).and_return sha_links
|
160
|
+
sha_instance.stub(:udpate_page_links)
|
161
|
+
sha_instance.should_receive(:page_request).
|
162
|
+
with("https://api.github.com/repos/peter-murach/github/commits",
|
163
|
+
'sha' => last_sha, 'per_page' => 30).and_return sha_link
|
164
|
+
sha_instance.next
|
165
|
+
end
|
166
|
+
end
|
99
167
|
end # next
|
100
168
|
|
101
169
|
context 'prev' do
|
@@ -56,7 +56,7 @@ describe Github::Repos::Watching, :type => :base do
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
-
describe "watched" do
|
59
|
+
describe ":watched:" do
|
60
60
|
|
61
61
|
context "if user unauthenticated" do
|
62
62
|
before do
|
@@ -76,7 +76,7 @@ describe Github::Repos::Watching, :type => :base do
|
|
76
76
|
it "should get the resource with username" do
|
77
77
|
stub_get("/users/#{user}/watched").
|
78
78
|
to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
|
79
|
-
github.repos.watched(user)
|
79
|
+
github.repos.watched(:user => user)
|
80
80
|
a_get("/users/#{user}/watched").should have_been_made
|
81
81
|
end
|
82
82
|
end
|
data/spec/github/result_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Github::Result do
|
|
4
4
|
|
5
5
|
let(:github) { Github.new }
|
6
6
|
let(:user) { 'wycats' }
|
7
|
-
let(:res) { github.events.public }
|
7
|
+
let(:res) { github.events.public :per_page => 20 }
|
8
8
|
let(:pages) { ['1', '5', '6'] }
|
9
9
|
let(:link) {
|
10
10
|
"<https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\""
|
@@ -12,6 +12,7 @@ describe Github::Result do
|
|
12
12
|
|
13
13
|
before do
|
14
14
|
stub_get("/events").
|
15
|
+
with(:query => { 'per_page' => '20' }).
|
15
16
|
to_return(:body => fixture('events/events.json'),
|
16
17
|
:status => 200,
|
17
18
|
:headers => {
|
@@ -19,12 +20,15 @@ describe Github::Result do
|
|
19
20
|
'X-RateLimit-Remaining' => '4999',
|
20
21
|
'X-RateLimit-Limit' => '5000',
|
21
22
|
'content-length' => '344',
|
23
|
+
'etag' => "\"d9a88f20567726e29d35c6fae87cef2f\"",
|
24
|
+
'server' => "nginx/1.0.4",
|
22
25
|
'Link' => link
|
23
26
|
})
|
24
27
|
|
25
|
-
['1', '5', '6'].each do |page|
|
28
|
+
['', '1', '5', '6'].each do |page|
|
29
|
+
params = page.empty? ? {'per_page'=>'20'} : {'per_page'=>'20', 'page'=>page}
|
26
30
|
stub_get("/users/#{user}/repos").
|
27
|
-
with(:query =>
|
31
|
+
with(:query => params).
|
28
32
|
to_return(:body => fixture('events/events.json'),
|
29
33
|
:status => 200,
|
30
34
|
:headers => {
|
@@ -57,6 +61,14 @@ describe Github::Result do
|
|
57
61
|
res.status.should be 200
|
58
62
|
end
|
59
63
|
|
64
|
+
it 'should read response etag' do
|
65
|
+
res.etag.should eql "\"d9a88f20567726e29d35c6fae87cef2f\""
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should read response server' do
|
69
|
+
res.server.should eql "nginx/1.0.4"
|
70
|
+
end
|
71
|
+
|
60
72
|
it "should assess successful" do
|
61
73
|
res.success?.should be_true
|
62
74
|
end
|
@@ -80,14 +92,26 @@ describe Github::Result do
|
|
80
92
|
end
|
81
93
|
|
82
94
|
%w[ next prev ].each do |link|
|
83
|
-
|
84
|
-
|
95
|
+
context "#{link}_page" do
|
96
|
+
it "should return collection of resources" do
|
97
|
+
res.send(:"#{link}_page").should be_an Array
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should have no link information' do
|
101
|
+
res.links.send(:"#{link}").should be_nil
|
102
|
+
end
|
85
103
|
end
|
86
104
|
end
|
87
105
|
|
88
106
|
%w[ first last].each do |link|
|
89
|
-
|
90
|
-
|
107
|
+
context "#{link}_page" do
|
108
|
+
it "should return resource if exists" do
|
109
|
+
res.send(:"#{link}_page").should_not be_empty
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should have link information" do
|
113
|
+
res.send(:"#{link}_page").should_not be_nil
|
114
|
+
end
|
91
115
|
end
|
92
116
|
end
|
93
117
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: github_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Piotr Murach
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-21 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -177,6 +177,14 @@ extra_rdoc_files: []
|
|
177
177
|
|
178
178
|
files:
|
179
179
|
- Rakefile
|
180
|
+
- features/cassettes/pagination/repos/commits/next.yml
|
181
|
+
- features/cassettes/pagination/repos/commits/sha/next.yml
|
182
|
+
- features/cassettes/pagination/repos/commits/sha.yml
|
183
|
+
- features/cassettes/pagination/repos/commits.yml
|
184
|
+
- features/cassettes/pagination/repos/diff/next.yml
|
185
|
+
- features/cassettes/pagination/repos/diff.yml
|
186
|
+
- features/cassettes/pagination/repos/next.yml
|
187
|
+
- features/cassettes/pagination/repos.yml
|
180
188
|
- features/cassettes/repos/branches.yml
|
181
189
|
- features/cassettes/repos/tags.yml
|
182
190
|
- features/cassettes/repos/teams.yml
|
@@ -222,6 +230,7 @@ files:
|
|
222
230
|
- lib/github_api/orgs.rb
|
223
231
|
- lib/github_api/page_iterator.rb
|
224
232
|
- lib/github_api/page_links.rb
|
233
|
+
- lib/github_api/page_uri_processor.rb
|
225
234
|
- lib/github_api/paged_request.rb
|
226
235
|
- lib/github_api/pull_requests/comments.rb
|
227
236
|
- lib/github_api/pull_requests.rb
|