diff options
-rw-r--r-- | appinfo/api.php | 184 | ||||
-rw-r--r-- | appinfo/routes.php | 17 | ||||
-rw-r--r-- | dependencyinjection/dicontainer.php | 14 | ||||
-rw-r--r-- | external/api.php | 0 | ||||
-rw-r--r-- | external/external.php | 42 | ||||
-rw-r--r-- | external/feedapi.php | 30 | ||||
-rw-r--r-- | external/folderapi.php | 74 | ||||
-rw-r--r-- | external/itemapi.php | 84 | ||||
-rw-r--r-- | tests/unit/external/FeedAPITest.php | 6 |
9 files changed, 434 insertions, 17 deletions
diff --git a/appinfo/api.php b/appinfo/api.php new file mode 100644 index 000000000..d018fef23 --- /dev/null +++ b/appinfo/api.php @@ -0,0 +1,184 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News; + +use \OCA\News\DependencyInjection\DIContainer; +use \OCA\News\External\External; + + +/** + * Folder API + */ +\OCP\API::register('get', '/apps/news/folders', + function($params) { + return External::main('FolderAPI', 'getAll', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('get', '/apps/news/folders/{folderId}', + function($urlParams) { + return External::main('FolderAPI', 'get', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('post', '/apps/news/folders', + function($urlParams) { + return External::main('FolderAPI', 'create', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('delete', '/apps/news/folders/{folderId}', + function($urlParams) { + return External::main('FolderAPI', 'delete', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/folders/{folderId}', + function($urlParams) { + return External::main('FolderAPI', 'update', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + + +/** + * Feed API + */ +\OCP\API::register('get', '/apps/news/feeds', + function($urlParams) { + return External::main('FeedAPI', 'getAll', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('get', '/apps/news/feeds/{feedId}', + function($urlParams) { + return External::main('FeedAPI', 'get', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('post', '/apps/news/feeds/{feedId}', + function($urlParams) { + return External::main('FeedAPI', 'create', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('delete', '/apps/news/feeds/{feedId}', + function($urlParams) { + return External::main('FeedAPI', 'delete', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/feeds/{feedId}/move', + function($urlParams) { + return External::main('FeedAPI', 'move', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('get', '/apps/news/feeds/{feedId}/read', + function($urlParams) { + return External::main('FeedAPI', 'read', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +/** + * Item API + */ +\OCP\API::register('get', '/apps/news/items', + function($urlParams) { + return External::main('ItemAPI', 'getAll', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('get', '/apps/news/items/updated', + function($urlParams) { + return External::main('ItemAPI', 'getUpdated', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('get', '/apps/news/items/{itemId}', + function($urlParams) { + return External::main('ItemAPI', 'get', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/items/{itemId}/read', + function($urlParams) { + return External::main('ItemAPI', 'read', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/items/{itemId}/unread', + function($urlParams) { + return External::main('ItemAPI', 'unread', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/items/{feedId}/{guidHash}/star', + function($urlParams) { + return External::main('ItemAPI', 'star', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +\OCP\API::register('put', '/apps/news/items/{feedId}/{guidHash}/unstar', + function($urlParams) { + return External::main('ItemAPI', 'unstar', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +);
\ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php index c82a011b3..1acf11334 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -29,11 +29,9 @@ use \OCA\AppFramework\App; use \OCA\News\DependencyInjection\DIContainer; - /** * Webinterface */ - $this->create('news_index', '/')->get()->action( function($params){ App::main('PageController', 'index', $params, new DIContainer()); @@ -202,16 +200,5 @@ $this->create('news_usersettings_language', '/usersettings/language')->get()->ac ); - -/** - * Feed API - */ -\OCP\API::register('get', '/apps/news/feeds', - function($urlParams) { - $container = new DIContainer(); - $response = $container['FeedAPI']->getAll($urlParams); - return new \OC_OCS_Result($response); - }, - 'news', - \OC_API::USER_AUTH -); +// include external API +require_once __DIR__ . '/api.php';
\ No newline at end of file diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php index 42b5b4238..761b95f64 100644 --- a/dependencyinjection/dicontainer.php +++ b/dependencyinjection/dicontainer.php @@ -43,7 +43,9 @@ use \OCA\News\Db\FeedMapper; use \OCA\News\Db\ItemMapper; use \OCA\News\Db\StatusFlag; +use \OCA\News\External\FolderAPI; use \OCA\News\External\FeedAPI; +use \OCA\News\External\ItemAPI; use \OCA\News\Utility\Fetcher; use \OCA\News\Utility\FeedFetcher; @@ -154,13 +156,23 @@ class DIContainer extends BaseContainer { /** * External API */ + $this['FolderAPI'] = $this->share(function($c){ + return new FolderAPI($c['API'], $c['Request'], + $c['FolderBusinessLayer']); + }); + $this['FeedAPI'] = $this->share(function($c){ - return new FeedAPI($c['API'], + return new FeedAPI($c['API'], $c['Request'], $c['FolderBusinessLayer'], $c['FeedBusinessLayer'], $c['ItemBusinessLayer']); }); + $this['ItemAPI'] = $this->share(function($c){ + return new ItemAPI($c['API'], $c['Request'], + $c['ItemBusinessLayer']); + }); + /** * Utility */ diff --git a/external/api.php b/external/api.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/external/api.php diff --git a/external/external.php b/external/external.php new file mode 100644 index 000000000..b134eee72 --- /dev/null +++ b/external/external.php @@ -0,0 +1,42 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\External; + +class External { + + + /** + * Simple main function for API calls + */ + public static function main($controllerName, $methodName, $urlParams, + \Pimple $container) { + $container['urlParams'] = $urlParams; + $response = $container[$controllerName]->$methodName(); + return new \OC_OCS_Result($response); + } + + +}
\ No newline at end of file diff --git a/external/feedapi.php b/external/feedapi.php index 219c8a893..e13ee9b0a 100644 --- a/external/feedapi.php +++ b/external/feedapi.php @@ -26,6 +26,7 @@ namespace OCA\News\External; use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Http\Request; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; @@ -39,8 +40,10 @@ class FeedAPI { private $feedBusinessLayer; private $folderBusinessLayer; private $api; + private $request; public function __construct(API $api, + Request $request, FolderBusinessLayer $folderBusinessLayer, FeedBusinessLayer $feedBusinessLayer, ItemBusinessLayer $itemBusinessLayer){ @@ -51,7 +54,7 @@ class FeedAPI { } - public function getAll(array $urlParams=array()) { + public function getAll() { $userId = $this->api->getUserId(); @@ -74,4 +77,29 @@ class FeedAPI { } + public function get() { + + } + + + public function create() { + + } + + + public function delete() { + + } + + + public function read() { + + } + + + public function move() { + + } + + } diff --git a/external/folderapi.php b/external/folderapi.php new file mode 100644 index 000000000..283230fdc --- /dev/null +++ b/external/folderapi.php @@ -0,0 +1,74 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\External; + +use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Http\Request; + +use \OCA\News\BusinessLayer\FolderBusinessLayer; +use \OCA\News\BusinessLayer\BusinessLayerException; + + +class FolderAPI { + + private $folderBusinessLayer; + private $api; + private $request; + + public function __construct(API $api, + Request $request, + FolderBusinessLayer $folderBusinessLayer){ + $this->api = $api; + $this->folderBusinessLayer = $folderBusinessLayer; + } + + + public function getAll() { + + + } + + + public function get() { + + } + + + public function create() { + + } + + + public function delete() { + + } + + + public function update() { + + } + +} diff --git a/external/itemapi.php b/external/itemapi.php new file mode 100644 index 000000000..4bb4f53af --- /dev/null +++ b/external/itemapi.php @@ -0,0 +1,84 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\External; + +use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Http\Request; + +use \OCA\News\BusinessLayer\ItemBusinessLayer; +use \OCA\News\BusinessLayer\BusinessLayerException; + + +class ItemAPI { + + private $itemBusinessLayer; + private $api; + private $request; + + public function __construct(API $api, + Request $request, + ItemBusinessLayer $itemBusinessLayer){ + $this->api = $api; + $this->itemBusinessLayer = $itemBusinessLayer; + } + + + public function getAll() { + + } + + + public function getUpdated() { + + } + + + public function get() { + + } + + + public function read() { + + } + + + public function unread() { + + } + + + public function star() { + + } + + + public function unstar() { + + } + + +} diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php index 8ceafd016..b3c945115 100644 --- a/tests/unit/external/FeedAPITest.php +++ b/tests/unit/external/FeedAPITest.php @@ -42,12 +42,17 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { private $feedAPI; private $api; private $user; + private $request; protected function setUp() { $this->api = $this->folderBusinessLayer = $this->getMockBuilder( '\OCA\AppFramework\Core\API') ->disableOriginalConstructor() ->getMock(); + $this->request = $this->folderBusinessLayer = $this->getMockBuilder( + '\OCA\AppFramework\Http\Request') + ->disableOriginalConstructor() + ->getMock(); $this->folderBusinessLayer = $this->getMockBuilder( '\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() @@ -62,6 +67,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { ->getMock(); $this->feedAPI = new FeedAPI( $this->api, + $this->request, $this->folderBusinessLayer, $this->feedBusinessLayer, $this->itemBusinessLayer |