<commit_before><?php

namespace MASNathan\Curl;

/**
 * Curl - Another Curl Object
 * 
 * @package MASNathan
 * @subpackage Curl
 * @author <NAME> <<EMAIL>>
 * @link https://github.com/ReiDuKuduro/Curl GitHub repo
 * @license MIT
 * @version 0.0.1
 */
class Ch
{
    /**
     * Calls a URL using the GET method
     * 
     * Ch::get( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::get('http://path_to_api.com');
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::get('http://path_to_api.com', 'json');
     *                 - Ch::get('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function get()
    {
        return self::call('GET', func_get_args());
    }

    /**
     * Calls a URL using the POST method
     * 
     * Ch::post( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::post('http://path_to_api.com');
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::post('http://path_to_api.com', 'json');
     *                 - Ch::post('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function post()
    {
        return self::call('POST', func_get_args());
    }

    /**
     * Uses POST method and send json data to the API 
     * 
     * Ch::postJson( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::postJson('http://path_to_api.com');
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'));
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), function(data) { var_dump($data); });
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), 'json');
     *                 - Ch::postJson('http://path_to_api.com', 'xml');
     *                 - Ch::postJson('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function postJson()
    {
        return self::call('POST', func_get_args(), 'json');
    }

    /**
     * Uses POST method and send xml data to the API 
     * 
     * Ch::postXml( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::postXml('http://path_to_api.com');
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'));
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), function(data) { var_dump($data); });
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), 'json');
     *                 - Ch::postXml('http://path_to_api.com', 'json');
     *                 - Ch::postXml('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function postXml()
    {
        return self::call('POST', func_get_args(), 'xml');
    }

    /**
     * Calls a URL using the PUT method
     * 
     * Ch::put( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::put('http://path_to_api.com');
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::put('http://path_to_api.com', 'json');
     *                 - Ch::put('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function put()
    {
        return self::call('PUT', func_get_args());
    }

    /**
     * Calls a URL using the DELETE method
     * 
     * Ch::delete( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::delete('http://path_to_api.com');
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::delete('http://path_to_api.com', 'json');
     *                 - Ch::delete('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function delete()
    {
        return self::call('DELETE', func_get_args());
    }

    /**
     * Requests a specified url using the specified method
     * @param string $methof
     * @param string $url
     * @param array $data
     * @param array $special_options Adicional CURL options
     * @return string
     */
    static private function curl($method, $url, $data, $special_options = null)
    {
        $curl = \curl_init();

        if ($method == 'GET') {
            $url .= '?' . \http_build_query($data);
        } elseif (!is_null($special_options)) {
        	\curl_setopt_array($curl, $special_options);
            \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            \curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        } else {
            \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            \curl_setopt($curl, CURLOPT_POSTFIELDS, \http_build_query($data));
        }

        \curl_setopt($curl, CURLOPT_URL, $url);

        \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);<commit_msg>Fixed issue with the params array<commit_after><?php

namespace MASNathan\Curl;

/**
 * Curl - Another Curl Object
 * 
 * @package MASNathan
 * @subpackage Curl
 * @author <NAME> <<EMAIL>>
 * @link https://github.com/ReiDuKuduro/Curl GitHub repo
 * @license MIT
 * @version 0.0.1
 */
class Ch
{
    /**
     * Calls a URL using the GET method
     * 
     * Ch::get( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::get('http://path_to_api.com');
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::get('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::get('http://path_to_api.com', 'json');
     *                 - Ch::get('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function get()
    {
        return self::call('GET', func_get_args());
    }

    /**
     * Calls a URL using the POST method
     * 
     * Ch::post( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::post('http://path_to_api.com');
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::post('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::post('http://path_to_api.com', 'json');
     *                 - Ch::post('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function post()
    {
        return self::call('POST', func_get_args());
    }

    /**
     * Uses POST method and send json data to the API 
     * 
     * Ch::postJson( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::postJson('http://path_to_api.com');
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'));
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), function(data) { var_dump($data); });
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::postJson('http://path_to_api.com', array('{"param1": "some value", "param2": "some other value"}'), 'json');
     *                 - Ch::postJson('http://path_to_api.com', 'xml');
     *                 - Ch::postJson('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function postJson()
    {
        return self::call('POST', func_get_args(), 'json');
    }

    /**
     * Uses POST method and send xml data to the API 
     * 
     * Ch::postXml( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::postXml('http://path_to_api.com');
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'));
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), function(data) { var_dump($data); });
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::postXml('http://path_to_api.com', array('<?xml version="1.0" encoding="ISO-8859-1"?><data><param1>some value</param1><param2>some other value</param2></data>'), 'json');
     *                 - Ch::postXml('http://path_to_api.com', 'json');
     *                 - Ch::postXml('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function postXml()
    {
        return self::call('POST', func_get_args(), 'xml');
    }

    /**
     * Calls a URL using the PUT method
     * 
     * Ch::put( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::put('http://path_to_api.com');
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::put('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::put('http://path_to_api.com', 'json');
     *                 - Ch::put('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function put()
    {
        return self::call('PUT', func_get_args());
    }

    /**
     * Calls a URL using the DELETE method
     * 
     * Ch::delete( string $url [, array $params [, function $callback [, string $data_type]]]);
     * Here are a few examples:
     *                 - Ch::delete('http://path_to_api.com');
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'));
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); });
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), function(data) { var_dump($data); }, 'json');
     *                 - Ch::delete('http://path_to_api.com', array('param1' => 'some value', 'param2' => 'some other value'), 'json');
     *                 - Ch::delete('http://path_to_api.com', 'json');
     *                 - Ch::delete('http://path_to_api.com', function(data) { var_dump($data); }, 'json');
     * Any of the above examples is aceptable
     * @return string|array|null
     */
    static public function delete()
    {
        return self::call('DELETE', func_get_args());
    }

    /**
     * Requests a specified url using the specified method
     * @param string $methof
     * @param string $url
     * @param array $data
     * @param array $special_options Adicional CURL options
     * @return string
     */
    static private function curl($method, $url, $data, $special_options = null)
    {
        $curl = \curl_init();

        if ($method == 'GET' && !empty($data) {
            $url .= '?' . \http_build_query($data);
        } elseif (!is_null($special_options)) {
        	\curl_setopt_array($curl, $special_options);
            \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            \curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        } else {
            \curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            \curl_setopt($curl, CURLOPT_POSTFIELDS, \http_build_query($data));
        }

        \curl_setopt($curl, CURLOPT_URL, $url);

        \curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        \curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
{'fraction_non_alphanumeric': 0.19279493269992082, 'fraction_numerical': 0.009953625155525394, 'mean_word_length': 2.498812821527503, 'pattern_counts': {'":': 16, '<': 67, '<?xml version=': 8, '>': 129, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '7288276', 'n_tokens_mistral': 5666, 'n_tokens_neox': 5525, 'n_words': 1177}