Skip to content

Commit ac67ff0

Browse files
drobeeacrobat
authored andcommitted
Added support for Miscellaneous Licenses (#744)
* Added support for Miscellaneous Licenses * Class fix
1 parent c9c742f commit ac67ff0

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ v3 APIs:
3434
* [Code of conduct](miscellaneous/codeofconduct.md)
3535
* [Emojis](miscellaneous/emojis.md)
3636
* [Gitignore](miscellaneous/gitignore.md)
37+
* [Licenses](miscellaneous/licenses.md)
3738
* [Markdown](miscellaneous/markdown.md)
3839
* [Organization](organization.md)
3940
* [Members](organization/members.md)

doc/miscellaneous/licenses.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Licenses API
2+
[Back to the navigation](../README.md)
3+
4+
### Lists all licenses.
5+
6+
```php
7+
$licenses = $client->api('licenses')->all();
8+
```
9+
10+
### Get a license.
11+
12+
```php
13+
$license = $client->api('licenses')->show('gpl-2.0');
14+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Github\Api\Miscellaneous;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class Licenses extends AbstractApi
8+
{
9+
/**
10+
* Lists all the licenses available on GitHub.
11+
*
12+
* @link https://developer.github.com/v3/licenses/
13+
*
14+
* @return array
15+
*/
16+
public function all()
17+
{
18+
return $this->get('/licenses');
19+
}
20+
21+
/**
22+
* Get an individual license by its license key.
23+
*
24+
* @link https://developer.github.com/v3/licenses/#get-an-individual-license
25+
*
26+
* @param string $license
27+
*
28+
* @return array
29+
*/
30+
public function show($license)
31+
{
32+
return $this->get('/licenses/'.rawurlencode($license));
33+
}
34+
}

lib/Github/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @method Api\Enterprise enterprise()
2626
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
2727
* @method Api\Miscellaneous\Emojis emojis()
28+
* @method Api\Miscellaneous\Licenses licenses()
2829
* @method Api\GitData git()
2930
* @method Api\GitData gitData()
3031
* @method Api\Gists gist()
@@ -221,6 +222,10 @@ public function api($name)
221222
$api = new Api\Markdown($this);
222223
break;
223224

225+
case 'licenses':
226+
$api = new Api\Miscellaneous\Licenses($this);
227+
break;
228+
224229
case 'notification':
225230
case 'notifications':
226231
$api = new Api\Notification($this);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Miscellaneous;
4+
5+
use Github\Api\Miscellaneous\Licenses;
6+
use Github\Tests\Api\TestCase;
7+
8+
class LicensesTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
public function shouldGetAllLicenses()
14+
{
15+
$expectedArray = [
16+
['key' => 'mit'],
17+
['key' => 'apache-2.0'],
18+
];
19+
20+
$api = $this->getApiMock();
21+
$api->expects($this->once())
22+
->method('get')
23+
->with('/licenses')
24+
->will($this->returnValue($expectedArray));
25+
26+
$this->assertEquals($expectedArray, $api->all());
27+
}
28+
29+
/**
30+
* @test
31+
*/
32+
public function shouldGetSingleLicenses()
33+
{
34+
$expectedArray = [
35+
'key' => 'gpl-2.0',
36+
];
37+
38+
$api = $this->getApiMock();
39+
$api->expects($this->once())
40+
->method('get')
41+
->with('/licenses/gpl-2.0')
42+
->will($this->returnValue($expectedArray));
43+
44+
$this->assertEquals($expectedArray, $api->show('gpl-2.0'));
45+
}
46+
47+
/**
48+
* @return string
49+
*/
50+
protected function getApiClass()
51+
{
52+
return Licenses::class;
53+
}
54+
}

0 commit comments

Comments
 (0)