Ejemplo n.º 1
0
    def __init__(self, api_key, api_secret):
        """
    Create a new FlickrApp object.

    Remember, this class is not meant to be used on it's own. Rather
    it is a base class that you subclass in your own application. For
    example:

    	class MyFlickrApp (FlickrApp) :

          def init (self) :
            api_key = "this part is left to you"
            api_secret = "to squirt in to your application"

            FlickrApp.__init__(self, api_key, api_secret)
    """

        webapp.RequestHandler.__init__(self)

        self._api_key = api_key
        self._api_secret = api_secret

        self.api = flickr.API(self._api_key, self._api_secret)
        self.user = None

        self.perms_map = {'read': 1, 'write': 2, 'delete': 3}

        self.crypto = None
        self.canhas_crypto()
Ejemplo n.º 2
0
  def do_flickr_auth (self, min_perms=None, redir=None) :

    """
    This method will generate and redirect the user to the Flickr
    API Auth endpoint where the user will be prompted to approve
    your request for a Flickr token (with 'min_perms' permissions).
    """

    args = {'api_key' : self._api_key}

    extra = []

    if redir :
      extra.append('redir=%s' % redir)
    else :
      extra.append('redir=%s' % urllib.quote(self.request.path))

    crumb = self.generate_crumb(None, 'flickrauth', 5)
    extra.append('crumb=%s' % urllib.quote(crumb))

    args['extra'] = "&".join(extra)

    if min_perms:
      args['perms'] = min_perms

    sig = flickr.sign_args(self._api_secret, args)

    args['api_sig'] = sig

    query = urllib.urlencode(args)

    url = "http://www.flickr.com/services/auth/?%s" % query

    self.redirect(url)
Ejemplo n.º 3
0
    def do_flickr_auth(self, min_perms=None, redir=None):
        """
    This method will generate and redirect the user to the Flickr
    API Auth endpoint where the user will be prompted to approve
    your request for a Flickr token (with 'min_perms' permissions).
    """

        args = {'api_key': self._api_key}

        extra = []

        if redir:
            extra.append('redir=%s' % redir)
        else:
            extra.append('redir=%s' % urllib.quote(self.request.path))

        crumb = self.generate_crumb(None, 'flickrauth', 5)
        extra.append('crumb=%s' % urllib.quote(crumb))

        args['extra'] = "&".join(extra)

        if min_perms:
            args['perms'] = min_perms

        sig = flickr.sign_args(self._api_secret, args)

        args['api_sig'] = sig

        query = urllib.urlencode(args)

        url = "http://www.flickr.com/services/auth/?%s" % query

        self.redirect(url)
Ejemplo n.º 4
0
    def generate_signature(self):

        required = ('crumb', )

        skip_list = ('crumb', 'format', 'method')

        if not self.ensure_args(required):
            return

        if not self.ensure_crumb('method=signature'):
            return

        query = self.request.queryvars
        args = {}

        for key, value in query.items():

            if key in skip_list:
                continue

            args[key] = value

        sig = flickr.sign_args(self._api_secret, args)

        self.api_ok({'signature': sig})
        return
Ejemplo n.º 5
0
    def generate_signature (self) :

        required = ('crumb',)

        skip_list = ('crumb', 'format', 'method')

        if not self.ensure_args(required) :
            return

        if not self.ensure_crumb('method=signature') :
            return

        query = self.request.queryvars
        args = {}

        for key, value in query.items() :

            if key in skip_list :
                continue

            args[ key ] = value            

        sig = flickr.sign_args(self._api_secret, args)

        self.api_ok({'signature' : sig})
        return
Ejemplo n.º 6
0
  def proxy_api_call (self, method, args, ttl=0) :

    args['method'] = method
    sig = flickr.sign_args(self._api_secret, args)

    memkey = "%s_%s" % (method, sig)
    cache = memcache.get(memkey)

    if cache :
      return cache

    rsp = self.api_call(method, args)

    if not rsp :
      return None

    if rsp['stat'] == 'ok' :
      memcache.add(memkey, rsp, ttl)

    return rsp
Ejemplo n.º 7
0
    def proxy_api_call(self, method, args, ttl=0):

        args['method'] = method
        sig = flickr.sign_args(self._api_secret, args)

        memkey = "%s_%s" % (method, sig)
        cache = memcache.get(memkey)

        if cache:
            return cache

        rsp = self.api_call(method, args)

        if not rsp:
            return None

        if rsp['stat'] == 'ok':
            memcache.add(memkey, rsp, ttl)

        return rsp
Ejemplo n.º 8
0
 def flickr_sign_args (self, args) :
   return flickr.sign_args(self._api_secret, args)
Ejemplo n.º 9
0
 def flickr_sign_args(self, args):
     return flickr.sign_args(self._api_secret, args)