<commit_before><?php namespace SOSTheBlack\Moip;

/**
 * MoIP's API connection class
 *
 * @author <NAME>
 * @author <NAME>
 * @version 0.0.2
 * @license <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>
 */
class Client {

    /**
     * Method send()
     *
     * Send the request to API's server
     *
     * @param string $credentials Token and key to the authentication
     * @param string $xml The XML request
     * @param string $url The server's URL
     * @param string $method Method used to send the request
	 * @throws Exception
	 * @return Response
     */
    public function send($credentials, $xml, $url='https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica', $method='POST') {
        $header = [];
        $header[] = "Authorization: Basic " . base64_encode($credentials);
        if (!function_exists('curl_init')){
            throw new Exception('This library needs cURL extension');
		}
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_USERPWD, $credentials);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
        if ($method == 'POST') {
            curl_setopt($curl, CURLOPT_POST, true);
        }
		if ($xml != '') curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $ret = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        return new Response(array('resposta' => $ret, 'erro' => $err));
    }

    /**
	 * @param string $credentials token / key authentication Moip
	 * @param string $xml url request
	 * @param string $url url request
	 * @param string $error errors
	 * @return Response
     */
    function curlPost($credentials, $xml, $url, $error=null) 
    {
        return $this->initialCurl($credentials, $xml, $url, $error);   
    }

    /**
     * @param string $credentials token / key authentication Moip
     * @param string $url url request
     * @param string $error errors
     * @return Response
     */
    function curlGet($credentials, $url, $error=null) 
    {
        return $this->initialCurl($credentials, null, (string) $url, $error);
    }

   /**
     * @param string $credentials token / key authentication Moip
     * @param string $xml url request
     * @param string $url url request
     * @param string $error errors
     * @return Response
     */
    public function initialCurl($credentials, $xml, $url, $error)
    {
        if (!$error) {
            $header   = [];
            $header[] = "Expect:";
            $header[] = "Authorization: Basic " . base64_encode($credentials);

            $ch = curl_init();
            $options = [];
            $options[CURLOPT_URL] = $url;
            $options[CURLOPT_HTTPHEADER] = $header;
            $options[CURLOPT_SSL_VERIFYPEER] = false;
            $options[CURLOPT_RETURNTRANSFER] = true;

            if ($xml !== null) {
                $options[CURLOPT_POST] = true ;
                $options[CURLOPT_POSTFIELDS] =  $xml;
                $options[CURLINFO_HEADER_OUT] =   true;
            }

            curl_setopt_array($ch, $options);
            $ret = curl_exec($ch);
            $err = curl_error($ch);
            $info = curl_getinfo($ch);
            curl_close($ch);            

            if ($info['http_code'] == "200")
                return new Response(array('response' => true, 'error' => null, 'xml' => $ret));
            else if ($info['http_code'] == "500")
                return new Response(array('response' => false, 'error' => 'Error processing XML', 'xml' => null));
            else if ($info['http_code'] == "401")
                return new Response(array('response' => false, 'error' => 'Authentication failed', 'xml' => null));
            else
                return new Response(array('response' => false, 'error' => $err, 'xml' => null));
        } else {
            return new Response(array('response' => false, 'error' => $error, 'xml' => null));
        }
    }
}<commit_msg>fixed Api::initialCurl()<commit_after><?php namespace SOSTheBlack\Moip;

/**
 * MoIP's API connection class
 *
 * @author <NAME>
 * @author <NAME>
 * @version 0.0.2
 * @license <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>
 */
class Client {

    /**
     * Method send()
     *
     * Send the request to API's server
     *
     * @param string $credentials Token and key to the authentication
     * @param string $xml The XML request
     * @param string $url The server's URL
     * @param string $method Method used to send the request
	 * @throws Exception
	 * @return Response
     */
    public function send($credentials, $xml, $url='https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica', $method='POST') {
        $header = [];
        $header[] = "Authorization: Basic " . base64_encode($credentials);
        if (!function_exists('curl_init')){
            throw new Exception('This library needs cURL extension');
		}
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_USERPWD, $credentials);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
        if ($method == 'POST') {
            curl_setopt($curl, CURLOPT_POST, true);
        }
		if ($xml != '') curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $ret = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        return new Response(array('resposta' => $ret, 'erro' => $err));
    }

    /**
	 * @param string $credentials token / key authentication Moip
	 * @param string $xml url request
	 * @param string $url url request
	 * @param string $error errors
	 * @return Response
     */
    function curlPost($credentials, $xml, $url, $error=null) 
    {
        return $this->initialCurl($credentials, $xml, $url, $error);   
    }

    /**
     * @param string $credentials token / key authentication Moip
     * @param string $url url request
     * @param string $error errors
     * @return Response
     */
    function curlGet($credentials, $url, $error=null) 
    {
        return $this->initialCurl($credentials, null, (string) $url, $error);
    }

   /**
     * @param string $credentials token / key authentication Moip
     * @param string $xml url request
     * @param string $url url request
     * @param string $error errors
     * @return Response
     */
    public function initialCurl($credentials, $xml, $url, $error)
    {
        if (!$error) {
            $header   = [];
            $header[] = "Expect:";
            $header[] = "Authorization: Basic " . base64_encode($credentials);

            $ch = curl_init();
            $options = [];
            $options[CURLOPT_URL] = $url;
            $options[CURLOPT_HTTPHEADER] = $header;
            $options[CURLOPT_SSL_VERIFYPEER] = false;
            $options[CURLOPT_RETURNTRANSFER] = true;

            if ($xml !== null) {
                $options[CURLOPT_POST] = true ;
                $options[CURLOPT_POSTFIELDS] =  $xml;
                $options[CURLINFO_HEADER_OUT] =   true;
            }

            curl_setopt_array($ch, $options);
            $ret = curl_exec($ch);
            $err = curl_error($ch);
            $info = curl_getinfo($ch);
            curl_close($ch);            

            if ($info['http_code'] == "200")
                return new Response(array('response' => true, 'error' => null, 'xml' => $ret));
            else
                return new Response(array('response' => false, 'error' => "Errors $info['http_code']". $err, 'xml' => null));
        } else {
            return new Response(array('response' => false, 'error' => $error, 'xml' => null));
        }
    }
}
{'fraction_non_alphanumeric': 0.14567075436640653, 'fraction_numerical': 0.0037160906726124115, 'mean_word_length': 2.38107202680067, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 30}, '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': '1662708', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2413, 'n_words': 590}