github_api 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/github_api/api.rb +1 -1
- data/lib/github_api/repos/hooks.rb +1 -1
- data/lib/github_api/users/emails.rb +9 -3
- data/lib/github_api/users/keys.rb +4 -2
- data/lib/github_api/version.rb +1 -1
- data/spec/github/repos/commits_spec.rb +2 -1
- data/spec/github/repos/hooks_spec.rb +0 -1
- data/spec/github/users/emails_spec.rb +106 -2
- data/spec/github/users/keys_spec.rb +249 -2
- metadata +2 -2
data/lib/github_api/api.rb
CHANGED
@@ -42,7 +42,7 @@ module Github
|
|
42
42
|
# @github.repos.hooks 'user-name', 'repo-name'
|
43
43
|
# @github.repos.hooks 'user-name', 'repo-name' { |hook| ... }
|
44
44
|
#
|
45
|
-
def hooks(user_name
|
45
|
+
def hooks(user_name, repo_name, params={})
|
46
46
|
_update_user_repo_params(user_name, repo_name)
|
47
47
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
48
48
|
_normalize_params_keys(params)
|
@@ -9,9 +9,13 @@ module Github
|
|
9
9
|
# = Examples
|
10
10
|
# @github = Github.new :oauth_token => '...'
|
11
11
|
# @github.users.emails
|
12
|
+
# @github.users.emails { |email| ... }
|
12
13
|
#
|
13
14
|
def emails(params={})
|
14
|
-
|
15
|
+
_normalize_params_keys(params)
|
16
|
+
response = get("/user/emails", params)
|
17
|
+
return response unless block_given?
|
18
|
+
response.each { |el| yield el }
|
15
19
|
end
|
16
20
|
|
17
21
|
# Add email address(es) for the authenticated user
|
@@ -25,7 +29,8 @@ module Github
|
|
25
29
|
#
|
26
30
|
def add_email(*args)
|
27
31
|
params = _extract_parameters(args)
|
28
|
-
params
|
32
|
+
_normalize_params_keys(params)
|
33
|
+
params['data'] = [args].flatten if args
|
29
34
|
post("/user/emails", params)
|
30
35
|
end
|
31
36
|
|
@@ -38,8 +43,9 @@ module Github
|
|
38
43
|
# @github = Github.new :oauth_token => '...'
|
39
44
|
# @github.users.delete_email "octocat@github.com", "support@github.com"
|
40
45
|
#
|
41
|
-
def
|
46
|
+
def delete_email(*args)
|
42
47
|
params = _extract_parameters(args)
|
48
|
+
_normalize_params_keys(params)
|
43
49
|
params['data'] = [args].flatten
|
44
50
|
delete("/user/emails", params)
|
45
51
|
end
|
@@ -13,12 +13,13 @@ module Github
|
|
13
13
|
# @github.users.public_keys
|
14
14
|
# @github.users.public_keys { |key| ... }
|
15
15
|
#
|
16
|
-
def
|
16
|
+
def keys(params={})
|
17
17
|
_normalize_params_keys(params)
|
18
18
|
response = get("/user/keys", params)
|
19
19
|
return response unless block_given?
|
20
20
|
response.each { |el| yield el }
|
21
21
|
end
|
22
|
+
alias :public_keys :keys
|
22
23
|
|
23
24
|
# Get a single pulic key for the authenticated user
|
24
25
|
#
|
@@ -26,11 +27,12 @@ module Github
|
|
26
27
|
# @github = Github.new :oauth_token => '...'
|
27
28
|
# @github.users.public_key 'key-id'
|
28
29
|
#
|
29
|
-
def
|
30
|
+
def key(key_id, params={})
|
30
31
|
_validate_presence_of key_id
|
31
32
|
_normalize_params_keys(params)
|
32
33
|
get("/user/keys/#{key_id}", params)
|
33
34
|
end
|
35
|
+
alias :public_key :key
|
34
36
|
|
35
37
|
# Create a public key for the authenticated user
|
36
38
|
#
|
data/lib/github_api/version.rb
CHANGED
@@ -4,7 +4,8 @@ describe Github::Repos::Commits do
|
|
4
4
|
let(:github) { Github.new }
|
5
5
|
let(:user) { 'peter-murach' }
|
6
6
|
let(:repo) { 'github' }
|
7
|
-
|
7
|
+
|
8
|
+
after { github.user, github.repo, github.oauth_token = nil, nil, nil }
|
8
9
|
|
9
10
|
describe "commits" do
|
10
11
|
context "resource found" do
|
@@ -1,5 +1,109 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Github::Users::Emails
|
4
|
-
|
3
|
+
describe Github::Users::Emails do
|
4
|
+
let(:github) { Github.new }
|
5
|
+
let(:email) { "octocat@github.com" }
|
6
|
+
|
7
|
+
before { github.oauth_token = OAUTH_TOKEN }
|
8
|
+
after { reset_authentication_for github }
|
9
|
+
|
10
|
+
describe "#emails" do
|
11
|
+
context "resource found for an authenticated user" do
|
12
|
+
before do
|
13
|
+
stub_get("/user/emails").
|
14
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
15
|
+
to_return(:body => fixture('users/emails.json'),
|
16
|
+
:status => 200,
|
17
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get the resources" do
|
21
|
+
github.users.emails
|
22
|
+
a_get("/user/emails").
|
23
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
24
|
+
should have_been_made
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return resource" do
|
28
|
+
emails = github.users.emails
|
29
|
+
emails.should be_an Array
|
30
|
+
emails.should have(2).items
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get emails information" do
|
34
|
+
emails = github.users.emails
|
35
|
+
emails.first.should == email
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should yield to a block" do
|
39
|
+
github.users.should_receive(:emails).and_yield('web')
|
40
|
+
github.users.emails { |param| 'web' }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "resource not found for a user" do
|
45
|
+
before do
|
46
|
+
stub_get("/user/emails").
|
47
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
48
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return 404 with a message 'Not Found'" do
|
52
|
+
expect {
|
53
|
+
github.users.emails
|
54
|
+
}.to raise_error(Github::Error::NotFound)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end # emails
|
58
|
+
|
59
|
+
context '#add_email' do
|
60
|
+
let(:params) { { :per_page => 21, :page => 1 }}
|
61
|
+
|
62
|
+
before do
|
63
|
+
stub_post("/user/emails").
|
64
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
65
|
+
to_return(:body => fixture('users/emails.json'),
|
66
|
+
:status => 200,
|
67
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'extracts request parameters and email data' do
|
71
|
+
github.users.should_receive(:post).
|
72
|
+
with("/user/emails", { "per_page" => 21, "page" => 1, "data" => [email] })
|
73
|
+
github.users.add_email email, params
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'submits request successfully' do
|
77
|
+
github.users.add_email email
|
78
|
+
a_post("/user/emails").
|
79
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
80
|
+
should have_been_made
|
81
|
+
end
|
82
|
+
end # add_email
|
83
|
+
|
84
|
+
context '#delete_email' do
|
85
|
+
let(:params) { { :per_page => 21, :page => 1 }}
|
86
|
+
|
87
|
+
before do
|
88
|
+
stub_delete("/user/emails").
|
89
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}", :data => email}).
|
90
|
+
to_return(:body => fixture('users/emails.json'),
|
91
|
+
:status => 200,
|
92
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'extracts request parameters and email data' do
|
96
|
+
github.users.should_receive(:delete).
|
97
|
+
with("/user/emails", { "per_page" => 21, "page" => 1, "data" => [email] })
|
98
|
+
github.users.delete_email email, params
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'submits request successfully' do
|
102
|
+
github.users.delete_email email
|
103
|
+
a_delete("/user/emails").
|
104
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}", :data => email } ).
|
105
|
+
should have_been_made
|
106
|
+
end
|
107
|
+
end # delete_email
|
108
|
+
|
5
109
|
end # Github::Users::Emails
|
@@ -1,5 +1,252 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Github::Users::Keys
|
4
|
-
|
3
|
+
describe Github::Users::Keys do
|
4
|
+
let(:github) { Github.new }
|
5
|
+
let(:key_id) { 1 }
|
6
|
+
|
7
|
+
before { github.oauth_token = OAUTH_TOKEN }
|
8
|
+
after { reset_authentication_for github }
|
9
|
+
|
10
|
+
describe "#keys" do
|
11
|
+
context "resource found for an authenticated user" do
|
12
|
+
before do
|
13
|
+
stub_get("/user/keys").
|
14
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
15
|
+
to_return(:body => fixture('users/keys.json'),
|
16
|
+
:status => 200,
|
17
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get the resources" do
|
21
|
+
github.users.keys
|
22
|
+
a_get("/user/keys").
|
23
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
24
|
+
should have_been_made
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return resource" do
|
28
|
+
keys = github.users.keys
|
29
|
+
keys.should be_an Array
|
30
|
+
keys.should have(1).item
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get keys information" do
|
34
|
+
keys = github.users.keys
|
35
|
+
keys.first.id.should == key_id
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should yield to a block" do
|
39
|
+
github.users.should_receive(:keys).and_yield('web')
|
40
|
+
github.users.keys { |param| 'web' }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "resource not found for a user" do
|
45
|
+
before do
|
46
|
+
stub_get("/user/keys").
|
47
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
48
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return 404 with a message 'Not Found'" do
|
52
|
+
expect {
|
53
|
+
github.users.keys
|
54
|
+
}.to raise_error(Github::Error::NotFound)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end # keys
|
58
|
+
|
59
|
+
describe "#key" do
|
60
|
+
context "resource found for an authenticated user" do
|
61
|
+
before do
|
62
|
+
stub_get("/user/keys/#{key_id}").
|
63
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
64
|
+
to_return(:body => fixture('users/key.json'),
|
65
|
+
:status => 200,
|
66
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should fail to get resource without key id" do
|
70
|
+
expect { github.users.key nil }.to raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should get the resource" do
|
74
|
+
github.users.key key_id
|
75
|
+
a_get("/user/keys/#{key_id}").
|
76
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
77
|
+
should have_been_made
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get public key information" do
|
81
|
+
key = github.users.key key_id
|
82
|
+
key.id.should == key_id
|
83
|
+
key.title.should == 'octocat@octomac'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return mash" do
|
87
|
+
key = github.users.key key_id
|
88
|
+
key.should be_a Hashie::Mash
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "resource not found" do
|
93
|
+
before do
|
94
|
+
stub_get("/user/keys/#{key_id}").
|
95
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
96
|
+
to_return(:body => fixture('users/key.json'),
|
97
|
+
:status => 404,
|
98
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should fail to retrive resource" do
|
102
|
+
expect {
|
103
|
+
github.users.key key_id
|
104
|
+
}.to raise_error(Github::Error::NotFound)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end # key
|
108
|
+
|
109
|
+
describe "create_key" do
|
110
|
+
let(:inputs) {
|
111
|
+
{
|
112
|
+
:title => "octocat@octomac",
|
113
|
+
:key => "ssh-rsa AAA...",
|
114
|
+
:unrelated => true
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
context "resouce created" do
|
119
|
+
before do
|
120
|
+
stub_post("/user/keys?access_token=#{OAUTH_TOKEN}").
|
121
|
+
with(:body => JSON.generate(inputs.except(:unrelated))).
|
122
|
+
to_return(:body => fixture('users/key.json'),
|
123
|
+
:status => 201,
|
124
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should create resource successfully" do
|
128
|
+
github.users.create_key inputs
|
129
|
+
a_post("/user/keys?access_token=#{OAUTH_TOKEN}").
|
130
|
+
with(inputs).should have_been_made
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should return the resource" do
|
134
|
+
key = github.users.create_key inputs
|
135
|
+
key.should be_a Hashie::Mash
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should get the key information" do
|
139
|
+
key = github.users.create_key inputs
|
140
|
+
key.title.should == 'octocat@octomac'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "fail to create resource" do
|
145
|
+
before do
|
146
|
+
stub_post("/user/keys?access_token=#{OAUTH_TOKEN}").with(inputs).
|
147
|
+
to_return(:body => fixture('users/key.json'),
|
148
|
+
:status => 404,
|
149
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should fail to retrieve resource" do
|
153
|
+
expect {
|
154
|
+
github.users.create_key inputs
|
155
|
+
}.to raise_error(Github::Error::NotFound)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end # create_key
|
159
|
+
|
160
|
+
describe "#update_key" do
|
161
|
+
let(:inputs) {
|
162
|
+
{
|
163
|
+
:title => "octocat@octomac",
|
164
|
+
:key => "ssh-rsa AAA...",
|
165
|
+
:unrelated => true
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
context "resouce updated" do
|
170
|
+
before do
|
171
|
+
stub_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
172
|
+
with(:body => JSON.generate(inputs.except(:unrelated))).
|
173
|
+
to_return(:body => fixture('users/key.json'),
|
174
|
+
:status => 201,
|
175
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should fail to get resource without key id" do
|
179
|
+
expect { github.users.update_key nil }.to raise_error(ArgumentError)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should create resource successfully" do
|
183
|
+
github.users.update_key key_id, inputs
|
184
|
+
a_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
185
|
+
with(inputs).should have_been_made
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return the resource" do
|
189
|
+
key = github.users.update_key key_id, inputs
|
190
|
+
key.should be_a Hashie::Mash
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should get the key information" do
|
194
|
+
key = github.users.update_key key_id, inputs
|
195
|
+
key.title.should == 'octocat@octomac'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "fail to update resource" do
|
200
|
+
before do
|
201
|
+
stub_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
202
|
+
with(inputs).
|
203
|
+
to_return(:body => fixture('users/key.json'),
|
204
|
+
:status => 404,
|
205
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should fail to retrieve resource" do
|
209
|
+
expect {
|
210
|
+
github.users.update_key key_id, inputs
|
211
|
+
}.to raise_error(Github::Error::NotFound)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end # update_key
|
215
|
+
|
216
|
+
describe "#delete_key" do
|
217
|
+
context "resouce deleted" do
|
218
|
+
before do
|
219
|
+
stub_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
220
|
+
to_return(:body => fixture('users/key.json'),
|
221
|
+
:status => 204,
|
222
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should fail to get resource without key id" do
|
226
|
+
expect { github.users.delete_key nil }.to raise_error(ArgumentError)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should create resource successfully" do
|
230
|
+
github.users.delete_key key_id
|
231
|
+
a_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
232
|
+
should have_been_made
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "fail to delete resource" do
|
237
|
+
before do
|
238
|
+
stub_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
|
239
|
+
to_return(:body => fixture('users/key.json'),
|
240
|
+
:status => 404,
|
241
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should fail to delete resource" do
|
245
|
+
expect {
|
246
|
+
github.users.delete_key key_id
|
247
|
+
}.to raise_error(Github::Error::NotFound)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end # delete_key
|
251
|
+
|
5
252
|
end # Github::Users::Keys
|
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.8
|
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-03-
|
13
|
+
date: 2012-03-17 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|