<commit_before>package com.irunninglog.strava.impl;

import com.irunninglog.api.factory.IFactory;
import com.irunninglog.api.security.AuthnException;
import com.irunninglog.api.security.IUser;
import com.irunninglog.strava.IStravaAthlete;
import com.irunninglog.strava.IStravaService;
import javastrava.api.v3.auth.AuthorisationService;
import javastrava.api.v3.auth.impl.retrofit.AuthorisationServiceImpl;
import javastrava.api.v3.auth.model.Token;
import javastrava.api.v3.model.StravaAthlete;
import javastrava.api.v3.rest.API;
import org.springframework.core.env.Environment;

final class StravaServiceImpl implements IStravaService {

    private final int id;
    private final String secret;

    private final IFactory factory;

    StravaServiceImpl(Environment environment, IFactory factory) {
        this.factory = factory;

        String config = environment.getRequiredProperty("strava");
        String [] tokens = config.split("\\|");
        id = Integer.parseInt(tokens[0]);
        secret = tokens[1];
    }

    @Override
    public IUser userFromCode(String code) throws AuthnException {
        AuthorisationService service = new AuthorisationServiceImpl();
        Token token= service.tokenExchange(id, secret, code);
        return factory.get(IUser.class)
                .setId(token.getAthlete().getId())
                .setUsername(token.getAthlete().getEmail())
                .setToken(token.getToken());
    }

    @Override
    public IUser userFromToken(String token) throws AuthnException {
        Token apiToken = new Token();
        apiToken.setToken(token);
        API api = new API(apiToken);

        StravaAthlete athlete = api.getAuthenticatedAthlete();

        return factory.get(IUser.class)
                .setId(athlete.getId())
                .setUsername(athlete.getEmail())
                .setToken(token);
    }

    @Override
    public IStravaAthlete athlete(IUser user) {
        return null;
    }

}<commit_msg>#74 - API profile endpoint<commit_after>package com.irunninglog.strava.impl;

import com.irunninglog.api.factory.IFactory;
import com.irunninglog.api.security.AuthnException;
import com.irunninglog.api.security.IUser;
import com.irunninglog.strava.IStravaAthlete;
import com.irunninglog.strava.IStravaService;
import javastrava.api.v3.auth.AuthorisationService;
import javastrava.api.v3.auth.impl.retrofit.AuthorisationServiceImpl;
import javastrava.api.v3.auth.model.Token;
import javastrava.api.v3.model.StravaAthlete;
import javastrava.api.v3.rest.API;
import org.springframework.core.env.Environment;

final class StravaServiceImpl implements IStravaService {

    private final int id;
    private final String secret;

    private final IFactory factory;

    StravaServiceImpl(Environment environment, IFactory factory) {
        this.factory = factory;

        String config = environment.getRequiredProperty("strava");
        String [] tokens = config.split("\\|");
        id = Integer.parseInt(tokens[0]);
        secret = tokens[1];
    }

    @Override
    public IUser userFromCode(String code) throws AuthnException {
        AuthorisationService service = new AuthorisationServiceImpl();
        Token token= service.tokenExchange(id, secret, code);
        return factory.get(IUser.class)
                .setId(token.getAthlete().getId())
                .setUsername(token.getAthlete().getEmail())
                .setToken(token.getToken());
    }

    @Override
    public IUser userFromToken(String token) throws AuthnException {
        Token apiToken = new Token();
        apiToken.setToken(token);
        API api = new API(apiToken);

        StravaAthlete athlete = api.getAuthenticatedAthlete();

        return factory.get(IUser.class)
                .setId(athlete.getId())
                .setUsername(athlete.getEmail())
                .setToken(token);
    }

    @Override
    public IStravaAthlete athlete(IUser user) {
        Token apiToken = new Token();
        apiToken.setToken(user.getToken());

        API api = new API(apiToken);
        StravaAthlete stravaAthlete = api.getAuthenticatedAthlete();

        return factory.get(IStravaAthlete.class)
                .setId(stravaAthlete.getId())
                .setFirstname(stravaAthlete.getFirstname())
                .setLastname(stravaAthlete.getLastname())
                .setEmail(stravaAthlete.getEmail()).setAvatar(stravaAthlete.getProfileMedium());
    }

}
{'fraction_non_alphanumeric': 0.10216021602160216, 'fraction_numerical': 0.0036003600360036, 'mean_word_length': 3.063071297989031, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1922618', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1310, 'n_words': 237}