Skip to content

Commit

Permalink
Merge pull request KnpLabs#449 from acrobat/api-projects
Browse files Browse the repository at this point in the history
Added support for the projects api
  • Loading branch information
cursedcoder authored Oct 19, 2016
2 parents 862c23d + 55a6a78 commit 6b2d292
Show file tree
Hide file tree
Showing 11 changed files with 755 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ APIs:
* [Repositories](repos.md)
* [Contents](repo/contents.md)
* [Deployments](repo/deployments.md)
* [Projects](repo/projects.md)
* [Columns](repo/columns.md)
* [Cards](repo/cards.md)
* [Releases](repo/releases.md)
* [Assets](repo/assets.md)
* [Stargazers](repo/stargazers.md)
Expand Down
53 changes: 53 additions & 0 deletions doc/repo/cards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Repo / Cards API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)

This api is currently only available to developers in Early Access. To access the API during the Early Access period,
you must provide a custom media type in the Accept header.

```php
$client->api('repo')->projects()->columns()->cards()->configure();
```

### List all cards of a column

```php
$cards = $client->api('repo')->projects()->columns()->cards()->all('twbs', 'bootstrap', $columnId);
```

### List one card

```php
$card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'bootstrap', $cardId);
```

### Create a card

> Requires [authentication](../security.md).
```php
$card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bootstrap', $columnId, array('content_type' => 'Issue', 'content_id' => '452'));
```

### Edit a card

> Requires [authentication](../security.md).
```php
$card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'bootstrap', $cardId, array('note' => 'card note'));
```

### Remove a card

> Requires [authentication](../security.md).
```php
$card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', 'bootstrap', $cardId);
```

### Move a card

> Requires [authentication](../security.md).
```php
$card = $client->api('repo')->projects()->columns()->cards()->move('twbs', 'bootstrap', $cardId, array('position' => 'top));
```
53 changes: 53 additions & 0 deletions doc/repo/columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Repo / Columns API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)

This api is currently only available to developers in Early Access. To access the API during the Early Access period,
you must provide a custom media type in the Accept header.

```php
$client->api('repo')->projects()->columns()->configure();
```

### List all columns of a project

```php
$columns = $client->api('repo')->projects()->columns()->all('twbs', 'bootstrap', $projectId);
```

### List one column

```php
$column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', $columnId);
```

### Create a column

> Requires [authentication](../security.md).
```php
$column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap', $projectId, array('name' => 'Column name'));
```

### Edit a column

> Requires [authentication](../security.md).
```php
$column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap', $columnId, array('name' => 'New name'));
```

### Remove a column

> Requires [authentication](../security.md).
```php
$column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'bootstrap', $columnId);
```

### Move a column

> Requires [authentication](../security.md).
```php
$column = $client->api('repo')->projects()->columns()->move('twbs', 'bootstrap', $columnId, array('position' => 'first));
```
45 changes: 45 additions & 0 deletions doc/repo/projects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Repo / Projects API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)

This api is currently only available to developers in Early Access. To access the API during the Early Access period,
you must provide a custom media type in the Accept header.

```php
$client->api('repo')->projects()->configure();
```

### List all projects

```php
$projects = $client->api('repo')->projects()->all('twbs', 'bootstrap');
```

### List one project

```php
$project = $client->api('repo')->projects()->show('twbs', 'bootstrap', $projectId);
```

### Create a project

> Requires [authentication](../security.md).
```php
$project = $client->api('repo')->projects()->create('twbs', 'bootstrap', array('name' => 'Project name'));
```

### Edit a project

> Requires [authentication](../security.md).
```php
$project = $client->api('repo')->project()->update('twbs', 'bootstrap', $projectId, array('name' => 'New name'));
```

### Remove a project

> Requires [authentication](../security.md).
```php
$project = $client->api('repo')->projects()->deleteProject('twbs', 'bootstrap', $projectId);
```
6 changes: 6 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Github\Api\Repository\Contents;
use Github\Api\Repository\DeployKeys;
use Github\Api\Repository\Downloads;
use Github\Api\Repository\Projects;
use Github\Api\Repository\Releases;
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
Expand Down Expand Up @@ -510,4 +511,9 @@ public function milestones($username, $repository)
{
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones');
}

public function projects()
{
return new Projects($this->client);
}
}
56 changes: 56 additions & 0 deletions lib/Github/Api/Repository/Cards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;

class Cards extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Configure the accept header for Early Access to the projects api
*
* @see https://developer.github.com/v3/repos/projects/#projects
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
}

public function all($username, $repository, $columnId, array $params = array())
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params));
}

public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id));
}

public function create($username, $repository, $columnId, array $params)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', $params);
}

public function update($username, $repository, $id, array $params)
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id), $params);
}

public function deleteCard($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id));
}

public function move($username, $repository, $id, array $params)
{
if (!isset($params['position'])) {
throw new MissingArgumentException(array('position'));
}

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id) . '/moves', $params);
}
}
69 changes: 69 additions & 0 deletions lib/Github/Api/Repository/Columns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;

class Columns extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Configure the accept header for Early Access to the projects api
*
* @see https://developer.github.com/v3/repos/projects/#projects
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
}

public function all($username, $repository, $projectId, array $params = array())
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params));
}

public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id));
}

public function create($username, $repository, $projectId, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(array('name'));
}

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', $params);
}

public function update($username, $repository, $id, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(array('name'));
}

return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id), $params);
}

public function deleteColumn($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id));
}

public function move($username, $repository, $id, array $params)
{
if (!isset($params['position'])) {
throw new MissingArgumentException(array('position'));
}

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id) . '/moves', $params);
}

public function cards()
{
return new Cards($this->client);
}
}
56 changes: 56 additions & 0 deletions lib/Github/Api/Repository/Projects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;

class Projects extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Configure the accept header for Early Access to the projects api
*
* @see https://developer.github.com/v3/repos/projects/#projects
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
}

public function all($username, $repository, array $params = array())
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(array('page' => 1), $params));
}

public function show($username, $repository, $id, array $params = array())
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params));
}

public function create($username, $repository, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(array('name'));
}

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params);
}

public function update($username, $repository, $id, array $params)
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id), $params);
}

public function deleteProject($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id));
}

public function columns()
{
return new Columns($this->client);
}
}
Loading

0 comments on commit 6b2d292

Please sign in to comment.