diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 16:47:16 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 16:47:16 +0200 |
commit | fc2fea7a261597af9f0fda3558a1fcb187043e8b (patch) | |
tree | 22d2d30c3c943f54e2432deaa1f1a33e8297e38a | |
parent | Updated README. (diff) | |
download | newspipe-fc2fea7a261597af9f0fda3558a1fcb187043e8b.tar.gz newspipe-fc2fea7a261597af9f0fda3558a1fcb187043e8b.tar.bz2 newspipe-fc2fea7a261597af9f0fda3558a1fcb187043e8b.zip |
It is now possible to update the status ('like' and 'readed') of an article with the REST API.
-rw-r--r-- | README.rst | 11 | ||||
-rw-r--r-- | pyaggr3g470r/rest.py | 31 |
2 files changed, 30 insertions, 12 deletions
@@ -191,6 +191,17 @@ Add an article: >>> print json.loads(r.content)["result"][0]["title"] Sortie de pyAggr3g470r 5.3 +Update an article: + +.. code:: python + + >>> payload = {"like":True, "readed":False} + >>> r = requests.put("https://pyaggr3g470r.herokuapp.com/api/v1.0/articles/65", headers=headers, auth=("your-email", "your-password"), data=json.dumps(payload)) + >>> print r.content + { + "message": "ok" + } + Delete an article: .. code:: python diff --git a/pyaggr3g470r/rest.py b/pyaggr3g470r/rest.py index 10116f8e..34530b02 100644 --- a/pyaggr3g470r/rest.py +++ b/pyaggr3g470r/rest.py @@ -31,6 +31,7 @@ import dateutil.parser from functools import wraps from flask import g, Response, request, session, jsonify from flask.ext.restful import Resource, reqparse +#from flask.ext.restful.inputs import boolean from pyaggr3g470r import api, db from pyaggr3g470r.models import User, Article, Feed @@ -141,14 +142,6 @@ class ArticleListAPI(Resource): db.session.commit() return {"message":"ok"} - def put(self): - """ - PUT method - no sense here. - """ - response = jsonify({'code': 501, 'message': 'PUT method not implemented for Article objects.'}) - response.status_code = 501 - return response - class ArticleAPI(Resource): """ Defines a RESTful API for Article elements. @@ -156,6 +149,9 @@ class ArticleAPI(Resource): method_decorators = [authenticate] def __init__(self): + self.reqparse = reqparse.RequestParser() + self.reqparse.add_argument('like', type = bool, location = 'json') + self.reqparse.add_argument('readed', type = bool, location = 'json') super(ArticleAPI, self).__init__() def get(self, id=None): @@ -188,11 +184,22 @@ class ArticleAPI(Resource): def put(self, id): """ - PUT method - no sense here. + Update an article. + It is only possible to update the status ('like' and 'readed') of an article. """ - response = jsonify({'code': 501, 'message': 'PUT method not implemented for Article objects.'}) - response.status_code = 501 - return response + args = self.reqparse.parse_args() + article = Article.query.filter(Article.id == id).first() + if article is not None and article.source.subscriber.id == g.user.id: + if None is not args.get('like', None): + article.like = args['like'] + if None is not args.get('readed', None): + article.readed = args['readed'] + db.session.commit() + return {"message":"ok"} + else: + response = jsonify({'code': 404, 'message': 'Article not found'}) + response.status_code = 404 + return response def delete(self, id): """ |