1from allauth.socialaccount.providers.base import ProviderAccount
2from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
3
4
5class BitlyAccount(ProviderAccount):
6    def get_profile_url(self):
7        return self.account.extra_data.get('profile_url')
8
9    def get_avatar_url(self):
10        return self.account.extra_data.get('profile_image')
11
12    def to_str(self):
13        dflt = super(BitlyAccount, self).to_str()
14        return '%s (%s)' % (
15            self.account.extra_data.get('full_name', ''),
16            dflt,
17        )
18
19
20class BitlyProvider(OAuth2Provider):
21    id = 'bitly'
22    name = 'Bitly'
23    account_class = BitlyAccount
24
25    def extract_uid(self, data):
26        return str(data['login'])
27
28    def extract_common_fields(self, data):
29        return dict(username=data['login'],
30                    name=data.get('full_name'))
31
32
33provider_classes = [BitlyProvider]
34