Skip to content

Integrations are now Apps! #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 23, 2017
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Navigation
==========

APIs:
* [Applications](apps.md)
* [Authorizations](authorizations.md)
* [Commits](commits.md)
* Current User
Expand All @@ -10,7 +11,6 @@ APIs:
* [Enterprise](enterprise.md)
* [Gists](gists.md)
* [Comments](gists/comments.md)
* [Integrations](integrations.md)
* [Issues](issues.md)
* [Assignees](issue/assignees.md)
* [Comments](issue/comments.md)
Expand Down
18 changes: 9 additions & 9 deletions doc/integrations.md → doc/apps.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
## Instegrations API
## Applications API
[Back to the navigation](README.md)

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

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

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

### Find all installations

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

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

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

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

### Remove repository from installation
Remove a single repository from an installation.
```php
$client->api('integrations')->removeRepository(123);
$client->api('apps')->removeRepository(123);
```
90 changes: 90 additions & 0 deletions lib/Github/Api/Apps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Github\Api;

/**
* @link https://developer.github.com/v3/apps/
* @author Nils Adermann <naderman@naderman.de>
*/
class Apps extends AbstractApi
{
/**
* Create an access token for an installation
*
* @param int $installationId An integration installation id
* @param int $userId An optional user id on behalf of whom the
* token will be requested
*
* @return array token and token metadata
*/
public function createInstallationToken($installationId, $userId = null)
{
$parameters = array();
if ($userId) {
$parameters['user_id'] = $userId;
}

return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
}

/**
* Find all installations for the authenticated application.
*
* @link https://developer.github.com/v3/apps/#find-installations
*
* @return array
*/
public function findInstallations()
{
return $this->get('/app/installations');
}

/**
* List repositories that are accessible to the authenticated installation.
*
* @link https://developer.github.com/v3/apps/installations/#list-repositories
*
* @param int $userId
*
* @return array
*/
public function listRepositories($userId = null)
{
$parameters = array();
if ($userId) {
$parameters['user_id'] = $userId;
}

return $this->get('/installation/repositories', $parameters);
}

/**
* Add a single repository to an installation.
*
* @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function addRepository($installationId, $repositoryId)
{
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}

/**
* Remove a single repository from an installation.
*
* @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function removeRepository($installationId, $repositoryId)
{
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
}
96 changes: 7 additions & 89 deletions lib/Github/Api/Integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,25 @@

namespace Github\Api;

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

/**
* @link https://developer.github.com/v3/integrations/
* @deprecated Use the Apps class
* @link https://developer.github.com/v3/apps/
* @author Nils Adermann <naderman@naderman.de>
*/
class Integrations extends AbstractApi
class Integrations extends Apps
{
use AcceptHeaderTrait;

/**
* Configure the accept header for Early Access to the integrations api
* @deprecated
* Configure the accept header for Early Access to the integrations api (DEPRECATED)
*
* @see https://developer.github.com/v3/integrations/
* @see https://developer.github.com/v3/apps/
*
* @return self
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json';

return $this;
}

/**
* Create an access token for an installation
*
* @param int $installationId An integration installation id
* @param int $userId An optional user id on behalf of whom the
* token will be requested
*
* @return array token and token metadata
*/
public function createInstallationToken($installationId, $userId = null)
{
$parameters = array();
if ($userId) {
$parameters['user_id'] = $userId;
}

return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
}

/**
* Find all installations for the authenticated integration.
*
* @link https://developer.github.com/v3/integrations/#find-installations
*
* @return array
*/
public function findInstallations()
{
return $this->get('/integration/installations');
}

/**
* List repositories that are accessible to the authenticated installation.
*
* @link https://developer.github.com/v3/integrations/installations/#list-repositories
*
* @param int $userId
*
* @return array
*/
public function listRepositories($userId = null)
{
$parameters = array();
if ($userId) {
$parameters['user_id'] = $userId;
}

return $this->get('/installation/repositories', $parameters);
}

/**
* Add a single repository to an installation.
*
* @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function addRepository($installationId, $repositoryId)
{
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}

/**
* Remove a single repository from an installation.
*
* @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function removeRepository($installationId, $repositoryId)
{
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
}
8 changes: 6 additions & 2 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
* @method Api\Gists gist()
* @method Api\Gists gists()
* @method Api\Miscellaneous\Gitignore gitignore()
* @method Api\Integrations integration()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could leave these comments.

Copy link
Collaborator

@acrobat acrobat May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed keep the old methods (to the deprecated class) so a user will know they have to change their code to the new methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @method Api\Integrations integrations()
* @method Api\Integrations integration() (deprecated)
* @method Api\Integrations integrations() (deprecated)
* @method Api\Apps apps()
* @method Api\Issue issue()
* @method Api\Issue issues()
* @method Api\Markdown markdown()
Expand Down Expand Up @@ -202,6 +203,9 @@ public function api($name)
case 'integrations':
$api = new Api\Integrations($this);
break;
case 'apps':
$api = new Api\Apps($this);
break;

case 'issue':
case 'issues':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Github\Tests\Api;

class IntegrationTest extends TestCase
class AppTest extends TestCase
{
/**
* @test
*/
public function shouldFindRepositoriesForIntegration()
public function shouldFindRepositoriesForApplication()
{
$result = ['installation1', 'installation2'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/integration/installations')
->with('/app/installations')
->willReturn($result);

$this->assertEquals($result, $api->findInstallations());
Expand Down Expand Up @@ -68,6 +68,6 @@ public function shouldRemoveRepositoryToInstallation()
*/
protected function getApiClass()
{
return \Github\Api\Integrations::class;
return \Github\Api\Apps::class;
}
}