<commit_before>/*
 * Copyright (C) 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmura.android.reddit.net;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Scanner;

import javax.net.ssl.HttpsURLConnection;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.JsonReader;
import android.util.Log;

import com.btmura.android.reddit.BuildConfig;

public class RedditApi {

    public static final String TAG = "RedditApi";

    private static final String CHARSET = "UTF-8";
    private static final String CONTENT_TYPE =
            "application/x-www-form-urlencoded;charset=" + CHARSET;
    static final String USER_AGENT = "reddit by brian v2.2 by /u/btmura";

    private static final boolean LOG_RESPONSES = BuildConfig.DEBUG && !true;

    public static AccountInfoResult aboutMe(String cookie) throws IOException {
        return getAccountResult(Urls.aboutMe(), cookie);
    }

    public static AccountInfoResult aboutUser(String user, String cookie) throws IOException {
        return getAccountResult(Urls.aboutUser(user), cookie);
    }

    private static AccountInfoResult getAccountResult(CharSequence url, String cookie)
            throws IOException {
        HttpURLConnection conn = null;
        InputStream in = null;
        try {
            conn = connect(url, cookie, true, false);
            in = new BufferedInputStream(conn.getInputStream());
            return AccountInfoResult.fromJsonReader(new JsonReader(new InputStreamReader(in)));
        } finally {
            close(in, conn);
        }
    }

    public static Result comment(String thingId, String text, String cookie, String modhash)
            throws IOException {
        return postData(Urls.comments(), Urls.commentsQuery(thingId, text, modhash), cookie);<commit_msg>Update user agent version string<commit_after>/*
 * Copyright (C) 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmura.android.reddit.net;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Scanner;

import javax.net.ssl.HttpsURLConnection;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.JsonReader;
import android.util.Log;

import com.btmura.android.reddit.BuildConfig;

public class RedditApi {

    public static final String TAG = "RedditApi";

    private static final String CHARSET = "UTF-8";
    private static final String CONTENT_TYPE =
            "application/x-www-form-urlencoded;charset=" + CHARSET;
    static final String USER_AGENT = "reddit by brian v2.3 by /u/btmura";

    private static final boolean LOG_RESPONSES = BuildConfig.DEBUG && !true;

    public static AccountInfoResult aboutMe(String cookie) throws IOException {
        return getAccountResult(Urls.aboutMe(), cookie);
    }

    public static AccountInfoResult aboutUser(String user, String cookie) throws IOException {
        return getAccountResult(Urls.aboutUser(user), cookie);
    }

    private static AccountInfoResult getAccountResult(CharSequence url, String cookie)
            throws IOException {
        HttpURLConnection conn = null;
        InputStream in = null;
        try {
            conn = connect(url, cookie, true, false);
            in = new BufferedInputStream(conn.getInputStream());
            return AccountInfoResult.fromJsonReader(new JsonReader(new InputStreamReader(in)));
        } finally {
            close(in, conn);
        }
    }

    public static Result comment(String thingId, String text, String cookie, String modhash)
            throws IOException {
        return postData(Urls.comments(), Urls.commentsQuery(thingId, text, modhash), cookie);
{'fraction_non_alphanumeric': 0.08387698042870456, 'fraction_numerical': 0.004100652376514445, 'mean_word_length': 3.7028921998247153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4222738', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1396, 'n_words': 467}