File tree Expand file tree Collapse file tree 4 files changed +104
-0
lines changed Expand file tree Collapse file tree 4 files changed +104
-0
lines changed Original file line number Diff line number Diff line change 12
12
use Github \Api \Repository \Forks ;
13
13
use Github \Api \Repository \Hooks ;
14
14
use Github \Api \Repository \Labels ;
15
+ use Github \Api \Repository \Stargazers ;
15
16
use Github \Api \Repository \Statuses ;
16
17
17
18
/**
@@ -309,6 +310,18 @@ public function forks()
309
310
return new Forks ($ this ->client );
310
311
}
311
312
313
+ /**
314
+ * Manage the stargazers of a repository.
315
+ *
316
+ * @link https://developer.github.com/v3/activity/starring/#list-stargazers
317
+ *
318
+ * @return Stargazers
319
+ */
320
+ public function stargazers ()
321
+ {
322
+ return new Stargazers ($ this ->client );
323
+ }
324
+
312
325
/**
313
326
* Manage the hooks of a repository.
314
327
*
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Github \Api \Repository ;
4
+
5
+ use Github \Api \AbstractApi ;
6
+
7
+ /**
8
+ * @link https://developer.github.com/v3/activity/starring/#list-stargazers
9
+ * @author Nicolas Dupont <[email protected] >
10
+ */
11
+ class Stargazers extends AbstractApi
12
+ {
13
+ /**
14
+ * Configure the body type
15
+ *
16
+ * @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
17
+ *
18
+ * @param string $bodyType
19
+ */
20
+ public function configure ($ bodyType = null )
21
+ {
22
+ if ('star ' === $ bodyType ) {
23
+ $ this ->client ->setHeaders (
24
+ array (
25
+ 'Accept ' => sprintf ('application/vnd.github.%s.star+json ' , $ this ->client ->getOption ('api_version ' ))
26
+ )
27
+ );
28
+ }
29
+ }
30
+
31
+ public function all ($ username , $ repository )
32
+ {
33
+ return $ this ->get ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/stargazers ' );
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -465,6 +465,16 @@ public function shouldGetStatusesApiObject()
465
465
$ this ->assertInstanceOf ('Github\Api\Repository\Statuses ' , $ api ->statuses ());
466
466
}
467
467
468
+ /**
469
+ * @test
470
+ */
471
+ public function shouldGetStargazersApiObject ()
472
+ {
473
+ $ api = $ this ->getApiMock ();
474
+
475
+ $ this ->assertInstanceOf ('Github\Api\Repository\Stargazers ' , $ api ->stargazers ());
476
+ }
477
+
468
478
/**
469
479
* @test
470
480
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Github \Tests \Api \Repository ;
4
+
5
+ use Github \Tests \Api \TestCase ;
6
+
7
+ class StargazersTest extends TestCase
8
+ {
9
+ /**
10
+ * @test
11
+ */
12
+ public function shouldGetAllRepositoryStargazers ()
13
+ {
14
+ $ expectedValue = array (array ('login ' => 'nidup ' ));
15
+
16
+ $ api = $ this ->getApiMock ();
17
+ $ api ->expects ($ this ->once ())
18
+ ->method ('get ' )
19
+ ->with ('repos/KnpLabs/php-github-api/stargazers ' )
20
+ ->will ($ this ->returnValue ($ expectedValue ));
21
+
22
+ $ this ->assertEquals ($ expectedValue , $ api ->all ('KnpLabs ' , 'php-github-api ' ));
23
+ }
24
+
25
+ /**
26
+ * @test
27
+ */
28
+ public function shouldGetAllRepositoryStargazersWithAlternativeResponse ()
29
+ {
30
+ $ expectedValue = array (array ('starred_at ' => '2013-10-01T13:22:01Z ' , 'user ' => array ('login ' => 'nidup ' )));
31
+
32
+ $ api = $ this ->getApiMock ();
33
+ $ api ->expects ($ this ->once ())
34
+ ->method ('get ' )
35
+ ->with ('repos/KnpLabs/php-github-api/stargazers ' )
36
+ ->will ($ this ->returnValue ($ expectedValue ));
37
+ $ api ->configure ('star ' );
38
+
39
+ $ this ->assertEquals ($ expectedValue , $ api ->all ('KnpLabs ' , 'php-github-api ' ));
40
+ }
41
+
42
+ protected function getApiClass ()
43
+ {
44
+ return 'Github\Api\Repository\Stargazers ' ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments