private function makeRequest($http_verb, $method, $args = array(), $timeout = self::TIMEOUT)
    {
        $url = $this->api_endpoint . '/' . $method;

        $response = $this->prepareStateForRequest($http_verb, $method, $url, $timeout);

        $httpHeader = array(
            'Accept: application/vnd.api+json',
            'Content-Type: application/vnd.api+json',
            'Authorization: apikey ' . $this->api_key
        );

        if (isset($args["language"])) {
            $httpHeader[] = "Accept-Language: " . $args["language"];
        }

        if ($http_verb === 'put') {
            $httpHeader[] = 'Allow: PUT, PATCH, POST';
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
        curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
        curl_setopt($ch, CURLOPT_ENCODING, '');
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);

        switch ($http_verb) {
            case 'post':
                curl_setopt($ch, CURLOPT_POST, true);
                $this->attachRequestPayload($ch, $args);
                break;

            case 'get':
                $query = http_build_query($args, '', '&');
                curl_setopt($ch, CURLOPT_URL, $url . '?' . $query);
                break;

            case 'delete':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;

            case 'patch':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                $this->attachRequestPayload($ch, $args);
                break;

            case 'put':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
                $this->attachRequestPayload($ch, $args);
                break;
        }

        $responseContent     = curl_exec($ch);
        $response['headers'] = curl_getinfo($ch);
        $response            = $this->setResponseState($response, $responseContent, $ch);
        $formattedResponse   = $this->formatResponse($response);

        curl_close($ch);

        $isSuccess = $this->determineSuccess($response, $formattedResponse, $timeout);

        return is_array($formattedResponse) ? $formattedResponse : $isSuccess;
    }
private function makeRequest($http_verb, $method, $args = array(), $timeout = self::TIMEOUT)
    {
        $url = $this->api_endpoint . '/' . $method;

        $response = $this->prepareStateForRequest($http_verb, $method, $url, $timeout);

        $httpHeader = array(
            'Accept: application/vnd.api+json',
            'Content-Type: application/vnd.api+json',
            'Authorization: apikey ' . $this->api_key
        );

        if (isset($args["language"])) {
            $httpHeader[] = "Accept-Language: " . $args["language"];
        }

        if ($http_verb === 'put') {
            $httpHeader[] = 'Allow: PUT, PATCH, POST';
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
        curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
        curl_setopt($ch, CURLOPT_ENCODING, '');
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);

        switch ($http_verb) {
            case 'post':
                curl_setopt($ch, CURLOPT_POST, true);
                $this->attachRequestPayload($ch, $args);
                break;

            case 'get':
                $query = http_build_query($args, '', '&');
                curl_setopt($ch, CURLOPT_URL, $url . '?' . $query);
                break;

            case 'delete':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;

            case 'patch':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                $this->attachRequestPayload($ch, $args);
                break;

            case 'put':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
                $this->attachRequestPayload($ch, $args);
                break;
        }

        $responseContent     = curl_exec($ch);
        $response['headers'] = curl_getinfo($ch);
        $response            = $this->setResponseState($response, $responseContent, $ch);
        $formattedResponse   = $this->formatResponse($response);

        curl_close($ch);

        $isSuccess = $this->determineSuccess($response, $formattedResponse, $timeout);

        return is_array($formattedResponse) ? $formattedResponse : $isSuccess;
    }
private function makeRequest ( $ http_verb , $ method , $ args = array ( ) , $ timeout = self :: TIMEOUT ) { $ url = $ this -> api_endpoint . '/' . $ method ; $ response = $ this -> prepareStateForRequest ( $ http_verb , $ method , $ url , $ timeout ) ; $ httpHeader = array ( 'Accept: application/vnd.api+json' , 'Content-Type: application/vnd.api+json' , 'Authorization: apikey ' . $ this -> api_key ) ; if ( isset ( $ args [ "language" ] ) ) { $ httpHeader [ ] = "Accept-Language: " . $ args [ "language" ] ; } if ( $ http_verb === 'put' ) { $ httpHeader [ ] = 'Allow: PUT, PATCH, POST' ; } $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ httpHeader ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)' ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_VERBOSE , true ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ timeout ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , $ this -> verify_ssl ) ; curl_setopt ( $ ch , CURLOPT_ENCODING , '' ) ; curl_setopt ( $ ch , CURLINFO_HEADER_OUT , true ) ; switch ( $ http_verb ) { case 'post' : curl_setopt ( $ ch , CURLOPT_POST , true ) ; $ this -> attachRequestPayload ( $ ch , $ args ) ; break ; case 'get' : $ query = http_build_query ( $ args , '' , '&' ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url . '?' . $ query ) ; break ; case 'delete' : curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'DELETE' ) ; break ; case 'patch' : curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'PATCH' ) ; $ this -> attachRequestPayload ( $ ch , $ args ) ; break ; case 'put' : curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'PUT' ) ; $ this -> attachRequestPayload ( $ ch , $ args ) ; break ; } $ responseContent = curl_exec ( $ ch ) ; $ response [ 'headers' ] = curl_getinfo ( $ ch ) ; $ response = $ this -> setResponseState ( $ response , $ responseContent , $ ch ) ; $ formattedResponse = $ this -> formatResponse ( $ response ) ; curl_close ( $ ch ) ; $ isSuccess = $ this -> determineSuccess ( $ response , $ formattedResponse , $ timeout ) ; return is_array ( $ formattedResponse ) ? $ formattedResponse : $ isSuccess ; }
Performs the underlying HTTP request. Not very exciting.

@param  string $http_verb The HTTP verb to use: get, post, put, patch, delete
@param  string $method    The API method to be called
@param  array  $args      Assoc array of parameters to be passed
@param int     $timeout

@return array|false Assoc array of decoded result
Performs the underlying HTTP request . Not very exciting .