diff options
-rw-r--r-- | app/Api/Project.php | 30 | ||||
-rw-r--r-- | app/Api/Task.php | 26 | ||||
-rw-r--r-- | docs/api-json-rpc.markdown | 71 | ||||
-rw-r--r-- | tests/functionals/ApiTest.php | 24 |
4 files changed, 122 insertions, 29 deletions
diff --git a/app/Api/Project.php b/app/Api/Project.php index 2451cd9c..faf2a3da 100644 --- a/app/Api/Project.php +++ b/app/Api/Project.php @@ -12,17 +12,17 @@ class Project extends Base { public function getProjectById($project_id) { - return $this->project->getById($project_id); + return $this->formatProject($this->project->getById($project_id)); } public function getProjectByName($name) { - return $this->project->getByName($name); + return $this->formatProject($this->project->getByName($name)); } public function getAllProjects() { - return $this->project->getAll(); + return $this->formatProjects($this->project->getAll()); } public function removeProject($project_id) @@ -82,4 +82,28 @@ class Project extends Base list($valid,) = $this->project->validateModification($values); return $valid && $this->project->update($values); } + + private function formatProject($project) + { + if (! empty($project)) { + $project['url'] = array( + 'board' => $this->helper->url->base().$this->helper->url->to('board', 'show', array('project_id' => $project['id'])), + 'calendar' => $this->helper->url->base().$this->helper->url->to('calendar', 'show', array('project_id' => $project['id'])), + 'list' => $this->helper->url->base().$this->helper->url->to('listing', 'show', array('project_id' => $project['id'])), + ); + } + + return $project; + } + + private function formatProjects($projects) + { + if (! empty($projects)) { + foreach ($projects as &$project) { + $project = $this->formatProject($project); + } + } + + return $projects; + } } diff --git a/app/Api/Task.php b/app/Api/Task.php index e06c012b..ade49a6d 100644 --- a/app/Api/Task.php +++ b/app/Api/Task.php @@ -14,17 +14,17 @@ class Task extends Base { public function getTask($task_id) { - return $this->taskFinder->getById($task_id); + return $this->formatTask($this->taskFinder->getById($task_id)); } public function getTaskByReference($project_id, $reference) { - return $this->taskFinder->getByReference($project_id, $reference); + return $this->formatTask($this->taskFinder->getByReference($project_id, $reference)); } public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) { - return $this->taskFinder->getAll($project_id, $status_id); + return $this->formatTasks($this->taskFinder->getAll($project_id, $status_id)); } public function getOverdueTasks() @@ -115,4 +115,24 @@ class Task extends Base list($valid) = $this->taskValidator->validateApiModification($values); return $valid && $this->taskModification->update($values); } + + private function formatTask($task) + { + if (! empty($task)) { + $task['url'] = $this->helper->url->base().$this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])); + } + + return $task; + } + + private function formatTasks($tasks) + { + if (! empty($tasks)) { + foreach ($tasks as &$task) { + $task = $this->formatTask($task); + } + } + + return $tasks; + } } diff --git a/docs/api-json-rpc.markdown b/docs/api-json-rpc.markdown index e54c3a13..8a637412 100644 --- a/docs/api-json-rpc.markdown +++ b/docs/api-json-rpc.markdown @@ -306,9 +306,19 @@ Response example: "name": "API test", "is_active": "1", "token": "", - "last_modified": "1410263246", + "last_modified": "1436119135", "is_public": "0", - "description": "A sample project" + "is_private": "0", + "is_everybody_allowed": "0", + "default_swimlane": "Default swimlane", + "show_default_swimlane": "1", + "description": "test", + "identifier": "", + "url": { + "board": "http:\/\/127.0.0.1:8000\/?controller=board&action=show&project_id=1", + "calendar": "http:\/\/127.0.0.1:8000\/?controller=calendar&action=show&project_id=1", + "list": "http:\/\/127.0.0.1:8000\/?controller=listing&action=show&project_id=1" + } } } ``` @@ -345,9 +355,19 @@ Response example: "name": "Test", "is_active": "1", "token": "", - "last_modified": "0", + "last_modified": "1436119135", "is_public": "0", - "description": "A sample project" + "is_private": "0", + "is_everybody_allowed": "0", + "default_swimlane": "Default swimlane", + "show_default_swimlane": "1", + "description": "test", + "identifier": "", + "url": { + "board": "http:\/\/127.0.0.1:8000\/?controller=board&action=show&project_id=1", + "calendar": "http:\/\/127.0.0.1:8000\/?controller=calendar&action=show&project_id=1", + "list": "http:\/\/127.0.0.1:8000\/?controller=listing&action=show&project_id=1" + } } } ``` @@ -366,7 +386,7 @@ Request example: { "jsonrpc": "2.0", "method": "getAllProjects", - "id": 134982303 + "id": 2134420212 } ``` @@ -375,25 +395,26 @@ Response example: ```json { "jsonrpc": "2.0", - "id": 134982303, + "id": 2134420212, "result": [ { - "id": "2", - "name": "PHP client", - "is_active": "1", - "token": "", - "last_modified": "0", - "is_public": "0", - "description": "PHP client project" - }, - { "id": "1", - "name": "Test", + "name": "API test", "is_active": "1", "token": "", - "last_modified": "0", + "last_modified": "1436119570", "is_public": "0", - "description": "Test project" + "is_private": "0", + "is_everybody_allowed": "0", + "default_swimlane": "Default swimlane", + "show_default_swimlane": "1", + "description": null, + "identifier": "", + "url": { + "board": "http:\/\/127.0.0.1:8000\/?controller=board&action=show&project_id=1", + "calendar": "http:\/\/127.0.0.1:8000\/?controller=calendar&action=show&project_id=1", + "list": "http:\/\/127.0.0.1:8000\/?controller=listing&action=show&project_id=1" + } } ] } @@ -1970,8 +1991,9 @@ Response example: "recurrence_timeframe": "0", "recurrence_basedate": "0", "recurrence_parent": null, - "recurrence_child": null - } + "recurrence_child": null, + "url": "http:\/\/127.0.0.1:8000\/?controller=task&action=show&task_id=1&project_id=1" + } } ``` @@ -2033,7 +2055,8 @@ Response example: "recurrence_timeframe": "0", "recurrence_basedate": "0", "recurrence_parent": null, - "recurrence_child": null + "recurrence_child": null, + "url": "http:\/\/127.0.0.1:8000\/?controller=task&action=show&task_id=5&project_id=1" } } ``` @@ -2097,7 +2120,8 @@ Response example: "recurrence_timeframe": "0", "recurrence_basedate": "0", "recurrence_parent": null, - "recurrence_child": null + "recurrence_child": null, + "url": "http:\/\/127.0.0.1:8000\/?controller=task&action=show&task_id=1&project_id=1" }, { "id": "2", @@ -2128,7 +2152,8 @@ Response example: "recurrence_timeframe": "0", "recurrence_basedate": "0", "recurrence_parent": null, - "recurrence_child": null + "recurrence_child": null, + "url": "http:\/\/127.0.0.1:8000\/?controller=task&action=show&task_id=2&project_id=1" }, ... ] diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index b7ae80f1..284c31b9 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -63,6 +63,9 @@ class Api extends PHPUnit_Framework_TestCase if ($projects) { foreach ($projects as $project) { + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); $this->assertTrue($this->client->removeProject($project['id'])); } } @@ -80,6 +83,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); } public function testGetProjectByName() @@ -87,6 +93,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectByName('API test'); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); $project = $this->client->getProjectByName(array('name' => 'API test')); $this->assertNotEmpty($project); @@ -97,6 +106,18 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNull($project); } + public function testGetAllProjects() + { + $projects = $this->client->getAllProjects(); + $this->assertNotEmpty($projects); + + foreach ($projects as $project) { + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + } + } + public function testUpdateProject() { $project = $this->client->getProjectById(1); @@ -385,6 +406,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($task); $this->assertTrue(is_array($task)); $this->assertEquals('Task #1', $task['title']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } public function testGetAllTasks() @@ -394,6 +416,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($tasks); $this->assertTrue(is_array($tasks)); $this->assertEquals('Task #1', $tasks[0]['title']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); $tasks = $this->client->getAllTasks(2, 0); @@ -1030,5 +1053,6 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEmpty($task); $this->assertEquals('Task with external ticket number', $task['title']); $this->assertEquals('TICKET-1234', $task['reference']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } }
\ No newline at end of file |