diff --git a/docs/Api/Organization.md b/docs/Api/Organization.md index 03a1154..29bf9ab 100644 --- a/docs/Api/Organization.md +++ b/docs/Api/Organization.md @@ -6,3 +6,7 @@ Trello Organization API $api->organizations()->show(string $id, array $params) ``` +### Boards API +```php +$api->members()->boards() +``` \ No newline at end of file diff --git a/docs/Api/Organization/Boards.md b/docs/Api/Organization/Boards.md new file mode 100644 index 0000000..4a97fcb --- /dev/null +++ b/docs/Api/Organization/Boards.md @@ -0,0 +1,7 @@ +Trello Member Boards API +====================== + +### Get boads related to a given organization +```php +$api->organization()->boards()->all(string $id, array $params) +``` \ No newline at end of file diff --git a/lib/Trello/Api/Organization.php b/lib/Trello/Api/Organization.php index 6fce6b1..ec5cd93 100644 --- a/lib/Trello/Api/Organization.php +++ b/lib/Trello/Api/Organization.php @@ -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); } } diff --git a/lib/Trello/Api/Organization/Boards.php b/lib/Trello/Api/Organization/Boards.php new file mode 100644 index 0000000..77908ab --- /dev/null +++ b/lib/Trello/Api/Organization/Boards.php @@ -0,0 +1,51 @@ +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)); + } +} diff --git a/lib/Trello/Api/Organization/Members.php b/lib/Trello/Api/Organization/Members.php new file mode 100644 index 0000000..b5189e5 --- /dev/null +++ b/lib/Trello/Api/Organization/Members.php @@ -0,0 +1,53 @@ +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)); + } +} diff --git a/test/Trello/Tests/Unit/Api/Organization/BoardsTest.php b/test/Trello/Tests/Unit/Api/Organization/BoardsTest.php new file mode 100644 index 0000000..72650f1 --- /dev/null +++ b/test/Trello/Tests/Unit/Api/Organization/BoardsTest.php @@ -0,0 +1,80 @@ +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'; + } +} diff --git a/test/Trello/Tests/Unit/Api/Organization/MembersTest.php b/test/Trello/Tests/Unit/Api/Organization/MembersTest.php new file mode 100644 index 0000000..6a1c5e9 --- /dev/null +++ b/test/Trello/Tests/Unit/Api/Organization/MembersTest.php @@ -0,0 +1,80 @@ +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'; + } +} diff --git a/test/Trello/Tests/Unit/Api/OrganizationTest.php b/test/Trello/Tests/Unit/Api/OrganizationTest.php index 59f1346..47fa62f 100644 --- a/test/Trello/Tests/Unit/Api/OrganizationTest.php +++ b/test/Trello/Tests/Unit/Api/OrganizationTest.php @@ -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'; diff --git a/test/Trello/Tests/Unit/Api/TestCase.php b/test/Trello/Tests/Unit/Api/TestCase.php index 8fb4ec6..10d6494 100644 --- a/test/Trello/Tests/Unit/Api/TestCase.php +++ b/test/Trello/Tests/Unit/Api/TestCase.php @@ -6,6 +6,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { protected $fakeId = '5461efc60872da1eca5bf45c'; protected $fakeParentId = '5461efc60872da1eca5bf45d'; + protected $apiPath = null; abstract protected function getApiClass();