<commit_before>"""
MapMyFitness OAuth2 backend, docs at:
    http://psa.matiasaguirre.net/docs/backends/mapmyfitness.html
"""
from social.backends.oauth import BaseOAuth2


class MapMyFitnessOAuth2(BaseOAuth2):
    """MapMyFitness OAuth authentication backend"""
    name = 'mapmyfitness'
    AUTHORIZATION_URL = 'https://www.mapmyfitness.com/v7.0/oauth2/authorize'
    ACCESS_TOKEN_URL = 'https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token'
    REQUEST_TOKEN_METHOD = 'POST'
    ACCESS_TOKEN_METHOD = 'POST'
    REDIRECT_STATE = False
    EXTRA_DATA = [
        ('refresh_token', 'refresh_token'),
    ]

    def auth_headers(self):
        key = self.get_key_and_secret()[0]
        return {
            'Api-Key': key
        }

    def get_user_id(self, details, response):
        return response['id']

    def get_user_details(self, response):
        first = response.get('first_name', '')
        last = response.get('last_name', '')
        full = (first + last).strip()
        return {
            'username': response['username'],
            'email': response['email'],
            'fullname': full,
            'first_name': first,
            'last_name': last,
        }

    def user_data(self, access_token, *args, **kwargs):
        key = self.get_key_and_secret()[0]
        url = 'https://oauth2-api.mapmyapi.com/v7.0/user/self/'
        headers = {
            'Authorization': 'Bearer {}'.format(access_token),
            'Api-Key': key
        }
        return self.get_json(url, headers=headers)        <commit_msg>Python 2.6-friendly string formatting.<commit_after>"""
MapMyFitness OAuth2 backend, docs at:
    http://psa.matiasaguirre.net/docs/backends/mapmyfitness.html
"""
from social.backends.oauth import BaseOAuth2


class MapMyFitnessOAuth2(BaseOAuth2):
    """MapMyFitness OAuth authentication backend"""
    name = 'mapmyfitness'
    AUTHORIZATION_URL = 'https://www.mapmyfitness.com/v7.0/oauth2/authorize'
    ACCESS_TOKEN_URL = 'https://oauth2-api.mapmyapi.com/v7.0/oauth2/access_token'
    REQUEST_TOKEN_METHOD = 'POST'
    ACCESS_TOKEN_METHOD = 'POST'
    REDIRECT_STATE = False
    EXTRA_DATA = [
        ('refresh_token', 'refresh_token'),
    ]

    def auth_headers(self):
        key = self.get_key_and_secret()[0]
        return {
            'Api-Key': key
        }

    def get_user_id(self, details, response):
        return response['id']

    def get_user_details(self, response):
        first = response.get('first_name', '')
        last = response.get('last_name', '')
        full = (first + last).strip()
        return {
            'username': response['username'],
            'email': response['email'],
            'fullname': full,
            'first_name': first,
            'last_name': last,
        }

    def user_data(self, access_token, *args, **kwargs):
        key = self.get_key_and_secret()[0]
        url = 'https://oauth2-api.mapmyapi.com/v7.0/user/self/'
        headers = {
            'Authorization': 'Bearer {0}'.format(access_token),
            'Api-Key': key
        }
        return self.get_json(url, headers=headers)        
{'fraction_non_alphanumeric': 0.1367713004484305, 'fraction_numerical': 0.011210762331838564, 'mean_word_length': 2.5129358830146233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4530806', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1015, 'n_words': 171}