Skip to content

Commit 3eec9e7

Browse files
committed
fix current version break
1 parent 3fdd771 commit 3eec9e7

File tree

6 files changed

+159
-10
lines changed

6 files changed

+159
-10
lines changed

doc/activity.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Returns an array of watched repos.
2727
### Get repos that a authenticated user has starred
2828

2929
```php
30-
$activity = $client->api('current_user')->starred()->all();
30+
$activity = $client->api('current_user')->starring()->all();
3131
```
3232
Returns an array of starred repos.
3333

@@ -36,7 +36,7 @@ Returns an array of starred repos.
3636
```php
3737
$owner = "KnpLabs";
3838
$repo = "php-github-api";
39-
$activity = $client->api('current_user')->starred()->check($owner, $repo);
39+
$activity = $client->api('current_user')->starring()->check($owner, $repo);
4040
```
4141
Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user.
4242

@@ -45,7 +45,7 @@ Throws an Exception with code 404 in case that the repo is not starred by the au
4545
```php
4646
$owner = "KnpLabs";
4747
$repo = "php-github-api";
48-
$activity = $client->api('current_user')->starred()->star($owner, $repo);
48+
$activity = $client->api('current_user')->starring()->star($owner, $repo);
4949
```
5050
Throws an Exception in case of failure or NULL in case of success.
5151

@@ -54,7 +54,7 @@ Throws an Exception in case of failure or NULL in case of success.
5454
```php
5555
$owner = "KnpLabs";
5656
$repo = "php-github-api";
57-
$activity = $client->api('current_user')->starred()->unstar($owner, $repo);
57+
$activity = $client->api('current_user')->starring()->unstar($owner, $repo);
5858
```
5959
Throws an Exception in case of failure or NULL in case of success.
6060

doc/users.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ For authenticated user use.
136136
> Requires [authentication](security.md).
137137
138138
```php
139-
$users = $client->api('current_user')->starred()->all();
139+
$users = $client->api('current_user')->starring()->all();
140140
```
141141

142142
Returns an array of starred repos.

lib/Github/Api/CurrentUser.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Github\Api\CurrentUser\Followers;
88
use Github\Api\CurrentUser\Notifications;
99
use Github\Api\CurrentUser\Watchers;
10-
use Github\Api\CurrentUser\Starred;
10+
use Github\Api\CurrentUser\Starring;
1111

1212
/**
1313
* @link http://developer.github.com/v3/users/
@@ -123,12 +123,22 @@ public function watched($page = 1)
123123
'page' => $page
124124
));
125125
}
126+
127+
/**
128+
* @return Starring
129+
*/
130+
public function starring()
131+
{
132+
return new Starring($this->client);
133+
}
126134

127135
/**
128-
* @return Starred
136+
* @Deprecated
129137
*/
130-
public function starred()
138+
public function starred($page = 1)
131139
{
132-
return new Starred($this->client);
140+
return $this->get('user/starred', array(
141+
'page' => $page
142+
));
133143
}
134144
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Github\Api\CurrentUser;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://developer.github.com/v3/activity/starring/
9+
* @author Felipe Valtl de Mello <eu@felipe.im>
10+
*/
11+
class Starring extends AbstractApi
12+
{
13+
/**
14+
* List repositories starred by the authenticated user
15+
* @link https://developer.github.com/v3/activity/starring/
16+
*
17+
* @param integer $page
18+
* @return array
19+
*/
20+
public function all($page = 1)
21+
{
22+
return $this->get('user/starred', array(
23+
'page' => $page
24+
));
25+
}
26+
27+
/**
28+
* Check that the authenticated user starres a repository
29+
* @link https://developer.github.com/v3/activity/starring/
30+
*
31+
* @param string $username the user who owns the repo
32+
* @param string $repository the name of the repo
33+
* @return array
34+
*/
35+
public function check($username, $repository)
36+
{
37+
return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
38+
}
39+
40+
/**
41+
* Make the authenticated user star a repository
42+
* @link https://developer.github.com/v3/activity/starring/
43+
*
44+
* @param string $username the user who owns the repo
45+
* @param string $repository the name of the repo
46+
* @return array
47+
*/
48+
public function star($username, $repository)
49+
{
50+
return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
51+
}
52+
53+
/**
54+
* Make the authenticated user unstar a repository
55+
* @link https://developer.github.com/v3/activity/starring
56+
*
57+
* @param string $username the user who owns the repo
58+
* @param string $repository the name of the repo
59+
* @return array
60+
*/
61+
public function unstar($username, $repository)
62+
{
63+
return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
64+
}
65+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class StarringTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldGetStarred()
13+
{
14+
$expectedValue = array(
15+
array('name' => 'l3l0/test'),
16+
array('name' => 'cordoval/test')
17+
);
18+
19+
$api = $this->getApiMock();
20+
$api->expects($this->once())
21+
->method('get')
22+
->with('user/starred')
23+
->will($this->returnValue($expectedValue));
24+
25+
$this->assertEquals($expectedValue, $api->all());
26+
}
27+
28+
/**
29+
* @test
30+
*/
31+
public function shouldCheckStar()
32+
{
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with('user/starred/l3l0/test')
37+
->will($this->returnValue(null));
38+
39+
$this->assertNull($api->check('l3l0', 'test'));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function shouldStarUser()
46+
{
47+
$api = $this->getApiMock();
48+
$api->expects($this->once())
49+
->method('put')
50+
->with('user/starred/l3l0/test')
51+
->will($this->returnValue(null));
52+
53+
$this->assertNull($api->star('l3l0', 'test'));
54+
}
55+
56+
/**
57+
* @test
58+
*/
59+
public function shouldUnstarUser()
60+
{
61+
$api = $this->getApiMock();
62+
$api->expects($this->once())
63+
->method('delete')
64+
->with('user/starred/l3l0/test')
65+
->will($this->returnValue(null));
66+
67+
$this->assertNull($api->unstar('l3l0', 'test'));
68+
}
69+
70+
protected function getApiClass()
71+
{
72+
return 'Github\Api\CurrentUser\Starring';
73+
}
74+
}

test/Github/Tests/Api/CurrentUserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function shouldGetStarredApiObject()
141141
{
142142
$api = $this->getApiMock();
143143

144-
$this->assertInstanceOf('Github\Api\CurrentUser\Starred', $api->starred());
144+
$this->assertInstanceOf('Github\Api\CurrentUser\Starring', $api->starring());
145145
}
146146

147147
protected function getApiClass()

0 commit comments

Comments
 (0)