<commit_before>package it.near.sdk.Communication;

import android.content.Context;
import android.preference.PreferenceActivity;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestHandle;
import com.loopj.android.http.ResponseHandlerInterface;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import cz.msebera.android.httpclient.Header;
import cz.msebera.android.httpclient.HttpEntity;
import cz.msebera.android.httpclient.HttpResponse;
import cz.msebera.android.httpclient.auth.AuthenticationException;
import cz.msebera.android.httpclient.entity.StringEntity;
import cz.msebera.android.httpclient.message.BasicHeader;
import cz.msebera.android.httpclient.message.BasicHttpResponse;
import it.near.sdk.GlobalConfig;
import it.near.sdk.R;

/**
 * @author cattaneostefano.
 */
public class NearAsyncHttpClient extends AsyncHttpClient {

    public NearAsyncHttpClient() {
        super();
    }

    public RequestHandle nearGet(Context context, String url, ResponseHandlerInterface responseHandler) throws AuthenticationException {
        return super.get(context,
                buildUrl(context, url),
                getHeaders(context),
                null,
                responseHandler);
    }

    public RequestHandle nearPost(Context context, String url, String requestBody, ResponseHandlerInterface responseHandler) throws AuthenticationException, UnsupportedEncodingException {
        HttpEntity body = new StringEntity(requestBody);
        return super.post(context,
                buildUrl(context, url),
                getHeaders(context),
                body,
                Constants.Headers.jsonApiHeader,
                responseHandler);
    }

    public RequestHandle nearPut(Context context, String url, String requestBody, ResponseHandlerInterface responseHandler) throws UnsupportedEncodingException, AuthenticationException {
        HttpEntity body = new StringEntity(requestBody);
        return super.put(context,
                buildUrl(context, url),
                getHeaders(context),
                body,
                Constants.Headers.jsonApiHeader,
                responseHandler);
    }

    public RequestHandle nearMock(Context context, String url, JsonHttpResponseHandler responseHandlerInterface, int mockResId){
        String mockedString = context.getApplicationContext().getResources().getString(mockResId);
        JSONObject mockedResponse = null;
        try {
            mockedResponse = new JSONObject(mockedString);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        responseHandlerInterface.onSuccess(200, null, mockedResponse);
        return null;
    }

    public RequestHandle nearMock(Context context, String url, String requestBody, JsonHttpResponseHandler responseHandlerInterface, int mockResId){
        return nearMock(context, url, responseHandlerInterface, mockResId);
    }

    /**
 * Return headers for HTTP calls
 * @return a map of headers
 */

   /* @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map headers = new HashMap();
        headers.put(Constants.Headers.accessToken, "bearer " + GlobalConfig.getInstance(mContext).getApiKey());
        headers.put(Constants.Headers.contentType, Constants.Headers.jsonApiHeader);
        headers.put(Constants.Headers.accept, Constants.Headers.jsonApiHeader);
        return headers;
    }*/



    private Header[] getHeaders(Context context) throws AuthenticationException {
        return new Header[]{
                new BasicHeader(Constants.Headers.accessToken, "bearer " + GlobalConfig.getInstance(context).getApiKey()),
                new BasicHeader(Constants.Headers.contentType, Constants.Headers.jsonApiHeader),
                new BasicHeader(Constants.Headers.accept, Constants.Headers.jsonApiHeader)
        };
    }

    private String buildUrl(Context context, String relativeUrl){
        String baseUrl = context.getResources().getString(R.string.API_BASE_URL) + relativeUrl;

        return baseUrl.replace("%5B", "[").replace("%5D", "]");
    }

}
<commit_msg>Use sync/async http client based on thread context, everything is static<commit_after>package it.near.sdk.Communication;

import android.content.Context;
import android.os.Looper;
import android.preference.PreferenceActivity;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestHandle;
import com.loopj.android.http.ResponseHandlerInterface;
import com.loopj.android.http.SyncHttpClient;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import cz.msebera.android.httpclient.Header;
import cz.msebera.android.httpclient.HttpEntity;
import cz.msebera.android.httpclient.HttpResponse;
import cz.msebera.android.httpclient.auth.AuthenticationException;
import cz.msebera.android.httpclient.entity.StringEntity;
import cz.msebera.android.httpclient.message.BasicHeader;
import cz.msebera.android.httpclient.message.BasicHttpResponse;
import it.near.sdk.GlobalConfig;
import it.near.sdk.R;

/**
 * @author cattaneostefano.
 */
public class NearAsyncHttpClient {

    public static AsyncHttpClient syncHttpClient = new SyncHttpClient();
    public static AsyncHttpClient asyncHttpClient = new AsyncHttpClient();


    public static RequestHandle nearGet(Context context, String url, ResponseHandlerInterface responseHandler) throws AuthenticationException {
        return getClient().get(context,
                buildUrl(context, url),
                getHeaders(context),
                null,
                responseHandler);
    }

    private static AsyncHttpClient getClient() {
        if (Looper.myLooper() == null){
            return syncHttpClient;
        }
        return asyncHttpClient;
    }

    public static RequestHandle nearPost(Context context, String url, String requestBody, ResponseHandlerInterface responseHandler) throws AuthenticationException, UnsupportedEncodingException {
        HttpEntity body = new StringEntity(requestBody);
        return getClient().post(context,
                buildUrl(context, url),
                getHeaders(context),
                body,
                Constants.Headers.jsonApiHeader,
                responseHandler);
    }

    public static RequestHandle nearPut(Context context, String url, String requestBody, ResponseHandlerInterface responseHandler) throws UnsupportedEncodingException, AuthenticationException {
        HttpEntity body = new StringEntity(requestBody);
        return getClient().put(context,
                buildUrl(context, url),
                getHeaders(context),
                body,
                Constants.Headers.jsonApiHeader,
                responseHandler);
    }

    public RequestHandle nearMock(Context context, String url, JsonHttpResponseHandler responseHandlerInterface, int mockResId){
        String mockedString = context.getApplicationContext().getResources().getString(mockResId);
        JSONObject mockedResponse = null;
        try {
            mockedResponse = new JSONObject(mockedString);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        responseHandlerInterface.onSuccess(200, null, mockedResponse);
        return null;
    }

    public RequestHandle nearMock(Context context, String url, String requestBody, JsonHttpResponseHandler responseHandlerInterface, int mockResId){
        return nearMock(context, url, responseHandlerInterface, mockResId);
    }

    /**
 * Return headers for HTTP calls
 * @return a map of headers
 */

   /* @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map headers = new HashMap();
        headers.put(Constants.Headers.accessToken, "bearer " + GlobalConfig.getInstance(mContext).getApiKey());
        headers.put(Constants.Headers.contentType, Constants.Headers.jsonApiHeader);
        headers.put(Constants.Headers.accept, Constants.Headers.jsonApiHeader);
        return headers;
    }*/



    private static Header[] getHeaders(Context context) throws AuthenticationException {
        return new Header[]{
                new BasicHeader(Constants.Headers.accessToken, "bearer " + GlobalConfig.getInstance(context).getApiKey()),
                new BasicHeader(Constants.Headers.contentType, Constants.Headers.jsonApiHeader),
                new BasicHeader(Constants.Headers.accept, Constants.Headers.jsonApiHeader)
        };
    }

    private static String buildUrl(Context context, String relativeUrl){
        String baseUrl = context.getResources().getString(R.string.API_BASE_URL) + relativeUrl;

        return baseUrl.replace("%5B", "[").replace("%5D", "]");
    }

}

{'fraction_non_alphanumeric': 0.08737646001796945, 'fraction_numerical': 0.0011230907457322552, 'mean_word_length': 3.395360315893386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4554998', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2199, 'n_words': 483}