"""Configuration and marshaling of FeedUnits statuses.""" from flask_restful import fields from flask_restful import marshal_with from flask_restful import Resource from feed_status.connectors import snowflake feed_units_fields = { 'data': fields.Nested( { 'feed_id': fields.String(attribute='feed_id'), 'units': fields.List( fields.Nested( { 'filedate': fields.String, 'units': fields.Integer })) }) } feed_units_all_fields = { 'data': fields.List( fields.Nested( { 'feed_id': fields.String(attribute='feed_id'), 'licensor': fields.String(attribute='licensor'), 'units': fields.List( fields.Nested( { 'filedate': fields.String, 'units': fields.Integer })) })) } class FeedUnits(Resource): """Provide data for specific feed.""" @marshal_with(feed_units_fields) def get(self, feed_id, licensor): """Marshal specific FeedUnits data. Args: feed_id (str): specific feed of interest. licensor (str): specific data licensor. Returns: dict: json payload for feed units. """ units = snowflake.get_units(feed_id, licensor) if not units: return {'message': 'units not found'}, 404 return { 'data': { 'feed_id': feed_id, 'units': units } }, 200 class AllFeedsUnits(Resource): """Provide data for all the feeds.""" @marshal_with(feed_units_all_fields) def get(self): """Marshal specific FeedUnits data. Returns: dict: json payload for feeds units. """ units = snowflake.get_units_for_all_feeds() if not units: return {'message': 'units not found'}, 404 return { 'data': units }, 200