Skip to content

Commit 1d56183

Browse files
authored
Merge pull request KnpLabs#592 from m1guelpf/patch-1
Integrations are now Apps!
2 parents 4a97e07 + bf113ef commit 1d56183

File tree

6 files changed

+117
-105
lines changed

6 files changed

+117
-105
lines changed

doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Navigation
22
==========
33

44
APIs:
5+
* [Applications](apps.md)
56
* [Authorizations](authorizations.md)
67
* [Commits](commits.md)
78
* Current User
@@ -10,7 +11,6 @@ APIs:
1011
* [Enterprise](enterprise.md)
1112
* [Gists](gists.md)
1213
* [Comments](gists/comments.md)
13-
* [Integrations](integrations.md)
1414
* [Issues](issues.md)
1515
* [Assignees](issue/assignees.md)
1616
* [Comments](issue/comments.md)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
## Instegrations API
1+
## Applications API
22
[Back to the navigation](README.md)
33

4-
Wraps [GitHub Integrations API](http://developer.github.com/v3/integrations/).
4+
Wraps [GitHub Applications API](http://developer.github.com/v3/apps/).
55

66
### Create a new installation token
77
For the installation id 123 use the following:
88
```php
9-
$token = $client->api('integrations')->createInstallationToken(123);
9+
$token = $client->api('apps')->createInstallationToken(123);
1010
```
1111

1212
To create an access token on behalf of a user with id 456 use:
1313
```php
14-
$token = $client->api('integrations')->createInstallationToken(123, 456);
14+
$token = $client->api('apps')->createInstallationToken(123, 456);
1515
```
1616

1717
### Find all installations
1818

19-
Find all installations for the authenticated integration.
19+
Find all installations for the authenticated application.
2020
```php
21-
$installations = $client->api('integrations')->findInstallations();
21+
$installations = $client->api('apps')->findInstallations();
2222
```
2323

2424
### Find installations for a user
@@ -31,7 +31,7 @@ $installations = $client->api('current_user')->installations();
3131

3232
List repositories that are accessible to the authenticated installation.
3333
```php
34-
$repositories = $client->api('integrations')->listRepositories(456);
34+
$repositories = $client->api('apps')->listRepositories(456);
3535
```
3636

3737
### List repositories for a given installation and user
@@ -43,11 +43,11 @@ $repositories = $client->api('current_user')->repositoriesByInstallation(456);
4343
### Add repository to installation
4444
Add a single repository to an installation.
4545
```php
46-
$client->api('integrations')->addRepository(123);
46+
$client->api('apps')->addRepository(123);
4747
```
4848

4949
### Remove repository from installation
5050
Remove a single repository from an installation.
5151
```php
52-
$client->api('integrations')->removeRepository(123);
52+
$client->api('apps')->removeRepository(123);
5353
```

lib/Github/Api/Apps.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Github\Api;
4+
5+
/**
6+
* @link https://developer.github.com/v3/apps/
7+
* @author Nils Adermann <naderman@naderman.de>
8+
*/
9+
class Apps extends AbstractApi
10+
{
11+
/**
12+
* Create an access token for an installation
13+
*
14+
* @param int $installationId An integration installation id
15+
* @param int $userId An optional user id on behalf of whom the
16+
* token will be requested
17+
*
18+
* @return array token and token metadata
19+
*/
20+
public function createInstallationToken($installationId, $userId = null)
21+
{
22+
$parameters = array();
23+
if ($userId) {
24+
$parameters['user_id'] = $userId;
25+
}
26+
27+
return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
28+
}
29+
30+
/**
31+
* Find all installations for the authenticated application.
32+
*
33+
* @link https://developer.github.com/v3/apps/#find-installations
34+
*
35+
* @return array
36+
*/
37+
public function findInstallations()
38+
{
39+
return $this->get('/app/installations');
40+
}
41+
42+
/**
43+
* List repositories that are accessible to the authenticated installation.
44+
*
45+
* @link https://developer.github.com/v3/apps/installations/#list-repositories
46+
*
47+
* @param int $userId
48+
*
49+
* @return array
50+
*/
51+
public function listRepositories($userId = null)
52+
{
53+
$parameters = array();
54+
if ($userId) {
55+
$parameters['user_id'] = $userId;
56+
}
57+
58+
return $this->get('/installation/repositories', $parameters);
59+
}
60+
61+
/**
62+
* Add a single repository to an installation.
63+
*
64+
* @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation
65+
*
66+
* @param int $installationId
67+
* @param int $repositoryId
68+
*
69+
* @return array
70+
*/
71+
public function addRepository($installationId, $repositoryId)
72+
{
73+
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
74+
}
75+
76+
/**
77+
* Remove a single repository from an installation.
78+
*
79+
* @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
80+
*
81+
* @param int $installationId
82+
* @param int $repositoryId
83+
*
84+
* @return array
85+
*/
86+
public function removeRepository($installationId, $repositoryId)
87+
{
88+
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
89+
}
90+
}

lib/Github/Api/Integrations.php

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,25 @@
22

33
namespace Github\Api;
44

5-
use Github\Api\AcceptHeaderTrait;
5+
@trigger_error('The '.__NAMESPACE__.'\Integrations class is deprecated. Use the '.__NAMESPACE__.'\Apps class instead.', E_USER_DEPRECATED);
66

77
/**
8-
* @link https://developer.github.com/v3/integrations/
8+
* @deprecated Use the Apps class
9+
* @link https://developer.github.com/v3/apps/
910
* @author Nils Adermann <naderman@naderman.de>
1011
*/
11-
class Integrations extends AbstractApi
12+
class Integrations extends Apps
1213
{
13-
use AcceptHeaderTrait;
14-
1514
/**
16-
* Configure the accept header for Early Access to the integrations api
15+
* @deprecated
16+
* Configure the accept header for Early Access to the integrations api (DEPRECATED)
1717
*
18-
* @see https://developer.github.com/v3/integrations/
18+
* @see https://developer.github.com/v3/apps/
1919
*
2020
* @return self
2121
*/
2222
public function configure()
2323
{
24-
$this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json';
25-
2624
return $this;
2725
}
28-
29-
/**
30-
* Create an access token for an installation
31-
*
32-
* @param int $installationId An integration installation id
33-
* @param int $userId An optional user id on behalf of whom the
34-
* token will be requested
35-
*
36-
* @return array token and token metadata
37-
*/
38-
public function createInstallationToken($installationId, $userId = null)
39-
{
40-
$parameters = array();
41-
if ($userId) {
42-
$parameters['user_id'] = $userId;
43-
}
44-
45-
return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
46-
}
47-
48-
/**
49-
* Find all installations for the authenticated integration.
50-
*
51-
* @link https://developer.github.com/v3/integrations/#find-installations
52-
*
53-
* @return array
54-
*/
55-
public function findInstallations()
56-
{
57-
return $this->get('/integration/installations');
58-
}
59-
60-
/**
61-
* List repositories that are accessible to the authenticated installation.
62-
*
63-
* @link https://developer.github.com/v3/integrations/installations/#list-repositories
64-
*
65-
* @param int $userId
66-
*
67-
* @return array
68-
*/
69-
public function listRepositories($userId = null)
70-
{
71-
$parameters = array();
72-
if ($userId) {
73-
$parameters['user_id'] = $userId;
74-
}
75-
76-
return $this->get('/installation/repositories', $parameters);
77-
}
78-
79-
/**
80-
* Add a single repository to an installation.
81-
*
82-
* @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation
83-
*
84-
* @param int $installationId
85-
* @param int $repositoryId
86-
*
87-
* @return array
88-
*/
89-
public function addRepository($installationId, $repositoryId)
90-
{
91-
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
92-
}
93-
94-
/**
95-
* Remove a single repository from an installation.
96-
*
97-
* @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation
98-
*
99-
* @param int $installationId
100-
* @param int $repositoryId
101-
*
102-
* @return array
103-
*/
104-
public function removeRepository($installationId, $repositoryId)
105-
{
106-
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
107-
}
10826
}

lib/Github/Client.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
* @method Api\Gists gist()
3030
* @method Api\Gists gists()
3131
* @method Api\Miscellaneous\Gitignore gitignore()
32-
* @method Api\Integrations integration()
33-
* @method Api\Integrations integrations()
32+
* @method Api\Integrations integration() (deprecated)
33+
* @method Api\Integrations integrations() (deprecated)
34+
* @method Api\Apps apps()
3435
* @method Api\Issue issue()
3536
* @method Api\Issue issues()
3637
* @method Api\Markdown markdown()
@@ -202,6 +203,9 @@ public function api($name)
202203
case 'integrations':
203204
$api = new Api\Integrations($this);
204205
break;
206+
case 'apps':
207+
$api = new Api\Apps($this);
208+
break;
205209

206210
case 'issue':
207211
case 'issues':

test/Github/Tests/Api/IntegrationTest.php renamed to test/Github/Tests/Api/AppTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
namespace Github\Tests\Api;
44

5-
class IntegrationTest extends TestCase
5+
class AppTest extends TestCase
66
{
77
/**
88
* @test
99
*/
10-
public function shouldFindRepositoriesForIntegration()
10+
public function shouldFindRepositoriesForApplication()
1111
{
1212
$result = ['installation1', 'installation2'];
1313

1414
$api = $this->getApiMock();
1515
$api->expects($this->once())
1616
->method('get')
17-
->with('/integration/installations')
17+
->with('/app/installations')
1818
->willReturn($result);
1919

2020
$this->assertEquals($result, $api->findInstallations());
@@ -68,6 +68,6 @@ public function shouldRemoveRepositoryToInstallation()
6868
*/
6969
protected function getApiClass()
7070
{
71-
return \Github\Api\Integrations::class;
71+
return \Github\Api\Apps::class;
7272
}
7373
}

0 commit comments

Comments
 (0)