Skip to content

Commit 38301cc

Browse files
j0k3rNyholm
authored andcommitted
Add ability to define parameters for /users/{user}/starred (#536)
* Add ability to define parameter for /users/{user}/starred Following the documentation (https://developer.github.com/v3/activity/starring/#list-repositories-being-starred) we can define few parameters to the request: - page (was already available in the lib) - per_page - sort - direction * Typo in annotation
1 parent 0feb076 commit 38301cc

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

lib/Github/Api/CurrentUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function teams()
112112
*
113113
* @param string $type role in the repository
114114
* @param string $sort sort by
115-
* @param string $direction direction of sort, ask or desc
115+
* @param string $direction direction of sort, asc or desc
116116
*
117117
* @return array
118118
*/

lib/Github/Api/User.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,21 @@ public function watched($username)
129129
*
130130
* @link http://developer.github.com/v3/activity/starring/
131131
*
132-
* @param string $username the username
133-
* @param int $page the page number of the paginated result set
132+
* @param string $username the username
133+
* @param int $page the page number of the paginated result set
134+
* @param int $perPage the number of results per page
135+
* @param string $sort sort by (possible values: created, updated)
136+
* @param string $direction direction of sort (possible values: asc, desc)
134137
*
135138
* @return array list of starred repositories
136139
*/
137-
public function starred($username, $page = 1)
140+
public function starred($username, $page = 1, $perPage = 30, $sort = 'created', $direction = 'desc')
138141
{
139142
return $this->get('/users/'.rawurlencode($username).'/starred', array(
140-
'page' => $page
143+
'page' => $page,
144+
'per_page' => $perPage,
145+
'sort' => $sort,
146+
'direction' => $direction,
141147
));
142148
}
143149

test/Github/Tests/Api/UserTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function shouldGetUserOrganizations()
4242

4343
$this->assertEquals($expectedArray, $api->organizations('l3l0'));
4444
}
45+
4546
public function shouldGetUserOrgs()
4647
{
4748
$expectedArray = array(array(
@@ -61,6 +62,7 @@ public function shouldGetUserOrgs()
6162

6263
$this->assertEquals($expectedArray, $api->orgs());
6364
}
65+
6466
/**
6567
* @test
6668
*/
@@ -131,6 +133,22 @@ public function shouldGetUserFollowers()
131133
$this->assertEquals($expectedArray, $api->followers('l3l0'));
132134
}
133135

136+
/**
137+
* @test
138+
*/
139+
public function shouldGetStarredToRepositories()
140+
{
141+
$expectedArray = array(array('id' => 1, 'name' => 'l3l0repo'));
142+
143+
$api = $this->getApiMock();
144+
$api->expects($this->once())
145+
->method('get')
146+
->with('/users/l3l0/starred', ['page' => 2, 'per_page' => 30, 'sort' => 'created', 'direction' => 'desc'])
147+
->will($this->returnValue($expectedArray));
148+
149+
$this->assertEquals($expectedArray, $api->starred('l3l0', 2));
150+
}
151+
134152
/**
135153
* @test
136154
*/

0 commit comments

Comments
 (0)