From 3e7236a68870ac8dd755b09203280ced96528602 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 1 Jul 2014 07:45:37 +0200 Subject: Added FeedListAPI ressource (todo: FeedAPI ressource). --- pyaggr3g470r/rest.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/rest.py b/pyaggr3g470r/rest.py index f5c315c4..fa7def90 100644 --- a/pyaggr3g470r/rest.py +++ b/pyaggr3g470r/rest.py @@ -226,3 +226,46 @@ class ArticleAPI(Resource): api.add_resource(ArticleListAPI, '/api/v1.0/articles', endpoint = 'articles.json') api.add_resource(ArticleAPI, '/api/v1.0/articles/', endpoint = 'article.json') + +class FeedListAPI(Resource): + """ + Defines a RESTful API for Feed elements. + """ + method_decorators = [authenticate] + + def __init__(self): + self.reqparse = reqparse.RequestParser() + self.reqparse.add_argument('title', type = unicode, location = 'json') + self.reqparse.add_argument('description', type = unicode, location = 'json') + self.reqparse.add_argument('link', type = unicode, location = 'json') + self.reqparse.add_argument('site_link', type = unicode, location = 'json') + self.reqparse.add_argument('email_notification', type = bool, location = 'json') + self.reqparse.add_argument('enabled', type = bool, location = 'json') + super(FeedListAPI, self).__init__() + + def get(self): + """ + Returns a list of feeds. + """ + return jsonify(result= [{ + "id": feed.id, + "title": feed.title, + "description": feed.description, + "link": feed.link, + "site_link": feed.site_link, + "email_notification": feed.email_notification, + "enabled": feed.enabled, + "created_date": feed.created_date, + "nb_articles": feed.articles.count() + } + for feed in g.user.feeds] + ) + + def post(self): + """ + POST method - Create a new feed. + """ + pass + +api.add_resource(FeedListAPI, '/api/v1.0/feeds', endpoint = 'feeds.json') +#api.add_resource(FeedAPI, '/api/v1.0/feeds/', endpoint = 'feeds.json') \ No newline at end of file -- cgit