<commit_before>package com.tkporter.fabrictwitterkit;

import android.app.Activity;
import android.app.IntentService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.Callback;

import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.tweetcomposer.TweetComposer;
import com.twitter.sdk.android.tweetcomposer.TweetUploadService;

public class FabricTwitterKitModule extends ReactContextBaseJavaModule implements ActivityEventListener {

    private final ReactApplicationContext reactContext;
    private Callback callback = null;
    //112 is the average ascii value for every letter in 'twitter'
    private static final int REQUEST_CODE = 112112;

    public FabricTwitterKitModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;
    }


    @Override
    public String getName() {
        return "FabricTwitterKit";
    }


    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                sendCallback(true, false, false);
            } else if (resultCode == Activity.RESULT_CANCELED) {
                sendCallback(false, true, false);
            }
        }
    }

    public void sendCallback(Boolean completed, Boolean cancelled, Boolean error) {
        if (callback != null) {
            callback.invoke(completed, cancelled, error);
            callback = null;
        }
    }

    @ReactMethod
    public void composeTweet(ReadableMap options, final Callback callback) {
        try {
            this.callback = callback;

            String body = options.hasKey("body") ? options.getString("body") : "";

            TweetComposer.Builder builder = new TweetComposer.Builder(reactContext).text(body);
            final Intent intent = builder.createIntent();
            reactContext.startActivityForResult(intent, REQUEST_CODE, intent.getExtras());

        } catch (Exception e) {
            //error!
            sendCallback(false, false, true);
            throw e;
        }
    }

}
<commit_msg>Added more twitter functions<commit_after>package com.tkporter.fabrictwitterkit;

import android.app.Activity;
import android.content.Intent;

import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.google.gson.Gson;

import com.twitter.sdk.android.tweetcomposer.TweetComposer;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterLoginButton;
import com.twitter.sdk.android.core.TwitterApiClient;
import com.twitter.sdk.android.core.models.User;
import retrofit.http.GET;
import retrofit.http.Query;


public class FabricTwitterKitModule extends ReactContextBaseJavaModule implements ActivityEventListener {

    public TwitterLoginButton loginButton;
    private final ReactApplicationContext reactContext;
    private Callback callback = null;
    //112 is the average ascii value for every letter in 'twitter'
    private static final int REQUEST_CODE = 112112;

    public FabricTwitterKitModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;
    }


    @Override
    public String getName() {
        return "FabricTwitterKit";
    }


    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                sendCallback(true, false, false);
            } else if (resultCode == Activity.RESULT_CANCELED) {
                sendCallback(false, true, false);
            }
            if (loginButton != null) {
                loginButton.onActivityResult(requestCode, resultCode, data);
                loginButton = null;
            }
        }
    }

    public void sendCallback(Boolean completed, Boolean cancelled, Boolean error) {
        if (callback != null) {
            callback.invoke(completed, cancelled, error);
            callback = null;
        }
    }

    @ReactMethod
    public void composeTweet(ReadableMap options, final Callback callback) {
        try {
            this.callback = callback;

            String body = options.hasKey("body") ? options.getString("body") : "";

            TweetComposer.Builder builder = new TweetComposer.Builder(reactContext).text(body);
            final Intent intent = builder.createIntent();
            reactContext.startActivityForResult(intent, REQUEST_CODE, intent.getExtras());

        } catch (Exception e) {
            //error!
            sendCallback(false, false, true);
            throw e;
        }
    }

    @ReactMethod
    public void login(final Callback callback) {

        loginButton = new TwitterLoginButton(reactContext);
        loginButton.setCallback(new com.twitter.sdk.android.core.Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> sessionResult) {
                WritableMap result = new WritableNativeMap();
                result.putString("authToken", sessionResult.data.getAuthToken().token);
                result.putString("authTokenSecret",sessionResult.data.getAuthToken().secret);
                result.putString("userID", sessionResult.data.getUserId()+"");
                result.putString("userName", sessionResult.data.getUserName());
                callback.invoke(null, result);
            }

            @Override
            public void failure(TwitterException exception) {
                exception.printStackTrace();
                callback.invoke(exception.getMessage());
            }
        });

        loginButton.performClick();
    }

    @ReactMethod
    public void fetchProfile(final Callback callback) {

        try {
            ReactNativeFabricApiClient client = new ReactNativeFabricApiClient(TwitterCore.getInstance().getSessionManager().getActiveSession());
            client.getCustomService().show(TwitterCore.getInstance().getSessionManager().getActiveSession().getUserId(), new com.twitter.sdk.android.core.Callback<User>() {
                @Override
                public void success(Result<User> result) {
                    Gson gson = new Gson();
                    WritableMap map = gson.fromJson(gson.toJson(result), WritableMap.class);
                    callback.invoke(null, map);
                }

                @Override
                public void failure(TwitterException exception) {
                    exception.printStackTrace();
                    TwitterCore.getInstance().getSessionManager().clearActiveSession();
                    callback.invoke(exception.getMessage());
                }
            });
        } catch (Exception ex) {
            callback.invoke(ex.getMessage());
        }
    }

    @ReactMethod
    public void logOut() {
        TwitterCore.getInstance().logOut();
    }

    private boolean hasValidKey(String key, ReadableMap options) {
        return options.hasKey(key) && !options.isNull(key);
    }



    class ReactNativeFabricApiClient extends TwitterApiClient {
        public ReactNativeFabricApiClient(TwitterSession session) {
            super(session);
        }

        /**
         * Provide CustomService with defined endpoints
         */
        public CustomService getCustomService() {
            return getService(CustomService.class);
        }
    }

    // example users/show service endpoint
    interface CustomService {
        @GET("/1.1/users/show.json")
        void show(@Query("user_id") long id, com.twitter.sdk.android.core.Callback<User> cb);
    }

}

{'fraction_non_alphanumeric': 0.09379005009903298, 'fraction_numerical': 0.002330187580100198, 'mean_word_length': 2.7354221061792865, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2772760', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2148, 'n_words': 453}