Skip to content

Commit b222a3a

Browse files
committed
Change parameter slurping for listing organizations.
1 parent e291467 commit b222a3a

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

lib/github_api/orgs.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,22 @@ def teams
3434
# List all public organizations for a user.
3535
#
3636
# = Examples
37-
# github = Github.new :user => 'user-name'
38-
# github.orgs.list
37+
# github = Github.new
38+
# github.orgs.list user: 'user-name'
3939
#
4040
# List public and private organizations for the authenticated user.
4141
#
42-
# github = Github.new :oauth_token => '..'
43-
# github.orgs.list 'github'
42+
# github = Github.new oauth_token: '..'
43+
# github.orgs.list
4444
#
45-
def list(user_name=nil, params={})
46-
_update_user_repo_params(user_name)
45+
def list(*args)
46+
params = args.extract_options!
4747
_normalize_params_keys(params)
4848

49-
response = if user?
50-
get_request("/users/#{user}/orgs", params)
49+
response = if (user_name = params.delete("user"))
50+
get_request("/users/#{user_name}/orgs", params)
5151
else
52+
# For the authenticated user
5253
get_request("/user/orgs", params)
5354
end
5455
return response unless block_given?

spec/github/orgs_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@
2424
end
2525

2626
it "should get the resources" do
27-
github.orgs.list user
27+
github.orgs.list :user => user
2828
a_get("/users/#{user}/orgs").should have_been_made
2929
end
3030

3131
it "should return array of resources" do
32-
orgs = github.orgs.list user
32+
orgs = github.orgs.list :user => user
3333
orgs.should be_an Array
3434
orgs.should have(1).items
3535
end
3636

3737
it "should be a mash type" do
38-
orgs = github.orgs.list user
38+
orgs = github.orgs.list :user => user
3939
orgs.first.should be_a Hashie::Mash
4040
end
4141

4242
it "should get org information" do
43-
orgs = github.orgs.list user
43+
orgs = github.orgs.list :user => user
4444
orgs.first.login.should == 'github'
4545
end
4646

4747
it "should yield to a block" do
48-
github.orgs.should_receive(:list).with(user).and_yield('web')
49-
github.orgs.list(user) { |param| 'web' }
48+
github.orgs.should_receive(:list).with(:user => user).and_yield('web')
49+
github.orgs.list(:user => user) { |param| 'web' }
5050
end
5151
end
5252

@@ -76,7 +76,7 @@
7676

7777
it "should return 404 with a message 'Not Found'" do
7878
expect {
79-
github.orgs.list user
79+
github.orgs.list :user => user
8080
}.to raise_error(Github::Error::NotFound)
8181
end
8282
end

0 commit comments

Comments
 (0)