filmaster-api-sample / samplewebapp.py

import webapp2
import pprint, json, urllib2, cgi

from utils import gae
from filmaster_auth import FilmasterOAuthClient

import settings

import logging
logger = logging.getLogger(__name__)

class FilmasterClientMixin(object):
    def dispatch(self):
        self.filmaster_client = FilmasterOAuthClient(
                settings.FILMASTER_APP_KEY,
                settings.FILMASTER_APP_SECRET,
        )
        return super(FilmasterClientMixin, self).dispatch()

class SampleApp(FilmasterClientMixin, gae.BaseHandler):
    def authorize(self):
        request_token = self.filmaster_client.fetch_request_token()
        self.session['request_token'] = str(request_token)
        authorize_url = self.filmaster_client.get_authorize_url(request_token, callback_url = self.request.host_url+'/auth-cb/')
        self.response.status = 302
        self.response.location = authorize_url

    def get(self):
        access_token = self.session.get('access_token')
        if access_token is None:
            return self.authorize()
        self.filmaster_client.set_access_token(access_token)
        profile = self.filmaster_client.get('/1.1/profile/')
        out = pprint.pformat(profile)

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write(out)

    class AppError(Exception):
        pass

class SampleAppAuth(FilmasterClientMixin, gae.BaseHandler):
    def get(self):
        request_token = self.session['request_token']
        verifier = self.request.params.get('oauth_verifier')
        access_token = self.filmaster_client.fetch_access_token(request_token, verifier)
        self.session['access_token'] = str(access_token)
        self.response.status = 302
        self.response.location = '/'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.