<commit_before>package org.gdg.frisbee.android.api;

import android.support.annotation.Nullable;

import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.Person;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import org.gdg.frisbee.android.Const;
import org.gdg.frisbee.android.app.App;
import org.joda.time.DateTime;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import timber.log.Timber;

/**
 * Created by tasomaniac on 27/7/15.
 */
public class PlusPersonDownloader implements Interceptor {

    private static final Pattern mPlusPattern
            = Pattern.compile("http[s]?:\\/\\/plus\\..*google\\.com.*(\\+[a-zA-Z] +|[0-9]{21}).*");
    private Plus plusClient;

    public PlusPersonDownloader(Plus plusClient) {
        this.plusClient = plusClient;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        Matcher matcher = mPlusPattern.matcher(request.urlString());
        if (!matcher.matches()) {
            return chain.proceed(request);
        }

        String gplusId = matcher.group(1);
        Person person = getPersonSync(gplusId);
        if (person != null && person.getImage() != null && person.getImage().getUrl() != null) {
            return chain.proceed(request.newBuilder().url(person.getImage().getUrl()).build());
        }

        return null;
    }

    @Nullable
    public Person getPersonSync(final String gplusId) {

        final String cacheUrl = Const.CACHE_KEY_PERSON + gplusId;
        Object cachedPerson = App.getInstance().getModelCache().get(cacheUrl);
        Person person = null;

        if (cachedPerson instanceof Person) {
            person = (Person) cachedPerson;
            if (person.getImage() != null) {
                return person;
            }
        }
        if (cachedPerson != null) {
            App.getInstance().getModelCache().remove(cacheUrl);
        }

        try {
            Plus.People.Get request = plusClient.people().get(gplusId);
            request.setFields("aboutMe,cover/coverPhoto/url,image/url,displayName,tagline,urls");
            person = request.execute();
            App.getInstance().getModelCache().put(cacheUrl, person, DateTime.now().plusDays(2));
        } catch (IOException e) {
            Timber.e(e, "Error while getting profile URL.");
        }

        return person;
    }
}
<commit_msg>Quality images are brought back.<commit_after>package org.gdg.frisbee.android.api;

import android.support.annotation.Nullable;

import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.Person;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import org.gdg.frisbee.android.Const;
import org.gdg.frisbee.android.app.App;
import org.joda.time.DateTime;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import timber.log.Timber;

/**
 * Created by tasomaniac on 27/7/15.
 */
public class PlusPersonDownloader implements Interceptor {

    private static final Pattern mPlusPattern
            = Pattern.compile("http[s]?:\\/\\/plus\\..*google\\.com.*(\\+[a-zA-Z] +|[0-9]{21}).*");
    private Plus plusClient;

    public PlusPersonDownloader(Plus plusClient) {
        this.plusClient = plusClient;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        Matcher matcher = mPlusPattern.matcher(request.urlString());
        if (!matcher.matches()) {
            return chain.proceed(request);
        }

        String gplusId = matcher.group(1);
        Person person = getPersonSync(gplusId);
        if (person != null && person.getImage() != null && person.getImage().getUrl() != null) {
            String imageUrl = person.getImage().getUrl().replace("sz=50", "sz=196");
            return chain.proceed(request.newBuilder().url(imageUrl).build());
        }

        return null;
    }

    @Nullable
    public Person getPersonSync(final String gplusId) {

        final String cacheUrl = Const.CACHE_KEY_PERSON + gplusId;
        Object cachedPerson = App.getInstance().getModelCache().get(cacheUrl);
        Person person = null;

        if (cachedPerson instanceof Person) {
            person = (Person) cachedPerson;
            if (person.getImage() != null) {
                return person;
            }
        }
        if (cachedPerson != null) {
            App.getInstance().getModelCache().remove(cacheUrl);
        }

        try {
            Plus.People.Get request = plusClient.people().get(gplusId);
            request.setFields("aboutMe,cover/coverPhoto/url,image/url,displayName,tagline,urls");
            person = request.execute();
            App.getInstance().getModelCache().put(cacheUrl, person, DateTime.now().plusDays(2));
        } catch (IOException e) {
            Timber.e(e, "Error while getting profile URL.");
        }

        return person;
    }
}

{'fraction_non_alphanumeric': 0.13073038073038074, 'fraction_numerical': 0.005244755244755245, 'mean_word_length': 2.677857142857143, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5397388', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1470, 'n_words': 290}