<commit_before><?php
/*
 * Copyright (c) Plivo
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Plivo;

use Plivo\PlivoError;

class Plivo
{
    private $api;
    private $auth_id;
    private $auth_token;
    private $ch;

    public function __construct($auth_id, $auth_token, $url="https://api.plivo.com", $version="v1") {
        if ((!isset($auth_id)) || (!$auth_id)) {
            throw new PlivoError("no auth_id");
        }
        if ((!isset($auth_token)) || (!$auth_token)) {
            throw new PlivoError("no auth_token");
        }
        $this->version = $version;
        $this->api = $url."/".$this->version."/Account/".$auth_id;
        $this->auth_id = $auth_id;
        $this->auth_token = $auth_token;
        $this->ch = NULL;
    }

    private function curl_request($method, $path, $params) {
        $url = $this->api.rtrim($path, '/').'/';

        // init curl
        $this->ch = @curl_init();
        if (curl_errno($this->ch)) {
            return array("status" => 0, "response" => array("error" => curl_error($this->ch)));
        }

        if (($method == "GET") || ($method == "DELETE")) {
            $query = http_build_query($params, '', "&");
            if (($query != NULL) && ($query != "")) {
                    $url = $url."?".$query;
            }
        }

        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_USERAGENT => "PHPPlivo/Curl",
            CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CONNECTTIMEOUT => 30,
            CURLOPT_HEADER => FALSE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_VERBOSE => FALSE,
            CURLOPT_SSL_VERIFYPEER => FALSE
        );

        $headers = array(
            'Authorization: Basic '. base64_encode($this->auth_id.":".$this->auth_token),
            'Connection' => 'close'
        );

        if ($method == "POST") {
                $json_params = json_encode($params);
                $options[CURLOPT_POSTFIELDS] = $json_params;
                $options[CURLOPT_POST] = TRUE;
                array_push($headers, "Content-Type:application/json");
                array_push($headers, 'Content-Length: '.strlen($json_params));
        }

        $options[CURLOPT_HTTPHEADER] = $headers;

        curl_setopt_array($this->ch, $options);

        $res = @curl_exec($this->ch);
        $status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
        if ($res === FALSE) {
                $err = curl_error($this->ch);
                @curl_close($this->ch);
                return array("status" => $status, "response" => array("error" => $err));
        }
        @curl_close($this->ch);
        $result = json_decode($res, TRUE);
        return array("status" => $status, "response" => $result);
    }

    private function http2_request($method, $path, $params) {
        $url = $this->api.rtrim($path, '/').'/';
        if (!strcmp($method, "POST")) {
            $req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
            $req->setHeader('Content-type: application/json');
            if ($params) {
                $req->setBody(json_encode($params));
            }
        } else if (!strcmp($method, "GET")) {
            $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
            $url = $req->getUrl();
            $url->setQueryVariables($params);
        } else if (!strcmp($method, "DELETE")) {
            $req = new HTTP_Request2($url, HTTP_Request2::METHOD_DELETE);
            $url = $req->getUrl();
            $url->setQueryVariables($params);
        }
        $req->setAdapter('curl');
        $req->setConfig(array(
            'timeout' => 30,
            'ssl_verify_peer' => FALSE,
        ));
        $req->setAuth($this->auth_id, $this->auth_token, HTTP_Request2::AUTH_BASIC);
        $req->setHeader(array(
            'Connection' => 'close',
            'User-Agent' => 'PHPPlivo',
        ));
        $r = $req->send();
        $status = $r->getStatus();
        $body = $r->getbody();
        $response = json_decode($body, true);
        return array("status" => $status, "response" => $response);
    }
<commit_msg>Deleting PEAR http2_request<commit_after><?php
/*
 * Copyright (c) Plivo
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Plivo;

use Plivo\PlivoError;

class Plivo
{
    private $api;
    private $auth_id;
    private $auth_token;
    private $ch;

    public function __construct($auth_id, $auth_token, $url="https://api.plivo.com", $version="v1") {
        if ((!isset($auth_id)) || (!$auth_id)) {
            throw new PlivoError("no auth_id");
        }
        if ((!isset($auth_token)) || (!$auth_token)) {
            throw new PlivoError("no auth_token");
        }
        $this->version = $version;
        $this->api = $url."/".$this->version."/Account/".$auth_id;
        $this->auth_id = $auth_id;
        $this->auth_token = $auth_token;
        $this->ch = NULL;
    }

    private function curl_request($method, $path, $params) {
        $url = $this->api.rtrim($path, '/').'/';

        // init curl
        $this->ch = @curl_init();
        if (curl_errno($this->ch)) {
            return array("status" => 0, "response" => array("error" => curl_error($this->ch)));
        }

        if (($method == "GET") || ($method == "DELETE")) {
            $query = http_build_query($params, '', "&");
            if (($query != NULL) && ($query != "")) {
                    $url = $url."?".$query;
            }
        }

        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_USERAGENT => "PHPPlivo/Curl",
            CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CONNECTTIMEOUT => 30,
            CURLOPT_HEADER => FALSE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_VERBOSE => FALSE,
            CURLOPT_SSL_VERIFYPEER => FALSE
        );

        $headers = array(
            'Authorization: Basic '. base64_encode($this->auth_id.":".$this->auth_token),
            'Connection' => 'close'
        );

        if ($method == "POST") {
                $json_params = json_encode($params);
                $options[CURLOPT_POSTFIELDS] = $json_params;
                $options[CURLOPT_POST] = TRUE;
                array_push($headers, "Content-Type:application/json");
                array_push($headers, 'Content-Length: '.strlen($json_params));
        }

        $options[CURLOPT_HTTPHEADER] = $headers;

        curl_setopt_array($this->ch, $options);

        $res = @curl_exec($this->ch);
        $status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
        if ($res === FALSE) {
                $err = curl_error($this->ch);
                @curl_close($this->ch);
                return array("status" => $status, "response" => array("error" => $err));
        }
        @curl_close($this->ch);
        $result = json_decode($res, TRUE);
        return array("status" => $status, "response" => $result);
    }

{'fraction_non_alphanumeric': 0.16673433482203276, 'fraction_numerical': 0.0039247530112329135, 'mean_word_length': 2.077884214910454, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 101, 'https://': 2, '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': '5060454', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2265, 'n_words': 419}