Skip to content

Commit 6ee8ad8

Browse files
committed
Merge pull request KnpLabs#152 from KnpLabs/add-userapi-organizations-call
added User::organizations, to be able fetch user's organizations
2 parents a462c35 + 2c7ce8c commit 6ee8ad8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/Github/Api/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ public function show($username)
5151
return $this->get('users/'.rawurlencode($username));
5252
}
5353

54+
/**
55+
* Get extended information about a user by its username
56+
* @link https://developer.github.com/v3/orgs/
57+
*
58+
* @param string $username the username to show
59+
* @return array information about organizations that user belongs to
60+
*/
61+
public function organizations($username)
62+
{
63+
return $this->get('users/'.rawurlencode($username).'/orgs');
64+
}
65+
5466
/**
5567
* Request the users that a specific user is following
5668
* @link http://developer.github.com/v3/users/followers/

test/Github/Tests/Api/UserTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ public function shouldShowUser()
2020
$this->assertEquals($expectedArray, $api->show('l3l0'));
2121
}
2222

23+
/**
24+
* @test
25+
*/
26+
public function shouldGetUserOrganizations()
27+
{
28+
$expectedArray = array(array(
29+
'id' => 202732,
30+
'url' => 'https://api.github.com/orgs/KnpLabs',
31+
'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos',
32+
'events_url' => 'https://api.github.com/orgs/KnpLabs/events',
33+
'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}',
34+
'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}'
35+
));
36+
37+
$api = $this->getApiMock();
38+
$api->expects($this->once())
39+
->method('get')
40+
->with('users/l3l0/orgs')
41+
->will($this->returnValue($expectedArray));
42+
43+
$this->assertEquals($expectedArray, $api->organizations('l3l0'));
44+
}
45+
2346
/**
2447
* @test
2548
*/

0 commit comments

Comments
 (0)