<commit_before><?php

class SimpleRestClient
{
    const
        METHOD_GET = "GET",
        METHOD_POST = "POST";

    public static function get($url, $params = [], $headers = [])
    {
        return self::makeRequest($url, self::METHOD_GET, $params, $headers);
    }

    public static function post($url, $params = [], $headers = [])
    {
        return self::makeRequest($url, self::METHOD_POST, $params, $headers);
    }

    private static function makeRequest($url, $method = self::METHOD_GET, $params = [], $headers = [])
    {
        $ch = curl_init();
        curl_setopt_array($ch, self::prepareOpts($url, $method, $params, $headers));
        $response = curl_exec($ch);
        curl_close($ch);

        return json_decode($response, 1);
    }

    private static function prepareOpts($url, $method, $params, $headers)
    {
        $opts = [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_URL => $url,
        ];

        //prepare headers
        foreach ($headers as $key => $header) {
            $opts[CURLOPT_HTTPHEADER][] = "$key:$header";
        }

        //prepare get params
        if ($method == self::METHOD_GET && !empty($params)) {
            $opts[CURLOPT_URL] .= strpos($opts[CURLOPT_URL], '?') ? '&' : '?';
            $opts[CURLOPT_URL] .= http_build_query($params);
        }

        //prepare post params
        if ($method == self::METHOD_POST && !empty($params)) {
            $opts[CURLOPT_POST] = true;
            if (is_array($params)) {
                $params_str = json_encode($params);
            } else {
                $params_str = $params;
            }
            $opts[CURLOPT_POSTFIELDS] = $params_str;
        }

        return $opts;
    }
}<commit_msg>adding username and password to use for the connection<commit_after><?php

class SimpleRestClient
{
    const
        METHOD_GET = "GET",
        METHOD_POST = "POST";

    public static function get($url, $params = [], $headers = [], $username = "", $pass = "")
    {
        return self::makeRequest($url, self::METHOD_GET, $params, $headers, $username, $pass);
    }

    public static function post($url, $params = [], $headers = [], $username = "", $pass = "")
    {
        return self::makeRequest($url, self::METHOD_POST, $params, $headers, $username, $pass);
    }

    private static function makeRequest($url, $method = self::METHOD_GET, $params = [], $headers = [], $username = "", $pass = "")
    {
        $ch = curl_init();
        curl_setopt_array($ch, self::prepareOpts($url, $method, $params, $headers, $username, $pass));
        $response = curl_exec($ch);
        curl_close($ch);

        return json_decode($response, 1);
    }

    private static function prepareOpts($url, $method, $params, $headers, $username, $pass)
    {
        $opts = [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_URL => $url,
        ];

        if (!empty($username) && !empty($pass)) {
            $opts[CURLOPT_USERPWD] = "$username:$pass";
        }

        //prepare headers
        foreach ($headers as $key => $header) {
            $opts[CURLOPT_HTTPHEADER][] = "$key:$header";
        }

        //prepare get params
        if ($method == self::METHOD_GET && !empty($params)) {
            $opts[CURLOPT_URL] .= strpos($opts[CURLOPT_URL], '?') ? '&' : '?';
            $opts[CURLOPT_URL] .= http_build_query($params);
        }

        //prepare post params
        if ($method == self::METHOD_POST && !empty($params)) {
            $opts[CURLOPT_POST] = true;
            if (is_array($params)) {
                $params_str = json_encode($params);
            } else {
                $params_str = $params;
            }
            $opts[CURLOPT_POSTFIELDS] = $params_str;
        }

        return $opts;
    }
}
{'fraction_non_alphanumeric': 0.16173361522198731, 'fraction_numerical': 0.0005285412262156448, 'mean_word_length': 2.2212765957446807, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1274867', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1135, 'n_words': 233}