public function call($resource, $params = array(), $method = 'GET')
    {
        if (!empty($params) && is_array($params)) {
          $queryString = http_build_query($params);
        }
        else {
          $queryString = '';
        }

        $requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');

        $curl = curl_init();

        $curl_options = array(
          CURLOPT_USERPWD => $this->getAuthenticationString(),
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_URL => $requestUrl,
          CURLOPT_TIMEOUT => 30,
          CURLOPT_CONNECTTIMEOUT => 30,
          CURLOPT_HTTPHEADER => array('Accept: application/xml'),
        );

        if (strtolower($method) == 'post') {
          $curl_options[CURLOPT_POST] = 1;
          $curl_options[CURLOPT_POSTFIELDS] = $params;
        }

        curl_setopt_array($curl, $curl_options);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        //@todo test for curl error
        if ($errno = curl_errno($curl)) {
          $error_message = $errno . ': ' . curl_strerror($errno);
          throw new Exception($error_message, $errno);
        }
        curl_close($curl);

        //@todo test for any non 200 response
        if ($curl_info['http_code'] != 200) {
            throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
        }

        $xmlObject = simplexml_load_string($response);

        if ($xmlObject === false) {
            throw new Exception("Response: Response was not valid XML");
        }

        return $xmlObject;
    }
public function call($resource, $params = array(), $method = 'GET')
    {
        if (!empty($params) && is_array($params)) {
          $queryString = http_build_query($params);
        }
        else {
          $queryString = '';
        }

        $requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');

        $curl = curl_init();

        $curl_options = array(
          CURLOPT_USERPWD => $this->getAuthenticationString(),
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_URL => $requestUrl,
          CURLOPT_TIMEOUT => 30,
          CURLOPT_CONNECTTIMEOUT => 30,
          CURLOPT_HTTPHEADER => array('Accept: application/xml'),
        );

        if (strtolower($method) == 'post') {
          $curl_options[CURLOPT_POST] = 1;
          $curl_options[CURLOPT_POSTFIELDS] = $params;
        }

        curl_setopt_array($curl, $curl_options);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        //@todo test for curl error
        if ($errno = curl_errno($curl)) {
          $error_message = $errno . ': ' . curl_strerror($errno);
          throw new Exception($error_message, $errno);
        }
        curl_close($curl);

        //@todo test for any non 200 response
        if ($curl_info['http_code'] != 200) {
            throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
        }

        $xmlObject = simplexml_load_string($response);

        if ($xmlObject === false) {
            throw new Exception("Response: Response was not valid XML");
        }

        return $xmlObject;
    }
public function call ( $ resource , $ params = array ( ) , $ method = 'GET' ) { if ( ! empty ( $ params ) && is_array ( $ params ) ) { $ queryString = http_build_query ( $ params ) ; } else { $ queryString = '' ; } $ requestUrl = self :: API_URL . $ resource . ( ( strtolower ( $ method ) == 'get' ) ? '?' . $ queryString : '' ) ; $ curl = curl_init ( ) ; $ curl_options = array ( CURLOPT_USERPWD => $ this -> getAuthenticationString ( ) , CURLOPT_RETURNTRANSFER => 1 , CURLOPT_URL => $ requestUrl , CURLOPT_TIMEOUT => 30 , CURLOPT_CONNECTTIMEOUT => 30 , CURLOPT_HTTPHEADER => array ( 'Accept: application/xml' ) , ) ; if ( strtolower ( $ method ) == 'post' ) { $ curl_options [ CURLOPT_POST ] = 1 ; $ curl_options [ CURLOPT_POSTFIELDS ] = $ params ; } curl_setopt_array ( $ curl , $ curl_options ) ; $ response = curl_exec ( $ curl ) ; $ curl_info = curl_getinfo ( $ curl ) ; //@todo test for curl error if ( $ errno = curl_errno ( $ curl ) ) { $ error_message = $ errno . ': ' . curl_strerror ( $ errno ) ; throw new Exception ( $ error_message , $ errno ) ; } curl_close ( $ curl ) ; //@todo test for any non 200 response if ( $ curl_info [ 'http_code' ] != 200 ) { throw new Exception ( "Response: Bad response - HTTP Code:" . $ curl_info [ 'http_code' ] ) ; } $ xmlObject = simplexml_load_string ( $ response ) ; if ( $ xmlObject === false ) { throw new Exception ( "Response: Response was not valid XML" ) ; } return $ xmlObject ; }
Make an api request

@param string $resource
@param array $params
@param string $method
Make an api request