diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2015-12-12 21:14:28 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2015-12-17 09:42:56 +0100 |
commit | b35e9773198ef2d8b37c4ca223f08147db47de0b (patch) | |
tree | ba4b1b171b3c1ab9414a96ad264c47b0f9d1246b /src/web/views/api/feed.py | |
parent | Updated link to Heroku deploy button on the About page. (diff) | |
download | newspipe-b35e9773198ef2d8b37c4ca223f08147db47de0b.tar.gz newspipe-b35e9773198ef2d8b37c4ca223f08147db47de0b.tar.bz2 newspipe-b35e9773198ef2d8b37c4ca223f08147db47de0b.zip |
moving the root of source code from / to /src/
Diffstat (limited to 'src/web/views/api/feed.py')
-rw-r--r-- | src/web/views/api/feed.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/web/views/api/feed.py b/src/web/views/api/feed.py new file mode 100644 index 00000000..2bb9814f --- /dev/null +++ b/src/web/views/api/feed.py @@ -0,0 +1,69 @@ +#! /usr/bin/env python +# -*- coding: utf-8 - + +from flask import g + +from web.controllers.feed import (FeedController, + DEFAULT_MAX_ERROR, + DEFAULT_LIMIT, + DEFAULT_REFRESH_RATE) + +from web.views.api.common import PyAggAbstractResource, \ + PyAggResourceNew, \ + PyAggResourceExisting, \ + PyAggResourceMulti + +FEED_ATTRS = {'title': {'type': str}, + 'description': {'type': str}, + 'link': {'type': str}, + 'user_id': {'type': int}, + 'site_link': {'type': str}, + 'enabled': {'type': bool, 'default': True}, + 'etag': {'type': str, 'default': ''}, + 'icon_url': {'type': str, 'default': ''}, + 'last_modified': {'type': str}, + 'last_retrieved': {'type': str}, + 'last_error': {'type': str}, + 'error_count': {'type': int, 'default': 0}} + +class FeedNewAPI(PyAggResourceNew): + controller_cls = FeedController + attrs = FEED_ATTRS + to_date = ['date', 'last_retrieved'] + +class FeedAPI(PyAggResourceExisting): + controller_cls = FeedController + attrs = FEED_ATTRS + to_date = ['date', 'last_retrieved'] + +class FeedsAPI(PyAggResourceMulti): + controller_cls = FeedController + attrs = FEED_ATTRS + to_date = ['date', 'last_retrieved'] + +class FetchableFeedAPI(PyAggAbstractResource): + controller_cls = FeedController + to_date = ['date', 'last_retrieved'] + attrs = {'max_error': {'type': int, 'default': DEFAULT_MAX_ERROR}, + 'limit': {'type': int, 'default': DEFAULT_LIMIT}, + 'refresh_rate': {'type': int, 'default': DEFAULT_REFRESH_RATE}, + 'retreive_all': {'type': bool, 'default': False}} + + def get(self): + args = self.reqparse_args() + if g.user.refresh_rate: + args['refresh_rate'] = g.user.refresh_rate + + if args.pop('retreive_all', False): + contr = self.wider_controller + else: + contr = self.controller + result = [feed for feed in contr.list_fetchable(**args)] + return result or None, 200 if result else 204 + + +g.api.add_resource(FeedNewAPI, '/feed', endpoint='feed_new.json') +g.api.add_resource(FeedAPI, '/feed/<int:obj_id>', endpoint='feed.json') +g.api.add_resource(FeedsAPI, '/feeds', endpoint='feeds.json') +g.api.add_resource(FetchableFeedAPI, '/feeds/fetchable', + endpoint='fetchable_feed.json') |