private function _curlHelper(&$url, &$json = null)
    {
        $headers = [
            'Accept: application/json',
            'Accept-Encoding: gzip, deflate',
            'Connection: keep-alive',
            'Authorization: Bearer ' . $this->_token
        ];

        /*
         * If this is a request that has a body then we need to
         * include the content type, which in our case always is JSON.
         */
        if (isset($json)) {
            array_push($headers, 'Content-Type: application/json');
            curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $json);
        }

        curl_setopt($this->_curlHandle, CURLOPT_URL, $url);
        curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($this->_curlHandle, CURLOPT_USERAGENT, $this->_userAgent);

        $result = curl_exec($this->_curlHandle);

        if ($result === false) {
            throw new HttpCallException(curl_error($this->_curlHandle));
        }

        $httpStatus = curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

        // If we have a logger then we can emit a bit of debug info.
        if (isset($this->_logger)) {
            $httpTime = curl_getinfo($this->_curlHandle, CURLINFO_TOTAL_TIME);
            $this->_logger->debug(
                'Request: {req}; Response (status {status}, took {time}s): {rsp}',
                [
                    'req' => $json,
                    'rsp' => $result,
                    'status' => $httpStatus,
                    'time' => $httpTime
                ]
            );
        }

        switch ($httpStatus) {
        case 200:               // OK
        case 201:               // Created
            break;
        case 400:               // Bad Request
        case 403:               // Forbidden
            $e = Deserialize::error($result);
            throw new ErrorResponseException($e->getCode(), $e->getText());
        case 404:               // Not Found
            throw new NotFoundException($url);
        case 401:               // Unauthorized
            throw new UnauthorizedException(
                $this->_servicePlanId, $this->_token
            );
        default:                // Everything else
            throw new UnexpectedResponseException(
                "Unexpected HTTP status $httpStatus", $result
            );
        }

        return $result;
    }
private function _curlHelper(&$url, &$json = null)
    {
        $headers = [
            'Accept: application/json',
            'Accept-Encoding: gzip, deflate',
            'Connection: keep-alive',
            'Authorization: Bearer ' . $this->_token
        ];

        /*
         * If this is a request that has a body then we need to
         * include the content type, which in our case always is JSON.
         */
        if (isset($json)) {
            array_push($headers, 'Content-Type: application/json');
            curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $json);
        }

        curl_setopt($this->_curlHandle, CURLOPT_URL, $url);
        curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($this->_curlHandle, CURLOPT_USERAGENT, $this->_userAgent);

        $result = curl_exec($this->_curlHandle);

        if ($result === false) {
            throw new HttpCallException(curl_error($this->_curlHandle));
        }

        $httpStatus = curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

        // If we have a logger then we can emit a bit of debug info.
        if (isset($this->_logger)) {
            $httpTime = curl_getinfo($this->_curlHandle, CURLINFO_TOTAL_TIME);
            $this->_logger->debug(
                'Request: {req}; Response (status {status}, took {time}s): {rsp}',
                [
                    'req' => $json,
                    'rsp' => $result,
                    'status' => $httpStatus,
                    'time' => $httpTime
                ]
            );
        }

        switch ($httpStatus) {
        case 200:               // OK
        case 201:               // Created
            break;
        case 400:               // Bad Request
        case 403:               // Forbidden
            $e = Deserialize::error($result);
            throw new ErrorResponseException($e->getCode(), $e->getText());
        case 404:               // Not Found
            throw new NotFoundException($url);
        case 401:               // Unauthorized
            throw new UnauthorizedException(
                $this->_servicePlanId, $this->_token
            );
        default:                // Everything else
            throw new UnexpectedResponseException(
                "Unexpected HTTP status $httpStatus", $result
            );
        }

        return $result;
    }
private function _curlHelper ( & $ url , & $ json = null ) { $ headers = [ 'Accept: application/json' , 'Accept-Encoding: gzip, deflate' , 'Connection: keep-alive' , 'Authorization: Bearer ' . $ this -> _token ] ; /*
         * If this is a request that has a body then we need to
         * include the content type, which in our case always is JSON.
         */ if ( isset ( $ json ) ) { array_push ( $ headers , 'Content-Type: application/json' ) ; curl_setopt ( $ this -> _curlHandle , CURLOPT_POSTFIELDS , $ json ) ; } curl_setopt ( $ this -> _curlHandle , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> _curlHandle , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ this -> _curlHandle , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ this -> _curlHandle , CURLOPT_USERAGENT , $ this -> _userAgent ) ; $ result = curl_exec ( $ this -> _curlHandle ) ; if ( $ result === false ) { throw new HttpCallException ( curl_error ( $ this -> _curlHandle ) ) ; } $ httpStatus = curl_getinfo ( $ this -> _curlHandle , CURLINFO_HTTP_CODE ) ; // If we have a logger then we can emit a bit of debug info. if ( isset ( $ this -> _logger ) ) { $ httpTime = curl_getinfo ( $ this -> _curlHandle , CURLINFO_TOTAL_TIME ) ; $ this -> _logger -> debug ( 'Request: {req}; Response (status {status}, took {time}s): {rsp}' , [ 'req' => $ json , 'rsp' => $ result , 'status' => $ httpStatus , 'time' => $ httpTime ] ) ; } switch ( $ httpStatus ) { case 200 : // OK case 201 : // Created break ; case 400 : // Bad Request case 403 : // Forbidden $ e = Deserialize :: error ( $ result ) ; throw new ErrorResponseException ( $ e -> getCode ( ) , $ e -> getText ( ) ) ; case 404 : // Not Found throw new NotFoundException ( $ url ) ; case 401 : // Unauthorized throw new UnauthorizedException ( $ this -> _servicePlanId , $ this -> _token ) ; default : // Everything else throw new UnexpectedResponseException ( "Unexpected HTTP status $httpStatus" , $ result ) ; } return $ result ; }
Helper method that asks cURL to do an HTTP request.

@param string      $url  URL that should receive the request
@param string|null $json request body, if needed

@return string the request result body
Helper method that asks cURL to do an HTTP request .