diff options
-rw-r--r-- | appinfo/bootstrap.php | 12 | ||||
-rw-r--r-- | appinfo/routes.php | 17 | ||||
-rw-r--r-- | db/feed.php | 3 | ||||
-rw-r--r-- | external_api/feed.php | 26 | ||||
-rw-r--r-- | feed.bl.php | 11 |
5 files changed, 64 insertions, 5 deletions
diff --git a/appinfo/bootstrap.php b/appinfo/bootstrap.php index e9628979b..c7ce8fb62 100644 --- a/appinfo/bootstrap.php +++ b/appinfo/bootstrap.php @@ -123,6 +123,16 @@ function createDIContainer(){ return new FeedBL($c['FeedMapper']); }); - + /** + * EXTERNAL API LAYER + */ + $newsContainer['API_Feed'] = $newsContainer->share(function($c){ + return new API_($c['FolderMapper']); + }); + + $newsContainer['API_Folder'] = $newsContainer->share(function($c){ + return new FeedBL($c['FeedMapper']); + }); + return $newsContainer; }
\ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php index 57b8cb02e..66dedd7f0 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -205,10 +205,21 @@ $this->create('news_ajax_importOPML', '/import')->action( /** * External API */ +/** + * Feed API + */ \OCP\API::register( - 'get', '/news/feeds', array('OCA\News\API_Feed', 'getAll'), 'news', \OC_API::USER_AUTH + 'get', '/news/feeds', array('OCA\News\API_Feed', 'getAll'), 'news', \OC_API::USER_AUTH ); - \OCP\API::register( - 'get', '/news/folders', array('OCA\News\API_Folder', 'getAll'), 'news', \OC_API::USER_AUTH + 'get', '/news/feeds/{feedid}', array('OCA\News\API_Feed', 'getById'), 'news', \OC_API::USER_AUTH +); +\OCP\API::register( + 'post', '/news/feeds/create', array('OCA\News\API_Feed', 'create'), 'news', \OC_API::USER_AUTH +); +/** + * Folder API + */ +\OCP\API::register( + 'get', '/news/folders', array('OCA\News\API_Folder', 'getAll'), 'news', \OC_API::USER_AUTH );
\ No newline at end of file diff --git a/db/feed.php b/db/feed.php index 48f379a1b..8ab772ab9 100644 --- a/db/feed.php +++ b/db/feed.php @@ -77,7 +77,8 @@ class Feed extends Collection { $encoding = array( 'id' => $this->getId(), 'url' => $this->getUrl(), - 'title' => $this->getTitle() + 'title' => $this->getTitle(), + 'folderId' => $this->getFolderId() ); return $encoding; } diff --git a/external_api/feed.php b/external_api/feed.php index d23f77e01..dba518b7a 100644 --- a/external_api/feed.php +++ b/external_api/feed.php @@ -16,4 +16,30 @@ class API_Feed { } return new \OC_OCS_Result($serializedFeeds); } + + public static function getById($parameters) { + $feedid = $parameters['feedid']; + $container = createDIContainer(); + $bl = $container['FeedBL']; + $feed = $bl->getById($feedid); + $serializedFeed = array($feed->jsonSerialize()); + return new \OC_OCS_Result($serializedFeed); + } + + public static function create() { + + $url = $_POST['url']; + $folderId = $_POST['folderId']; + + $container = createDIContainer(); + $bl = $container['FeedBL']; + $success = $bl->create($url, $folderId); + + if ($success) { + return new OC_OCS_Result(); + } + else { + return new OC_OCS_Result(null, 101); + } + } } diff --git a/feed.bl.php b/feed.bl.php index 71507af98..c18b5a50b 100644 --- a/feed.bl.php +++ b/feed.bl.php @@ -11,4 +11,15 @@ class FeedBL { public function getAll() { return $this->feedMapper->findAll(); } + + public function getById($feedid) { + return $this->feedMapper->findById($feedid); + } + + public function create($url, $folderid) { + $feed = \OC_News_Utils::fetch($url); + $this->feedMapper->save($feed, $folderid); + return true; + } + } |