<commit_before>package com.alorma.github.basesdk.client;

import android.content.Context;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;

import com.alorma.github.basesdk.ApiClient;

import retrofit.Callback;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.OkClient;
import retrofit.client.Response;
import retrofit.converter.Converter;

public abstract class BaseClient<K> implements Callback<K>, RequestInterceptor, RestAdapter.Log {

    private StoreCredentials storeCredentials;

    protected final Context context;
    private OnResultCallback<K> onResultCallback;
    protected Handler handler;
    private ApiClient client;

    public BaseClient(Context context, ApiClient client) {
        this.client = client;
        this.context = context.getApplicationContext();
        storeCredentials = new StoreCredentials(context);
        try {
            handler = new Handler();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private RestAdapter getRestAdapter() {
        RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder()
                .setClient(new OkClient())
                .setEndpoint(client.getApiEndpoint())
                .setRequestInterceptor(this)
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setLog(this);

        if (customConverter() != null) {
            restAdapterBuilder.setConverter(customConverter());
        }

        return restAdapterBuilder.build();
    }

    public void execute() {
        if (getToken() != null) {
            executeService(getRestAdapter());
        }
    }

    public K executeSync() {
        if (getToken() != null) {
            return executeServiceSync(getRestAdapter());
        }
        return null;
    }

    protected Converter customConverter() {
        return null;
    }

    protected abstract void executeService(RestAdapter restAdapter);

    protected abstract K executeServiceSync(RestAdapter restAdapter);

    @Override
    public void success(final K k, final Response response) {
        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    sendResponse(k, response);
                }
            });
        } else {<commit_msg>Moved handler creation (Not needed when doing Synchronous calls)<commit_after>package com.alorma.github.basesdk.client;

import android.content.Context;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;

import com.alorma.github.basesdk.ApiClient;

import retrofit.Callback;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.OkClient;
import retrofit.client.Response;
import retrofit.converter.Converter;

public abstract class BaseClient<K> implements Callback<K>, RequestInterceptor, RestAdapter.Log {

    private StoreCredentials storeCredentials;

    protected final Context context;
    private OnResultCallback<K> onResultCallback;
    protected Handler handler;
    private ApiClient client;

    public BaseClient(Context context, ApiClient client) {
        this.client = client;
        this.context = context.getApplicationContext();
        storeCredentials = new StoreCredentials(context);
    }

    private RestAdapter getRestAdapter() {
        RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder()
                .setClient(new OkClient())
                .setEndpoint(client.getApiEndpoint())
                .setRequestInterceptor(this)
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setLog(this);

        if (customConverter() != null) {
            restAdapterBuilder.setConverter(customConverter());
        }

        return restAdapterBuilder.build();
    }

    public void execute() {
        try {
            handler = new Handler();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (getToken() != null) {
            executeService(getRestAdapter());
        }
    }

    public K executeSync() {
        if (getToken() != null) {
            return executeServiceSync(getRestAdapter());
        }
        return null;
    }

    protected Converter customConverter() {
        return null;
    }

    protected abstract void executeService(RestAdapter restAdapter);

    protected abstract K executeServiceSync(RestAdapter restAdapter);

    @Override
    public void success(final K k, final Response response) {
        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    sendResponse(k, response);
                }
            });
        } else {
{'fraction_non_alphanumeric': 0.08793918224779125, 'fraction_numerical': 0.0004109307581672488, 'mean_word_length': 2.5097332372025956, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1791181', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1200, 'n_words': 288}