github_api 0.8.8 → 0.8.9
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 +2 -1
- data/features/cassettes/orgs/members/list.yml +139 -0
- data/features/cassettes/orgs/members/list_public.yml +140 -0
- data/features/cassettes/orgs/members/member_false.yml +52 -0
- data/features/cassettes/orgs/members/member_public_false.yml +55 -0
- data/features/cassettes/orgs/members/member_public_true.yml +48 -0
- data/features/orgs/members.feature +57 -0
- data/lib/github_api/connection.rb +4 -4
- data/lib/github_api/orgs/members.rb +28 -35
- data/lib/github_api/orgs/teams.rb +14 -13
- data/lib/github_api/version.rb +1 -1
- data/spec/github/gists/create_spec.rb +64 -0
- data/spec/github/gists/delete_spec.rb +31 -0
- data/spec/github/gists/edit_spec.rb +60 -0
- data/spec/github/gists/fork_spec.rb +41 -0
- data/spec/github/gists/get_spec.rb +47 -0
- data/spec/github/gists/gists_spec.rb +7 -0
- data/spec/github/gists/is_starred_spec.rb +42 -0
- data/spec/github/gists/list_spec.rb +78 -0
- data/spec/github/gists/star_spec.rb +30 -0
- data/spec/github/gists/starred_spec.rb +44 -0
- data/spec/github/gists/unstar_spec.rb +30 -0
- data/spec/github/orgs/members/conceal_spec.rb +35 -0
- data/spec/github/orgs/members/delete_spec.rb +33 -0
- data/spec/github/orgs/members/list_spec.rb +82 -0
- data/spec/github/orgs/members/member_spec.rb +65 -0
- data/spec/github/orgs/members/publicize_spec.rb +35 -0
- data/spec/github/orgs/members_spec.rb +0 -277
- data/spec/github/orgs/teams/add_member_spec.rb +38 -0
- data/spec/github/orgs/teams/add_repo_spec.rb +39 -0
- data/spec/github/orgs/teams/create_spec.rb +58 -0
- data/spec/github/orgs/teams/delete_spec.rb +36 -0
- data/spec/github/orgs/teams/edit_spec.rb +57 -0
- data/spec/github/orgs/teams/get_spec.rb +45 -0
- data/spec/github/orgs/teams/list_members_spec.rb +49 -0
- data/spec/github/orgs/teams/list_repos_spec.rb +49 -0
- data/spec/github/orgs/teams/list_spec.rb +49 -0
- data/spec/github/orgs/teams/remove_member_spec.rb +40 -0
- data/spec/github/orgs/teams/remove_repo_spec.rb +40 -0
- data/spec/github/orgs/teams/team_member_spec.rb +40 -0
- data/spec/github/orgs/teams/team_repo_spec.rb +43 -0
- data/spec/github/orgs/teams_spec.rb +2 -566
- metadata +67 -33
- data/spec/github/gists_spec.rb +0 -470
@@ -26,10 +26,10 @@ module Github
|
|
26
26
|
def default_options(options={})
|
27
27
|
{
|
28
28
|
:headers => {
|
29
|
-
ACCEPT =>
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
ACCEPT => "application/vnd.github.v3.full+json," \
|
30
|
+
"application/vnd.github.beta.full+json;q=0.7," \
|
31
|
+
"application/vnd.github+json;q=0.5," \
|
32
|
+
"application/json;q=0.1",
|
33
33
|
ACCEPT_CHARSET => "utf-8",
|
34
34
|
USER_AGENT => user_agent,
|
35
35
|
CONTENT_TYPE => 'application/json'
|
@@ -16,26 +16,50 @@ module Github
|
|
16
16
|
# github.orgs.members.list 'org-name'
|
17
17
|
# github.orgs.members.list 'org-name' { |memb| ... }
|
18
18
|
#
|
19
|
+
# List public members
|
20
|
+
#
|
21
|
+
# Members of an organization can choose to have their membership publicized or not.
|
22
|
+
# = Examples
|
23
|
+
# github = Github.new
|
24
|
+
# github.orgs.members.list 'org-name', :public => true
|
25
|
+
# github.orgs.members.list 'org-name', :public => true { |memb| ... }
|
26
|
+
#
|
19
27
|
def list(org_name, params={})
|
20
28
|
assert_presence_of org_name
|
21
29
|
normalize! params
|
22
|
-
|
30
|
+
|
31
|
+
response = if params.delete('public')
|
32
|
+
get_request("/orgs/#{org_name}/public_members", params)
|
33
|
+
else
|
34
|
+
get_request("/orgs/#{org_name}/members", params)
|
35
|
+
end
|
23
36
|
return response unless block_given?
|
24
37
|
response.each { |el| yield el }
|
25
38
|
end
|
26
39
|
alias :all :list
|
27
40
|
|
28
|
-
# Check if user is a member of an organization
|
41
|
+
# Check if user is, publicly or privately, a member of an organization
|
29
42
|
#
|
30
43
|
# = Examples
|
31
44
|
# github = Github.new
|
32
45
|
# github.orgs.members.member? 'org-name', 'member-name'
|
33
46
|
#
|
47
|
+
# Check if a user is a public member of an organization
|
48
|
+
#
|
49
|
+
# = Examples
|
50
|
+
# github = Github.new
|
51
|
+
# github.orgs.members.member? 'org-name', 'member-name', :public => true
|
52
|
+
#
|
34
53
|
def member?(org_name, member_name, params={})
|
35
54
|
assert_presence_of org_name, member_name
|
36
55
|
normalize! params
|
37
|
-
|
38
|
-
|
56
|
+
|
57
|
+
response = if params.delete('public')
|
58
|
+
get_request("/orgs/#{org_name}/public_members/#{member_name}", params)
|
59
|
+
else
|
60
|
+
get_request("/orgs/#{org_name}/members/#{member_name}", params)
|
61
|
+
end
|
62
|
+
response.status == 204
|
39
63
|
rescue Github::Error::NotFound
|
40
64
|
false
|
41
65
|
end
|
@@ -55,37 +79,6 @@ module Github
|
|
55
79
|
end
|
56
80
|
alias :remove :delete
|
57
81
|
|
58
|
-
# List public members
|
59
|
-
# Members of an organization can choose to have their membership publicized or not.
|
60
|
-
# = Examples
|
61
|
-
# github = Github.new
|
62
|
-
# github.orgs.members.list_public 'org-name'
|
63
|
-
# github.orgs.members.list_public 'org-name' { |memb| ... }
|
64
|
-
#
|
65
|
-
def list_public(org_name, params={})
|
66
|
-
assert_presence_of org_name
|
67
|
-
normalize! params
|
68
|
-
response = get_request("/orgs/#{org_name}/public_members", params)
|
69
|
-
return response unless block_given?
|
70
|
-
response.each { |el| yield el }
|
71
|
-
end
|
72
|
-
alias :public_members :list_public
|
73
|
-
|
74
|
-
# Get if a user is a public member of an organization
|
75
|
-
#
|
76
|
-
# = Examples
|
77
|
-
# github = Github.new
|
78
|
-
# github.orgs.members.public_member? 'org-name', 'member-name'
|
79
|
-
#
|
80
|
-
def public_member?(org_name, member_name, params={})
|
81
|
-
assert_presence_of org_name, member_name
|
82
|
-
normalize! params
|
83
|
-
get_request("/orgs/#{org_name}/public_members/#{member_name}", params)
|
84
|
-
true
|
85
|
-
rescue Github::Error::NotFound
|
86
|
-
false
|
87
|
-
end
|
88
|
-
|
89
82
|
# Publicize a user’s membership
|
90
83
|
#
|
91
84
|
# = Examples
|
@@ -135,11 +135,11 @@ module Github
|
|
135
135
|
# github = Github.new :oauth_token => '...'
|
136
136
|
# github.orgs.teams.team_member? 'team-id', 'user-name'
|
137
137
|
#
|
138
|
-
def team_member?(team_id,
|
139
|
-
assert_presence_of team_id,
|
138
|
+
def team_member?(team_id, user_name, params={})
|
139
|
+
assert_presence_of team_id, user_name
|
140
140
|
normalize! params
|
141
|
-
get_request("/teams/#{team_id}/members/#{
|
142
|
-
|
141
|
+
response = get_request("/teams/#{team_id}/members/#{user_name}", params)
|
142
|
+
response.status == 204
|
143
143
|
rescue Github::Error::NotFound
|
144
144
|
false
|
145
145
|
end
|
@@ -151,14 +151,15 @@ module Github
|
|
151
151
|
# github = Github.new :oauth_token => '...'
|
152
152
|
# github.orgs.teams.add_member 'team-id', 'user-name'
|
153
153
|
#
|
154
|
-
def add_member(team_id,
|
155
|
-
assert_presence_of team_id,
|
154
|
+
def add_member(team_id, user_name, params={})
|
155
|
+
assert_presence_of team_id, user_name
|
156
156
|
normalize! params
|
157
|
-
put_request("/teams/#{team_id}/members/#{
|
157
|
+
put_request("/teams/#{team_id}/members/#{user_name}", params)
|
158
158
|
end
|
159
159
|
alias :add_team_member :add_member
|
160
160
|
|
161
161
|
# Remove a team member
|
162
|
+
#
|
162
163
|
# In order to remove a user from a team, the authenticated user must
|
163
164
|
# have ‘admin’ permissions to the team or be an owner of the org that
|
164
165
|
# the team is associated with.
|
@@ -166,12 +167,12 @@ module Github
|
|
166
167
|
#
|
167
168
|
# = Examples
|
168
169
|
# github = Github.new :oauth_token => '...'
|
169
|
-
# github.orgs.teams.remove_member 'team-id', '
|
170
|
+
# github.orgs.teams.remove_member 'team-id', 'user-name'
|
170
171
|
#
|
171
|
-
def remove_member(team_id,
|
172
|
-
assert_presence_of team_id,
|
172
|
+
def remove_member(team_id, user_name, params={})
|
173
|
+
assert_presence_of team_id, user_name
|
173
174
|
normalize! params
|
174
|
-
delete_request("/teams/#{team_id}/members/#{
|
175
|
+
delete_request("/teams/#{team_id}/members/#{user_name}", params)
|
175
176
|
end
|
176
177
|
alias :remove_team_member :remove_member
|
177
178
|
|
@@ -200,8 +201,8 @@ module Github
|
|
200
201
|
def team_repo?(team_id, user_name, repo_name, params={})
|
201
202
|
assert_presence_of team_id, user_name, repo_name
|
202
203
|
normalize! params
|
203
|
-
get_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params)
|
204
|
-
|
204
|
+
response = get_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params)
|
205
|
+
response.status == 204
|
205
206
|
rescue Github::Error::NotFound
|
206
207
|
false
|
207
208
|
end
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#create' do
|
6
|
+
let(:request_path) { "/gists" }
|
7
|
+
|
8
|
+
let(:inputs) {
|
9
|
+
{
|
10
|
+
"description" => "the description for this gist",
|
11
|
+
"public" => true,
|
12
|
+
"files" => {
|
13
|
+
"file1.txt" => {
|
14
|
+
"content" => "String file contents"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
before {
|
21
|
+
stub_post(request_path).with(inputs).
|
22
|
+
to_return(:body => body, :status => status,
|
23
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
}
|
25
|
+
|
26
|
+
after { reset_authentication_for(subject) }
|
27
|
+
|
28
|
+
context "resouce created" do
|
29
|
+
let(:body) { fixture('gists/gist.json') }
|
30
|
+
let(:status) { 201 }
|
31
|
+
|
32
|
+
it "should fail to create resource if 'files' input is missing" do
|
33
|
+
expect {
|
34
|
+
subject.create inputs.except('files')
|
35
|
+
}.to raise_error(Github::Error::RequiredParams)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fail to create resource if 'public' input is missing" do
|
39
|
+
expect {
|
40
|
+
subject.create inputs.except('public')
|
41
|
+
}.to raise_error(Github::Error::RequiredParams)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create resource successfully" do
|
45
|
+
subject.create inputs
|
46
|
+
a_post(request_path).with(inputs).should have_been_made
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return the resource" do
|
50
|
+
gist = subject.create inputs
|
51
|
+
gist.should be_a Hashie::Mash
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should get the gist information" do
|
55
|
+
gist = subject.create inputs
|
56
|
+
gist.user.login.should == 'octocat'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like 'request failure' do
|
61
|
+
let(:requestable) { subject.create inputs }
|
62
|
+
end
|
63
|
+
|
64
|
+
end # create
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#delete' do
|
6
|
+
let(:gist_id) { 1 }
|
7
|
+
let(:request_path) { "/gists/#{gist_id}" }
|
8
|
+
let(:body) { fixture('gists/gist.json') }
|
9
|
+
let(:status) { 204 }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_delete(request_path).to_return(:body => body, :status => status,
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
}
|
15
|
+
|
16
|
+
after { reset_authentication_for(subject) }
|
17
|
+
|
18
|
+
it 'should raise error if gist id not present' do
|
19
|
+
expect { subject.delete nil }.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should remove resource successfully" do
|
23
|
+
subject.delete gist_id
|
24
|
+
a_delete(request_path).should have_been_made
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_behave_like 'request failure' do
|
28
|
+
let(:requestable) { subject.delete gist_id }
|
29
|
+
end
|
30
|
+
|
31
|
+
end # delete
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#edit' do
|
6
|
+
let(:gist_id) { 1 }
|
7
|
+
let(:request_path) { "/gists/#{gist_id}" }
|
8
|
+
|
9
|
+
let(:inputs) {
|
10
|
+
{
|
11
|
+
"description" => "the description for this gist",
|
12
|
+
"files" => {
|
13
|
+
"file1.txt" => {
|
14
|
+
"content" => "updated file contents"
|
15
|
+
},
|
16
|
+
"old_name.txt" => {
|
17
|
+
"filename" => "new_name.txt",
|
18
|
+
"content" => "modified contents"
|
19
|
+
},
|
20
|
+
"new_file.txt" => {
|
21
|
+
"content" => "a new file"
|
22
|
+
},
|
23
|
+
"delete_this_file.txt" => nil
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
before {
|
29
|
+
stub_patch(request_path).with(inputs).
|
30
|
+
to_return(:body => body, :status => status,
|
31
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
}
|
33
|
+
|
34
|
+
after { reset_authentication_for(subject) }
|
35
|
+
|
36
|
+
context "resouce edited" do
|
37
|
+
let(:body) { fixture('gists/gist.json') }
|
38
|
+
let(:status) { 200 }
|
39
|
+
|
40
|
+
it "should edit resource successfully" do
|
41
|
+
subject.edit gist_id, inputs
|
42
|
+
a_patch(request_path).with(inputs).should have_been_made
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the resource" do
|
46
|
+
gist = subject.edit gist_id, inputs
|
47
|
+
gist.should be_a Hashie::Mash
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should get the gist information" do
|
51
|
+
gist = subject.edit gist_id, inputs
|
52
|
+
gist.user.login.should == 'octocat'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like 'request failure' do
|
57
|
+
let(:requestable) { subject.edit gist_id, inputs }
|
58
|
+
end
|
59
|
+
|
60
|
+
end # edit
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#star' do
|
6
|
+
let(:gist_id) { 1 }
|
7
|
+
let(:request_path) { "/gists/#{gist_id}/fork" }
|
8
|
+
let(:body) { fixture('gists/gist.json') }
|
9
|
+
let(:status) { 201 }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_post(request_path).to_return(:body => body, :status => status,
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
}
|
15
|
+
|
16
|
+
after { reset_authentication_for(subject) }
|
17
|
+
|
18
|
+
it "should fail to fork gist without gist id" do
|
19
|
+
expect { subject.fork(nil) }.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should fork resource successfully" do
|
23
|
+
subject.fork gist_id
|
24
|
+
a_post(request_path).should have_been_made
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the resource" do
|
28
|
+
gist = subject.fork gist_id
|
29
|
+
gist.should be_a Hashie::Mash
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get the gist information" do
|
33
|
+
gist = subject.fork gist_id
|
34
|
+
gist.user.login.should == 'octocat'
|
35
|
+
end
|
36
|
+
|
37
|
+
it_should_behave_like 'request failure' do
|
38
|
+
let(:requestable) { subject.fork gist_id }
|
39
|
+
end
|
40
|
+
|
41
|
+
end # fork
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#get' do
|
6
|
+
let(:gist_id) { 1 }
|
7
|
+
let(:request_path) { "/gists/#{gist_id}" }
|
8
|
+
|
9
|
+
before {
|
10
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
11
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
}
|
13
|
+
|
14
|
+
after { reset_authentication_for(subject) }
|
15
|
+
|
16
|
+
context "resource found" do
|
17
|
+
let(:body) { fixture('gists/gist.json') }
|
18
|
+
let(:status) { 200 }
|
19
|
+
|
20
|
+
it { should respond_to :find }
|
21
|
+
|
22
|
+
it "should fail to get resource without gist id" do
|
23
|
+
expect { subject.get nil }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get the resource" do
|
27
|
+
subject.get gist_id
|
28
|
+
a_get(request_path).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get gist information" do
|
32
|
+
gist = subject.get gist_id
|
33
|
+
gist.id.to_i.should eq gist_id
|
34
|
+
gist.user.login.should == 'octocat'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return mash" do
|
38
|
+
gist = subject.get gist_id
|
39
|
+
gist.should be_a Hashie::Mash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should_behave_like 'request failure' do
|
44
|
+
let(:requestable) { subject.get gist_id }
|
45
|
+
end
|
46
|
+
|
47
|
+
end # get
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Gists, '#unstar' do
|
6
|
+
let(:gist_id) { 1 }
|
7
|
+
let(:request_path) { "/gists/#{gist_id}/star" }
|
8
|
+
let(:body) { '' }
|
9
|
+
let(:status) { 204 }
|
10
|
+
|
11
|
+
before {
|
12
|
+
stub_get(request_path).to_return(:body => body, :status => status,
|
13
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
}
|
15
|
+
|
16
|
+
after { reset_authentication_for(subject) }
|
17
|
+
|
18
|
+
context 'when gist is starred' do
|
19
|
+
let(:status) { 204 }
|
20
|
+
|
21
|
+
it 'should raise error if gist id not present' do
|
22
|
+
expect { subject.starred? nil }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should perform request' do
|
26
|
+
subject.starred? gist_id
|
27
|
+
a_get(request_path).should have_been_made
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return true if gist is already starred' do
|
31
|
+
subject.starred?(gist_id).should be_true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when gist is not starred' do
|
36
|
+
let(:status) { 404 }
|
37
|
+
|
38
|
+
it 'should return false if gist is not starred' do
|
39
|
+
subject.starred?(gist_id).should be_false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end # starred?
|