summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/api.php218
-rw-r--r--appinfo/routes.php149
-rw-r--r--external/feedapi.php5
-rw-r--r--external/folderapi.php5
-rw-r--r--external/itemapi.php11
-rw-r--r--external/newsapi.php4
-rw-r--r--tests/unit/external/FeedAPITest.php5
-rw-r--r--tests/unit/external/FolderAPITest.php3
-rw-r--r--tests/unit/external/ItemAPITest.php3
-rw-r--r--tests/unit/external/NewsAPIResultTest.php49
-rw-r--r--tests/unit/external/NewsAPITest.php3
11 files changed, 178 insertions, 277 deletions
diff --git a/appinfo/api.php b/appinfo/api.php
deleted file mode 100644
index 5d5a1fee2..000000000
--- a/appinfo/api.php
+++ /dev/null
@@ -1,218 +0,0 @@
-<?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\AppFramework\External\External;
-
-
-/**
- * Generic API
- */
-\OCP\API::register('get', '/apps/news/version',
- function($params) {
- return External::main('NewsAPI', 'version', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-/**
- * 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('post', '/apps/news/folders',
- function($params) {
- return External::main('FolderAPI', 'create', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('delete', '/apps/news/folders/{folderId}',
- function($params) {
- return External::main('FolderAPI', 'delete', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/folders/{folderId}',
- function($params) {
- return External::main('FolderAPI', 'update', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/folders/{folderId}/read',
- function($params) {
- return External::main('FolderAPI', 'read', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-/**
- * Feed API
- */
-\OCP\API::register('get', '/apps/news/feeds',
- function($params) {
- return External::main('FeedAPI', 'getAll', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('post', '/apps/news/feeds/{feedId}',
- function($params) {
- return External::main('FeedAPI', 'create', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('delete', '/apps/news/feeds/{feedId}',
- function($params) {
- return External::main('FeedAPI', 'delete', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/feeds/{feedId}/move',
- function($params) {
- return External::main('FeedAPI', 'move', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/feeds/{feedId}/read',
- function($params) {
- return External::main('FeedAPI', 'read', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-/**
- * Item API
- */
-\OCP\API::register('get', '/apps/news/items',
- function($params) {
- return External::main('ItemAPI', 'getAll', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('get', '/apps/news/items/updated',
- function($params) {
- return External::main('ItemAPI', 'getUpdated', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/{itemId}/read',
- function($params) {
- return External::main('ItemAPI', 'read', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/{itemId}/unread',
- function($params) {
- return External::main('ItemAPI', 'unread', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/{feedId}/{guidHash}/star',
- function($params) {
- return External::main('ItemAPI', 'star', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/{feedId}/{guidHash}/unstar',
- function($params) {
- return External::main('ItemAPI', 'unstar', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/read',
- function($params) {
- return External::main('ItemAPI', 'readAll', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/read/multiple',
- function($params) {
- return External::main('ItemAPI', 'readMultiple', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/unread/multiple',
- function($params) {
- return External::main('ItemAPI', 'unreadMultiple', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/star/multiple',
- function($params) {
- return External::main('ItemAPI', 'starMultiple', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
-
-\OCP\API::register('put', '/apps/news/items/unstar/multiple',
- function($params) {
- return External::main('ItemAPI', 'unstarMultiple', $params, new DIContainer());
- },
- 'news',
- \OC_API::USER_AUTH
-);
diff --git a/appinfo/routes.php b/appinfo/routes.php
index f290c2e2b..9f30def1d 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -39,7 +39,7 @@ $this->create('news_index', '/')->get()->action(
);
/**
- * Folders
+ * Folders
*/
$this->create('news_folders', '/folders')->get()->action(
function($params){
@@ -143,7 +143,7 @@ $this->create('news_feeds_read', '/feeds/{feedId}/read')->post()->action(
$this->create('news_feeds_import_googlereader', '/feeds/import/googlereader')
->post()->action(
function($params){
- App::main('FeedController', 'importGoogleReader', $params,
+ App::main('FeedController', 'importGoogleReader', $params,
new DIContainer());
}
);
@@ -224,5 +224,146 @@ $this->create('news_usersettings_language', '/usersettings/language')->get()->ac
);
-// include external API
-require_once __DIR__ . '/api.php'; \ No newline at end of file
+/**
+ * Generic API
+ */
+$this->create('news_api_version', '/api/v1-2/version')->get()->action(
+ function($params) {
+ return App::main('NewsAPI', 'version', $params, new DIContainer());
+ }
+);
+
+/**
+ * Folder API
+ */
+$this->create('news_api_folders_get_all', '/api/v1-2/folders')->get()->action(
+ function($params) {
+ return App::main('FolderAPI', 'getAll', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_folders_create', '/api/v1-2/folders')->post()->action(
+ function($params) {
+ return App::main('FolderAPI', 'create', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_folders_delete', '/api/v1-2/folders/{folderId}')->delete()->action(
+ function($params) {
+ return App::main('FolderAPI', 'delete', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_folders_update', '/api/v1-2/folders/{folderId}')->put()->action(
+ function($params) {
+ return App::main('FolderAPI', 'update', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_folders_read', '/api/v1-2/folders/{folderId}/read')->put()->action(
+ function($params) {
+ return App::main('FolderAPI', 'read', $params, new DIContainer());
+ }
+);
+
+/**
+ * Feed API
+ */
+$this->create('news_api_feeds_get_all', '/api/v1-2/feeds')->get()->action(
+ function($params) {
+ return App::main('FeedAPI', 'getAll', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_feeds_create', '/api/v1-2/feeds/{feedId}')->post()->action(
+ function($params) {
+ return App::main('FeedAPI', 'create', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_feeds_delete', '/api/v1-2/feeds/{feedId}')->delete()->action(
+ function($params) {
+ return App::main('FeedAPI', 'delete', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_feeds_move', '/api/v1-2/feeds/{feedId}/move')->put()->action(
+ function($params) {
+ return App::main('FeedAPI', 'move', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_feeds_read', '/api/v1-2/feeds/{feedId}/read')->put()->action(
+ function($params) {
+ return App::main('FeedAPI', 'read', $params, new DIContainer());
+ }
+);
+
+/**
+ * Item API
+ */
+$this->create('news_api_items_get_all', '/api/v1-2/items')->get()->action(
+ function($params) {
+ return App::main('ItemAPI', 'getAll', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_updated', '/api/v1-2/items/updated')->get()->action(
+ function($params) {
+ return App::main('ItemAPI', 'getUpdated', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_read', '/api/v1-2/items/{itemId}/read')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'read', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_unread', '/api/v1-2/items/{itemId}/unread')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'unread', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_star', '/api/v1-2/items/{feedId}/{guidHash}/star')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'star', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_unstar', '/api/v1-2/items/{feedId}/{guidHash}/unstar')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'unstar', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_read_all', '/api/v1-2/items/read')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'readAll', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_read_multiple', '/api/v1-2/items/read/multiple')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'readMultiple', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_unread_multiple', '/api/v1-2/items/unread/multiple')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'unreadMultiple', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_star_multiple', '/api/v1-2/items/star/multiple')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'starMultiple', $params, new DIContainer());
+ }
+);
+
+$this->create('news_api_items_unstar_multiple', '/api/v1-2/items/unstar/multiple')->put()->action(
+ function($params) {
+ return App::main('ItemAPI', 'unstarMultiple', $params, new DIContainer());
+ }
+);
diff --git a/external/feedapi.php b/external/feedapi.php
index b9dad00d2..f2f02831a 100644
--- a/external/feedapi.php
+++ b/external/feedapi.php
@@ -59,6 +59,7 @@ class FeedAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function getAll() {
@@ -86,6 +87,7 @@ class FeedAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function create() {
@@ -121,6 +123,7 @@ class FeedAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function delete() {
@@ -140,6 +143,7 @@ class FeedAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function read() {
@@ -155,6 +159,7 @@ class FeedAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function move() {
diff --git a/external/folderapi.php b/external/folderapi.php
index 3a8b7ea6f..237f23660 100644
--- a/external/folderapi.php
+++ b/external/folderapi.php
@@ -55,6 +55,7 @@ class FolderAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function getAll() {
@@ -74,6 +75,7 @@ class FolderAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function create() {
@@ -99,6 +101,7 @@ class FolderAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function delete() {
@@ -118,6 +121,7 @@ class FolderAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function update() {
@@ -143,6 +147,7 @@ class FolderAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function read() {
diff --git a/external/itemapi.php b/external/itemapi.php
index 611a51fd2..2d484ce7b 100644
--- a/external/itemapi.php
+++ b/external/itemapi.php
@@ -50,6 +50,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function getAll() {
@@ -90,6 +91,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function getUpdated() {
@@ -148,6 +150,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function read() {
@@ -158,6 +161,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function unread() {
@@ -168,6 +172,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function star() {
@@ -178,6 +183,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function unstar() {
@@ -188,6 +194,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function readAll() {
@@ -218,6 +225,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function readMultiple() {
@@ -228,6 +236,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function unreadMultiple() {
@@ -255,6 +264,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function starMultiple() {
@@ -265,6 +275,7 @@ class ItemAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function unstarMultiple() {
diff --git a/external/newsapi.php b/external/newsapi.php
index bb3e3bc28..4a2e16fa3 100644
--- a/external/newsapi.php
+++ b/external/newsapi.php
@@ -28,6 +28,7 @@ namespace OCA\News\External;
use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Controller\Controller;
use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Http\JSONResponse;
class NewsAPI extends Controller {
@@ -41,11 +42,12 @@ class NewsAPI extends Controller {
/**
* @IsAdminExemption
* @IsSubAdminExemption
+ * @CSRFExemption
* @Ajax
*/
public function version() {
$version = $this->api->getAppValue('installed_version');
- return new NewsAPIResult(array('version' => $version));
+ return new JSONResponse(array('version' => $version));
}
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index b4ab8bfe6..9b9d02514 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -84,7 +84,8 @@ class FeedAPITest extends ControllerTestUtility {
private function assertDefaultAnnotations($methodName){
- $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption',
+ 'Ajax', 'CSRFExemption');
$this->assertAnnotations($this->feedAPI, $methodName, $annotations);
}
@@ -336,7 +337,7 @@ class FeedAPITest extends ControllerTestUtility {
$data = $response->getData();
$this->assertEquals($this->msg, $data['message']);
- $this->assertEquals(NewsAPIResult::EXISTS_ERROR, $response->getStatus());
+ $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
}
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php
index f20cf0ccf..60ab40a81 100644
--- a/tests/unit/external/FolderAPITest.php
+++ b/tests/unit/external/FolderAPITest.php
@@ -79,7 +79,8 @@ class FolderAPITest extends ControllerTestUtility {
private function assertDefaultAnnotations($methodName){
- $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption',
+ 'Ajax', 'CSRFExemption');
$this->assertAnnotations($this->folderAPI, $methodName, $annotations);
}
diff --git a/tests/unit/external/ItemAPITest.php b/tests/unit/external/ItemAPITest.php
index f20e38b25..f2533b4fa 100644
--- a/tests/unit/external/ItemAPITest.php
+++ b/tests/unit/external/ItemAPITest.php
@@ -69,7 +69,8 @@ class ItemAPITest extends ControllerTestUtility {
private function assertDefaultAnnotations($methodName){
- $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption',
+ 'Ajax', 'CSRFExemption');
$this->assertAnnotations($this->itemAPI, $methodName, $annotations);
}
diff --git a/tests/unit/external/NewsAPIResultTest.php b/tests/unit/external/NewsAPIResultTest.php
deleted file mode 100644
index 6d0e41669..000000000
--- a/tests/unit/external/NewsAPIResultTest.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?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;
-
-require_once(__DIR__ . "/../../classloader.php");
-
-
-class NewsAPIResultTest extends \PHPUnit_Framework_TestCase {
-
-
- public function testExistsError(){
- $result = new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR, 'hi');
- $this->assertEquals(409, $result->getStatusCode());
- $this->assertEquals('hi', $result->getMessage());
- }
-
-
- public function testNoInput(){
- $result = new NewsAPIResult();
- $this->assertNull($result->getData());
- $this->assertEquals(100, $result->getStatusCode());
- $this->assertNull($result->getMessage());
- }
-
-
-}
diff --git a/tests/unit/external/NewsAPITest.php b/tests/unit/external/NewsAPITest.php
index 07ba00a1e..3cccd62ff 100644
--- a/tests/unit/external/NewsAPITest.php
+++ b/tests/unit/external/NewsAPITest.php
@@ -51,7 +51,8 @@ class NewsAPITest extends ControllerTestUtility {
private function assertDefaultAnnotations($methodName){
- $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption',
+ 'Ajax', 'CSRFExemption');
$this->assertAnnotations($this->newsAPI, $methodName, $annotations);
}