import foauth.providers


class Flickr(foauth.providers.OAuth1):
    # General info about the provider
    provider_url = 'http://www.flickr.com/'
    docs_url = 'http://www.flickr.com/services/api/'
    category = 'Pictures'

    # URLs to interact with the API
    request_token_url = 'http://www.flickr.com/services/oauth/request_token'
    authorize_url = 'http://www.flickr.com/services/oauth/authorize'
    access_token_url = 'http://www.flickr.com/services/oauth/access_token'
    api_domain = 'secure.flickr.com'

    available_permissions = [
        (None, 'access your public and private photos'),
        ('write', 'upload, edit and replace your photos'),
        ('delete', 'upload, edit, replace and delete your photos'),
    ]
    permissions_widget = 'radio'

    def get_authorize_params(self, redirect_uri, scopes):
        params = super(Flickr, self).get_authorize_params(redirect_uri, scopes)

        if any(scopes):
            params['perms'] = scopes[0]
        else:
            params['perms'] = 'read'

        return params

    def get_user_id(self, key):
        url = u'/services/rest/?method=flickr.people.getLimits'
        url += u'&format=json&nojsoncallback=1'
        r = self.api(key, self.api_domain, url)
        return r.json()[u'person'][u'nsid']

@@ -911,37 +911,8 @@
 es)%0A
-%0A        if any(scopes):%0A    
     
@@ -946,60 +946,19 @@
 s%5B0%5D
-%0A        else:%0A            params%5B'perms'%5D =
+ or
  'read'%0A
 %0A   
@@ -953,17 +953,16 @@
  'read'%0A
-%0A
         

Simplify Flickr's scope handling a bit