예제 #1
0
import logging

from flask import request
from flask_restplus import Resource
from flask_restplus import fields
from flask_restplus import abort

from webapp.api.oauth import oauth
from webapp.api.blueprint import api
from webapp.api.representations import subscribe_result_fields
from webapp.podcasts import SubscribeResult

ns = api.namespace("subscriptionResults")

@ns.route("/<string:resultId>", endpoint="subscribeResult")
@api.doc(params={"resultId": "A subscription result ID,"})
class SubscriptionResultResource(Resource):
    """Resource representing the result of a podcast subscription request. Such
    requests may take a while, because we might need to fetch the feed if we
    don't already have it in the db.."""

    @api.marshal_with(subscribe_result_fields)
    @api.doc(id="getSubscriptionResult", security=[{"javascript":[]}, {"server":[]}])
    def get(self, resultId):
        """Get a subscription result."""
        return SubscribeResult.get(resultId)
예제 #2
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
예제 #3
0
import logging

from flask import request
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 user_fields, subscribe_fields, podcast_fields, success_status, subscribe_result_fields
from webapp.users import User
from webapp.users.auth import session

ns = api.namespace("users")


@ns.route("/<string:userId>", endpoint="user")
@api.doc(params={"userId": "A user ID, or \"me\" without quotes, for the user associated with the provided access token."})
class UserResource(Resource):
    """Resource representing a single user."""
    @api.marshal_with(user_fields)
    @api.doc(id="getUser", security=[{"javascript":[]}, {"server":[]}])
    def get(self, userId):
        """Get a user."""
        if userId == "me":
            valid, req = oauth.verify_request(["publicuserinfo/read"])
            if not valid:
                raise AuthorizationRequired()
            user = req.user
예제 #4
0
import logging

from flask import request
from flask_restplus import Resource
from flask_restplus import fields
from flask_restplus import abort

from webapp.api.oauth import oauth
from webapp.api.blueprint import api
from webapp.api.representations import subscribe_result_fields
from webapp.podcasts import SubscribeResult

ns = api.namespace("subscriptionResults")


@ns.route("/<string:resultId>", endpoint="subscribeResult")
@api.doc(params={"resultId": "A subscription result ID,"})
class SubscriptionResultResource(Resource):
    """Resource representing the result of a podcast subscription request. Such
    requests may take a while, because we might need to fetch the feed if we
    don't already have it in the db.."""
    @api.marshal_with(subscribe_result_fields)
    @api.doc(id="getSubscriptionResult",
             security=[{
                 "javascript": []
             }, {
                 "server": []
             }])
    def get(self, resultId):
        """Get a subscription result."""
        return SubscribeResult.get(resultId)
예제 #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.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}
예제 #6
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
        }
예제 #7
0
from flask_restplus import Resource

from webapp.api.oauth import AuthorizationRequired
from webapp.api.blueprint import api
from webapp.api.oauth import oauth

ns = api.namespace("debug_")


def dictify(d, seen=None, depth=0):
    try:
        isinstance(d, object)
    except:
        return "can't call isinstance on this."
    seen = seen or []
    if isinstance(d, (
            basestring,
            int,
            float,
            bool,
            type(None),
    )):
        return d
    if depth > 4:
        return {"@type": type(d), "@str": str(d), "m": True}
    seen.append(d)

    if isinstance(d, dict):
        d = dict(d)
        for key in d:
            try:
예제 #8
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):
예제 #9
0
import urllib
import logging

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.",