Skip to content

Commit

Permalink
Merge pull request #152 from KnpLabs/add-userapi-organizations-call
Browse files Browse the repository at this point in the history
added User::organizations, to be able fetch user's organizations
  • Loading branch information
cursedcoder committed Jul 1, 2014
2 parents a462c35 + 2c7ce8c commit 6ee8ad8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Github/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
23 changes: 23 additions & 0 deletions test/Github/Tests/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 6ee8ad8

Please sign in to comment.