Skip to content
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

added endpoint to get boards for organization #36

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/Api/Organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ Trello Organization API
$api->organizations()->show(string $id, array $params)
```

### Boards API
```php
$api->members()->boards()
```
7 changes: 7 additions & 0 deletions docs/Api/Organization/Boards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Trello Member Boards API
======================

### Get boads related to a given organization
```php
$api->organization()->boards()->all(string $id, array $params)
```
22 changes: 21 additions & 1 deletion lib/Trello/Api/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ class Organization extends AbstractApi
*/
public function show($id, array $params = array())
{
return $this->get($this->getPath().'/'.rawurlencode($id), $params);
return $this->get($this->getPath() . '/' . rawurlencode($id), $params);
}

/**
* Organization Boards API
*
* @return Organization\Boards
*/
public function boards()
{
return new Organization\Boards($this->client);
}

/**
* Organization Members API
*
* @return Organization\Members
*/
public function members()
{
return new Organization\Members($this->client);
}
}
51 changes: 51 additions & 0 deletions lib/Trello/Api/Organization/Boards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Trello\Api\Organization;

use Trello\Api\AbstractApi;
use Trello\Api\Board;
use Trello\Api\Member\Board\Backgrounds;
use Trello\Api\Member\Board\Stars;
use Trello\Exception\InvalidArgumentException;

/**
* Trello Organization Boards API
* @link https://trello.com/docs/api/organization
*
* Fully implemented.
*/
class Boards extends AbstractApi
{
protected $path = 'organizations/#id#/boards';

/**
* Get boads related to a given organization
* @link https://trello.com/docs/api/organization/#get-1-organizations-idorg-or-name-boards
*
* @param string $id the organization's id or username
* @param array $params optional parameters
*
* @return array
*/
public function all($id, array $params = array())
{
return $this->get($this->getPath($id), $params);
}

/**
* Filter boards related to a given organization
* @link https://trello.com/docs/api/organization/#get-1-organizations-idorg-or-name-boards-filter
*
* @param string $id the board's id
* @param string|array $filter array of / one of 'all', none', 'open', 'closed', 'all'
*
* @return array
*/
public function filter($id, $filter = 'all')
{
$allowed = array('all', 'members', 'organization', 'public', 'open', 'closed', 'pinned', 'unpinned', 'starred');
$filters = $this->validateAllowedParameters($allowed, $filter, 'filter');

return $this->get($this->getPath($id) . '/' . implode(',', $filters));
}
}
53 changes: 53 additions & 0 deletions lib/Trello/Api/Organization/Members.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Trello\Api\Organization;

use Trello\Api\AbstractApi;
use Trello\Api\Member;
use Trello\Exception\InvalidArgumentException;

/**
* Trello Board Members API
* @link https://trello.com/docs/api/board
*
* Fully implemented.
*/
class Members extends AbstractApi
{
/**
* Base path of board members api
* @var string
*/
protected $path = 'organizations/#id#/members';

/**
* Get a given board's members
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members
*
* @param string $id the board's id
* @param array $params optional parameters
*
* @return array
*/
public function all($id, array $params = array())
{
return $this->get($this->getPath($id), $params);
}

/**
* Filter members related to a given board
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members-filter
*
* @param string $id the board's id
* @param string|array $filter array of / one of 'none', 'normal', 'admins', 'owners', 'all'
*
* @return array
*/
public function filter($id, $filter = 'all')
{
$allowed = array('none', 'normal', 'admins', 'owners', 'all');
$filters = $this->validateAllowedParameters($allowed, $filter, 'filter');

return $this->get($this->getPath($id) . '/' . implode(',', $filters));
}
}
80 changes: 80 additions & 0 deletions test/Trello/Tests/Unit/Api/Organization/BoardsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Trello\Tests\Unit\Api\Organization;

use Trello\Tests\Unit\Api\TestCase;

/**
* @group unit
*/
class BoardsTest extends TestCase
{
protected $apiPath = 'organizations/#id#/boards';

/**
* @test
*/
public function shouldGetAllBoards()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath())
->will($this->returnValue($this->fakeId));

$this->assertEquals($this->fakeId, $api->all($this->fakeParentId));
}

/**
* @test
*/
public function shouldFilterBoardsWithDefaultFilter()
{
$defaultFilter = 'all';

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/' . $defaultFilter)
->will($this->returnValue($defaultFilter));

$this->assertEquals($defaultFilter, $api->filter($this->fakeParentId));
}

/**
* @test
*/
public function shouldFilterBoardsWithStringArgument()
{
$filter = 'open';

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/open')
->will($this->returnValue($filter));

$this->assertEquals($filter, $api->filter($this->fakeParentId, $filter));
}

/**
* @test
*/
public function shouldFilterBoardsWithArrayArgument()
{
$filter = array('open', 'closed');

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/open,closed')
->will($this->returnValue($filter));

$this->assertEquals($filter, $api->filter($this->fakeParentId, $filter));
}

protected function getApiClass()
{
return 'Trello\Api\Organization\Boards';
}
}
80 changes: 80 additions & 0 deletions test/Trello/Tests/Unit/Api/Organization/MembersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Trello\Tests\Unit\Api\Organization;

use Trello\Tests\Unit\Api\TestCase;

/**
* @group unit
*/
class MembersTest extends TestCase
{
protected $apiPath = 'organizations/#id#/members';

/**
* @test
*/
public function shouldGetAllMembers()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath())
->will($this->returnValue(true));

$this->assertEquals(true, $api->all($this->fakeParentId));
}

/**
* @test
*/
public function shouldFilterMembersWithDefaultFilter()
{
$defaultFilter = 'all';

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/' . $defaultFilter)
->will($this->returnValue(true));

$this->assertEquals(true, $api->filter($this->fakeParentId));
}

/**
* @test
*/
public function shouldFilterMembersWithStringArgument()
{
$filter = 'admins';

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/admins')
->will($this->returnValue(true));

$this->assertEquals(true, $api->filter($this->fakeParentId, $filter));
}

/**
* @test
*/
public function shouldFilterMembersWithArrayArgument()
{
$filter = array('admins', 'owners');

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->getPath() . '/admins,owners')
->will($this->returnValue(true));

$this->assertEquals(true, $api->filter($this->fakeParentId, $filter));
}

protected function getApiClass()
{
return 'Trello\Api\Organization\Members';
}
}
18 changes: 18 additions & 0 deletions test/Trello/Tests/Unit/Api/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ public function shouldShowOrganization()
$this->assertEquals($expectedArray, $api->show('54744b094fef0c7d704ca379'));
}

/**
* @test
*/
public function shouldGetBoardsApiObject()
{
$api = $this->getApiMock();
$this->assertInstanceOf('Trello\Api\Organization\Boards', $api->boards());
}

/**
* @test
*/
public function shouldGetMembersApiObject()
{
$api = $this->getApiMock();
$this->assertInstanceOf('Trello\Api\Organization\Members', $api->members());
}

protected function getApiClass()
{
return 'Trello\Api\Organization';
Expand Down
1 change: 1 addition & 0 deletions test/Trello/Tests/Unit/Api/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected $fakeId = '5461efc60872da1eca5bf45c';
protected $fakeParentId = '5461efc60872da1eca5bf45d';
protected $apiPath = null;

abstract protected function getApiClass();

Expand Down