aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/api/v2/article.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-14 08:14:52 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-14 08:14:52 +0200
commit728d34d05a47050262322148f1704dc075971863 (patch)
treef4bc2ae7a29a19abd9cdc3b790489c2e4cdf30a1 /src/web/views/api/v2/article.py
parentRemoved links between current article and the previous/next articles. (diff)
parentBug fix: arguments in the URL weren't processed. (diff)
downloadnewspipe-728d34d05a47050262322148f1704dc075971863.tar.gz
newspipe-728d34d05a47050262322148f1704dc075971863.tar.bz2
newspipe-728d34d05a47050262322148f1704dc075971863.zip
Merge branch 'new-api'
Diffstat (limited to 'src/web/views/api/v2/article.py')
-rw-r--r--src/web/views/api/v2/article.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/web/views/api/v2/article.py b/src/web/views/api/v2/article.py
new file mode 100644
index 00000000..71201538
--- /dev/null
+++ b/src/web/views/api/v2/article.py
@@ -0,0 +1,53 @@
+from conf import API_ROOT
+import dateutil.parser
+from datetime import datetime
+from flask import current_app
+from flask.ext.restful import Api
+
+from web.views.common import api_permission
+from web.controllers import ArticleController
+from web.views.api.v2.common import (PyAggAbstractResource,
+ PyAggResourceNew, PyAggResourceExisting, PyAggResourceMulti)
+
+
+class ArticleNewAPI(PyAggResourceNew):
+ controller_cls = ArticleController
+
+
+class ArticleAPI(PyAggResourceExisting):
+ controller_cls = ArticleController
+
+
+class ArticlesAPI(PyAggResourceMulti):
+ controller_cls = ArticleController
+
+
+class ArticlesChallenge(PyAggAbstractResource):
+ controller_cls = ArticleController
+ attrs = {'ids': {'type': list, 'default': []}}
+
+ @api_permission.require(http_exception=403)
+ def get(self):
+ parsed_args = self.reqparse_args(right='read')
+ # collecting all attrs for casting purpose
+ attrs = self.controller_cls._get_attrs_desc('admin')
+ for id_dict in parsed_args['ids']:
+ keys_to_ignore = []
+ for key in id_dict:
+ if key not in attrs:
+ keys_to_ignore.append(key)
+ if issubclass(attrs[key]['type'], datetime):
+ id_dict[key] = dateutil.parser.parse(id_dict[key])
+ for key in keys_to_ignore:
+ del id_dict[key]
+
+ result = list(self.controller.challenge(parsed_args['ids']))
+ return result or None, 200 if result else 204
+
+api = Api(current_app, prefix=API_ROOT)
+
+api.add_resource(ArticleNewAPI, '/article', endpoint='article_new.json')
+api.add_resource(ArticleAPI, '/article/<int:obj_id>', endpoint='article.json')
+api.add_resource(ArticlesAPI, '/articles', endpoint='articles.json')
+api.add_resource(ArticlesChallenge, '/articles/challenge',
+ endpoint='articles_challenge.json')
bgstack15