diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 7573c6e2b98..bcbfc58f80e 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -51,6 +51,18 @@ public function show($username) return $this->get('users/'.rawurlencode($username)); } + /** + * Get extended information about a user by its username + * @link https://developer.github.com/v3/orgs/ + * + * @param string $username the username to show + * @return array information about organizations that user belongs to + */ + public function organizations($username) + { + return $this->get('users/'.rawurlencode($username).'/orgs'); + } + /** * Request the users that a specific user is following * @link http://developer.github.com/v3/users/followers/ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 05eb7061b0d..1bb0f959b52 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,29 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldGetUserOrganizations() + { + $expectedArray = array(array( + 'id' => 202732, + 'url' => 'https://api.github.com/orgs/KnpLabs', + 'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos', + 'events_url' => 'https://api.github.com/orgs/KnpLabs/events', + 'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}', + 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}' + )); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users/l3l0/orgs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->organizations('l3l0')); + } + /** * @test */