aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-07-02 22:52:07 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-07-02 22:52:07 +0200
commit65bbeb1871367e74e1e01c101d5890d0464fecf3 (patch)
tree329a7741b79d4a80fe8f0e361989d4ef4be2dfeb
parentAdded FeedListAPI ressource (todo: FeedAPI ressource). (diff)
downloadnewspipe-65bbeb1871367e74e1e01c101d5890d0464fecf3.tar.gz
newspipe-65bbeb1871367e74e1e01c101d5890d0464fecf3.tar.bz2
newspipe-65bbeb1871367e74e1e01c101d5890d0464fecf3.zip
FeedAPI added to the rest module.
-rw-r--r--pyaggr3g470r/rest.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/pyaggr3g470r/rest.py b/pyaggr3g470r/rest.py
index fa7def90..e2cb92e5 100644
--- a/pyaggr3g470r/rest.py
+++ b/pyaggr3g470r/rest.py
@@ -267,5 +267,57 @@ class FeedListAPI(Resource):
"""
pass
+class FeedAPI(Resource):
+ """
+ Defines a RESTful API for Feed elements.
+ """
+ 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(FeedAPI, self).__init__()
+
+ def get(self, id=None):
+ """
+ Returns a feed.
+ """
+ result = []
+ if id is not None:
+ feed = Feed.query.filter(Feed.id == id, Feed.user_id == g.user.id).first()
+ if feed is not None:
+ result.append(feed)
+
+ return jsonify(result= [{
+ "id": feed.id,
+ "title": feed.title,
+ "description": feed.description,
+ "link": feed.link,
+ "site_link": feed.site_link
+ }
+ for feed in result]
+ )
+
+ def put(self, id):
+ """
+ Update a feed.
+ """
+ pass
+
+ def delete(self, id):
+ """
+ Delete a feed.
+ """
+ feed = Feed.query.filter(Feed.id == id, Feed.user_id == g.user.id).first()
+ if feed is not None:
+ db.session.delete(feed)
+ db.session.commit()
+ return {"message":"ok"}
+ else:
+ response = jsonify({'code': 404, 'message': 'Feed not found'})
+ response.status_code = 404
+ return response
+
api.add_resource(FeedListAPI, '/api/v1.0/feeds', endpoint = 'feeds.json')
-#api.add_resource(FeedAPI, '/api/v1.0/feeds/<int:id>', endpoint = 'feeds.json') \ No newline at end of file
+api.add_resource(FeedAPI, '/api/v1.0/feeds/<int:id>', endpoint = 'feed.json') \ No newline at end of file
bgstack15