示例#1
0
from flask_restplus import Resource

from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.oauth import oauth
from webapp.podcasts.progress import PlaybackProgress

ns = api.namespace("episodes")

progress_parser = api.parser()
progress_parser.add_argument(name="progress", location="form", type=int)
@ns.route("/<string:episodeId>/progress")
class ProgressResource(Resource):
    """This resource represents the current user's listening progress on an episode."""
    @api.doc(id="getProgress")
    def get(self, episodeId):
        valid, req = oauth.verify_request([])
        if not valid:
            raise AuthorizationRequired()
        user = req.user

        return {"progress": PlaybackProgress.get_progress(user_id=user.id, episode_id=episodeId)}

    @api.doc(id="setProgress", parser=progress_parser)
    def post(self, episodeId):
        valid, req = oauth.verify_request([])
        if not valid:
            raise AuthorizationRequired()

        user = req.user
示例#2
0
                raise AuthorizationRequired()
            user = req.user
        else:
            user = User.get_by_id(userId)

        if not user:
            abort(404, message="User not found: %s." % userId)
            return

        # make sure the client is authorized to get the user's email.
        valid, req = oauth.verify_request(["userinfo/email"])
        if not (valid and (userId == "me" or userId == req.user.id)):
            return AttributeHider(user, ["primary_email"])
        return user

followParser = api.parser()
followParser.add_argument(name="otherUser", required=True, location="values")

@ns.route("/<string:userId>/following", endpoint="following")
@api.doc({"userId": "A user ID, or \"me\" without quotes, for the user associated with the provided access token."})
class FollowingResource(Resource):
    @api.marshal_with(success_status)
    @api.doc(id="follow", security=[{"javascript":[]}, {"server":[]}], parser=followParser)
    def post(self, userId):
        if userId == "me":
            valid, req = oauth.verify_request([])
            follow = followParser.parse_args()["otherUser"].split(",")
            if not valid:
                raise AuthorizationRequired()
            user = req.user
            others = [User.get_by_id(f) for f in follow]
示例#3
0
from flask_restplus import Resource

from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.oauth import oauth
from webapp.api.graphql.schemas import schema

from debug_resources import dictify

ns = api.namespace("graphql")

graphql_parser = api.parser()
graphql_parser.add_argument(name="query", location="form", type=str)


@ns.route("/query")
class GraphqlResource(Resource):
    @api.doc(id="query", parser=graphql_parser)
    def post(self):
        valid, req = oauth.verify_request([])
        result = schema.execute(graphql_parser.parse_args()["query"])
        return {"data": result.data, "errors": [dictify(e) for e in result.errors] if result.errors else None}
示例#4
0
from flask_restplus import Resource

from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.oauth import oauth
from webapp.api.graphql.schemas import schema

from debug_resources import dictify

ns = api.namespace("graphql")

graphql_parser = api.parser()
graphql_parser.add_argument(name="query", location="form", type=str)


@ns.route("/query")
class GraphqlResource(Resource):
    @api.doc(id="query", parser=graphql_parser)
    def post(self):
        valid, req = oauth.verify_request([])
        result = schema.execute(graphql_parser.parse_args()["query"])
        return {
            "data":
            result.data,
            "errors":
            [dictify(e) for e in result.errors] if result.errors else None
        }
示例#5
0
from flask_restplus import Resource

from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.oauth import oauth
from webapp.podcasts.progress import PlaybackProgress

ns = api.namespace("episodes")

progress_parser = api.parser()
progress_parser.add_argument(name="progress", location="form", type=int)


@ns.route("/<string:episodeId>/progress")
class ProgressResource(Resource):
    """This resource represents the current user's listening progress on an episode."""
    @api.doc(id="getProgress")
    def get(self, episodeId):
        valid, req = oauth.verify_request([])
        if not valid:
            raise AuthorizationRequired()
        user = req.user

        return {
            "progress":
            PlaybackProgress.get_progress(user_id=user.id,
                                          episode_id=episodeId)
        }

    @api.doc(id="setProgress", parser=progress_parser)
    def post(self, episodeId):
示例#6
0
from flask import abort
from flask_restplus import Resource
from flask_restplus import fields
from flask_restplus import abort

from webapp.utils import AttributeHider
from webapp.api.oauth import oauth
from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.representations import podcast_full_fields, podcast_fields, episode_list
from webapp.podcasts import Podcast

ns = api.namespace("podcasts")

podcast_parser = api.parser()
podcast_parser.add_argument(name="fetch", required=False, location="args")
podcast_parser.add_argument(name="maxEpisodes",
                            required=False,
                            location="args",
                            type=int,
                            default=30)


@ns.route("/<path:podcastId>", endpoint="podcast")
@api.doc(
    params={
        "podcastId":
        "A podcast's id (the same as its URL. If the API returns a podcast with a different URL, it means the podcast has moved.",
        "fetch": "Whether to fetch the podcast if it's not in the database.",
        "maxEpisodes": "The maximum number of episodes to return."