public function prepareRequest($path, $method = 'GET', $data = '')
    {
        $this->responseCode = null;
        $curl = curl_init();

        // General cURL options
        $this->setCurlOption(CURLOPT_VERBOSE, 0);
        $this->setCurlOption(CURLOPT_HEADER, 0);
        $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);

        // HTTP Basic Authentication
        if ($this->apikeyOrUsername && $this->useHttpAuth) {
            if (null === $this->pass) {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.rand(100000, 199999));
            } else {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.$this->pass);
            }
            $this->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        }

        // Host and request options
        $this->setCurlOption(CURLOPT_URL, $this->url.$path);
        $this->setCurlOption(CURLOPT_PORT, $this->getPort());
        if (80 !== $this->getPort()) {
            $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, (int) $this->checkSslCertificate);
            $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, (int) $this->checkSslHost);
            $this->setCurlOption(CURLOPT_SSLVERSION, $this->sslVersion);
        }

        // Set the HTTP request headers
        $httpHeader = $this->setHttpHeader($path);
        $this->setCurlOption(CURLOPT_HTTPHEADER, $httpHeader);

        $this->unsetCurlOption(CURLOPT_CUSTOMREQUEST);
        $this->unsetCurlOption(CURLOPT_POST);
        $this->unsetCurlOption(CURLOPT_POSTFIELDS);
        switch ($method) {
            case 'POST':
                $this->setCurlOption(CURLOPT_POST, 1);
                if ($this->isUploadCall($path, $data)) {
                    $this->prepareUploadRequest($data);
                } elseif (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'PUT':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
                if (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'DELETE':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
            default: // GET
                break;
        }
        // Set all cURL options to the current cURL resource
        curl_setopt_array($curl, $this->getCurlOptions());

        return $curl;
    }
public function prepareRequest($path, $method = 'GET', $data = '')
    {
        $this->responseCode = null;
        $curl = curl_init();

        // General cURL options
        $this->setCurlOption(CURLOPT_VERBOSE, 0);
        $this->setCurlOption(CURLOPT_HEADER, 0);
        $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);

        // HTTP Basic Authentication
        if ($this->apikeyOrUsername && $this->useHttpAuth) {
            if (null === $this->pass) {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.rand(100000, 199999));
            } else {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.$this->pass);
            }
            $this->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        }

        // Host and request options
        $this->setCurlOption(CURLOPT_URL, $this->url.$path);
        $this->setCurlOption(CURLOPT_PORT, $this->getPort());
        if (80 !== $this->getPort()) {
            $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, (int) $this->checkSslCertificate);
            $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, (int) $this->checkSslHost);
            $this->setCurlOption(CURLOPT_SSLVERSION, $this->sslVersion);
        }

        // Set the HTTP request headers
        $httpHeader = $this->setHttpHeader($path);
        $this->setCurlOption(CURLOPT_HTTPHEADER, $httpHeader);

        $this->unsetCurlOption(CURLOPT_CUSTOMREQUEST);
        $this->unsetCurlOption(CURLOPT_POST);
        $this->unsetCurlOption(CURLOPT_POSTFIELDS);
        switch ($method) {
            case 'POST':
                $this->setCurlOption(CURLOPT_POST, 1);
                if ($this->isUploadCall($path, $data)) {
                    $this->prepareUploadRequest($data);
                } elseif (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'PUT':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
                if (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'DELETE':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
            default: // GET
                break;
        }
        // Set all cURL options to the current cURL resource
        curl_setopt_array($curl, $this->getCurlOptions());

        return $curl;
    }
public function prepareRequest ( $ path , $ method = 'GET' , $ data = '' ) { $ this -> responseCode = null ; $ curl = curl_init ( ) ; // General cURL options $ this -> setCurlOption ( CURLOPT_VERBOSE , 0 ) ; $ this -> setCurlOption ( CURLOPT_HEADER , 0 ) ; $ this -> setCurlOption ( CURLOPT_RETURNTRANSFER , 1 ) ; // HTTP Basic Authentication if ( $ this -> apikeyOrUsername && $ this -> useHttpAuth ) { if ( null === $ this -> pass ) { $ this -> setCurlOption ( CURLOPT_USERPWD , $ this -> apikeyOrUsername . ':' . rand ( 100000 , 199999 ) ) ; } else { $ this -> setCurlOption ( CURLOPT_USERPWD , $ this -> apikeyOrUsername . ':' . $ this -> pass ) ; } $ this -> setCurlOption ( CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) ; } // Host and request options $ this -> setCurlOption ( CURLOPT_URL , $ this -> url . $ path ) ; $ this -> setCurlOption ( CURLOPT_PORT , $ this -> getPort ( ) ) ; if ( 80 !== $ this -> getPort ( ) ) { $ this -> setCurlOption ( CURLOPT_SSL_VERIFYPEER , ( int ) $ this -> checkSslCertificate ) ; $ this -> setCurlOption ( CURLOPT_SSL_VERIFYHOST , ( int ) $ this -> checkSslHost ) ; $ this -> setCurlOption ( CURLOPT_SSLVERSION , $ this -> sslVersion ) ; } // Set the HTTP request headers $ httpHeader = $ this -> setHttpHeader ( $ path ) ; $ this -> setCurlOption ( CURLOPT_HTTPHEADER , $ httpHeader ) ; $ this -> unsetCurlOption ( CURLOPT_CUSTOMREQUEST ) ; $ this -> unsetCurlOption ( CURLOPT_POST ) ; $ this -> unsetCurlOption ( CURLOPT_POSTFIELDS ) ; switch ( $ method ) { case 'POST' : $ this -> setCurlOption ( CURLOPT_POST , 1 ) ; if ( $ this -> isUploadCall ( $ path , $ data ) ) { $ this -> prepareUploadRequest ( $ data ) ; } elseif ( isset ( $ data ) ) { $ this -> setCurlOption ( CURLOPT_POSTFIELDS , $ data ) ; } break ; case 'PUT' : $ this -> setCurlOption ( CURLOPT_CUSTOMREQUEST , 'PUT' ) ; if ( isset ( $ data ) ) { $ this -> setCurlOption ( CURLOPT_POSTFIELDS , $ data ) ; } break ; case 'DELETE' : $ this -> setCurlOption ( CURLOPT_CUSTOMREQUEST , 'DELETE' ) ; break ; default : // GET break ; } // Set all cURL options to the current cURL resource curl_setopt_array ( $ curl , $ this -> getCurlOptions ( ) ) ; return $ curl ; }
Prepare the request by setting the cURL options.

@param string $path
@param string $method
@param string $data

@return resource a cURL handle on success, <b>FALSE</b> on errors
Prepare the request by setting the cURL options .