Skip to content

Commit e19e169

Browse files
committed
Merge branch 'feature/api-v2-users' into develop
2 parents 3d8755a + f707d63 commit e19e169

File tree

4 files changed

+154
-4
lines changed

4 files changed

+154
-4
lines changed

docs/Home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A simple PHP wrapper for Bitbucket API.
2727
* [Teams](teams.md) (API 2.0)
2828
* [User](user.md)
2929
* [Repositories](user/repositories.md)
30-
* [Users](users.md)
30+
* [Users](users.md) (API 2.0)
3131
* [Account](users/account.md)
3232
* [Emails](users/emails.md)
3333
* [Invitations](users/invitations.md)

docs/users.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@ Get information related to an individual or team account.
55

66
### Prepare:
77
```php
8-
$users = new Bitbucket\API\Users();
9-
$users->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
8+
$user = new Bitbucket\API\Users();
9+
$user->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
10+
```
11+
12+
### Get the public information associated with a user: (API 2.0)
13+
```php
14+
$user->get($username);
15+
```
16+
17+
### Get the list of followers: (API 2.0)
18+
```php
19+
$user->followers($username);
20+
```
21+
22+
### Get a list of accounts the user is following: (API 2.0)
23+
```php
24+
$user->following($username);
25+
```
26+
27+
### Get the list of the user's repositories: (API 2.0)
28+
```php
29+
$user->repositories($username);
1030
```
1131

1232
----

lib/Bitbucket/API/Users.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Bitbucket\API;
1313

14+
use Buzz\Message\MessageInterface;
15+
1416
/**
1517
* Get information related to an individual or team account.
1618
* NOTE: For making calls against the currently authenticated account, see the `User` resource.
@@ -19,6 +21,62 @@
1921
*/
2022
class Users extends Api
2123
{
24+
/**
25+
* Get the public information associated with a user
26+
*
27+
* @access public
28+
* @param string $username
29+
* @return MessageInterface
30+
*/
31+
public function get($username)
32+
{
33+
return $this->getClient()->setApiVersion('2.0')->get(
34+
sprintf('users/%s', $username)
35+
);
36+
}
37+
38+
/**
39+
* Get the list of followers.
40+
*
41+
* @access public
42+
* @param string $username
43+
* @return MessageInterface
44+
*/
45+
public function followers($username)
46+
{
47+
return $this->getClient()->setApiVersion('2.0')->get(
48+
sprintf('users/%s/followers', $username)
49+
);
50+
}
51+
52+
/**
53+
* Get a list of accounts the user is following
54+
*
55+
* @access public
56+
* @param string $username
57+
* @return MessageInterface
58+
*/
59+
public function following($username)
60+
{
61+
return $this->getClient()->setApiVersion('2.0')->get(
62+
sprintf('users/%s/following', $username)
63+
);
64+
}
65+
66+
/**
67+
* Get the list of the user's repositories
68+
*
69+
* @access public
70+
* @param string $username
71+
* @return MessageInterface
72+
*/
73+
public function repositories($username)
74+
{
75+
return $this->getClient()->setApiVersion('2.0')->get(
76+
sprintf('repositories/%s', $username)
77+
);
78+
}
79+
2280
/**
2381
* Get account
2482
*

test/Bitbucket/Tests/API/UsersTest.php

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,78 @@ public function setUp()
2020
);
2121
}
2222

23+
public function testGetUserPublicInformation()
24+
{
25+
$endpoint = 'users/john-doe';
26+
$expectedResult = $this->fakeResponse(array('dummy'));
27+
28+
$client = $this->getHttpClientMock();
29+
$client->expects($this->once())
30+
->method('get')
31+
->with($endpoint)
32+
->will($this->returnValue($expectedResult));
33+
34+
/** @var \Bitbucket\API\Users $user */
35+
$user = $this->getClassMock('Bitbucket\API\Users', $client);
36+
$actual = $user->get('john-doe');
37+
38+
$this->assertEquals($expectedResult, $actual);
39+
}
40+
41+
public function testGetUserFollowers()
42+
{
43+
$endpoint = 'users/john-doe/followers';
44+
$expectedResult = $this->fakeResponse(array('dummy'));
45+
46+
$client = $this->getHttpClientMock();
47+
$client->expects($this->once())
48+
->method('get')
49+
->with($endpoint)
50+
->will($this->returnValue($expectedResult));
51+
52+
/** @var \Bitbucket\API\Users $user */
53+
$user = $this->getClassMock('Bitbucket\API\Users', $client);
54+
$actual = $user->followers('john-doe');
55+
56+
$this->assertEquals($expectedResult, $actual);
57+
}
58+
59+
public function testGetUserFollowing()
60+
{
61+
$endpoint = 'users/john-doe/following';
62+
$expectedResult = $this->fakeResponse(array('dummy'));
63+
64+
$client = $this->getHttpClientMock();
65+
$client->expects($this->once())
66+
->method('get')
67+
->with($endpoint)
68+
->will($this->returnValue($expectedResult));
69+
70+
/** @var \Bitbucket\API\Users $user */
71+
$user = $this->getClassMock('Bitbucket\API\Users', $client);
72+
$actual = $user->following('john-doe');
73+
74+
$this->assertEquals($expectedResult, $actual);
75+
}
76+
77+
public function testGetUserRepositories()
78+
{
79+
$endpoint = 'repositories/john-doe';
80+
$expectedResult = $this->fakeResponse(array('dummy'));
81+
82+
$client = $this->getHttpClientMock();
83+
$client->expects($this->once())
84+
->method('get')
85+
->with($endpoint)
86+
->will($this->returnValue($expectedResult));
87+
88+
/** @var \Bitbucket\API\Users $user */
89+
$user = $this->getClassMock('Bitbucket\API\Users', $client);
90+
$actual = $user->repositories('john-doe');
91+
92+
$this->assertEquals($expectedResult, $actual);
93+
}
94+
2395
public function testGetAccountInstance()
2496
{
2597
$this->assertInstanceOf('\Bitbucket\API\Users\Account', $this->users->account());
@@ -49,4 +121,4 @@ public function testGetSshKeysInstance()
49121
{
50122
$this->assertInstanceOf('\Bitbucket\API\Users\SshKeys', $this->users->sshKeys());
51123
}
52-
}
124+
}

0 commit comments

Comments
 (0)