public function api($subdomain, $resource, array $parameters = array(), $version = 'v2') {
        $ch = $this->getCurl();
        $url = sprintf($this->domain, $subdomain, $version, $resource);
        
        if (!empty($parameters))
            $url .= "?" . http_build_query($parameters);

        curl_setopt_array($ch, array(
            CURLOPT_URL  => $url,
            CURLOPT_HTTPHEADER => array(
                'Accept: application/xml',
                'Authorization: ' . $this->api_key,
            )
        ));

        $body = curl_exec($ch);

        $errno = curl_errno($ch);
        if ($errno !== 0) {
            throw new Exception(sprintf("Error connecting to CommissionJunction: [%s] %s", $errno, curl_error($ch)), $errno);
        }
        
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_status >= 400) {
            throw new Exception(sprintf("CommissionJunction Error [%s] %s", $http_status, strip_tags($body)), $http_status);
        }

        $body = preg_replace("/'/", "&#39;", $body);
        $body = preg_replace("/&#11/", "&amp;#11", $body);
        
        return json_decode(json_encode((array)simplexml_load_string($body)), true);
    }
public function api($subdomain, $resource, array $parameters = array(), $version = 'v2') {
        $ch = $this->getCurl();
        $url = sprintf($this->domain, $subdomain, $version, $resource);
        
        if (!empty($parameters))
            $url .= "?" . http_build_query($parameters);

        curl_setopt_array($ch, array(
            CURLOPT_URL  => $url,
            CURLOPT_HTTPHEADER => array(
                'Accept: application/xml',
                'Authorization: ' . $this->api_key,
            )
        ));

        $body = curl_exec($ch);

        $errno = curl_errno($ch);
        if ($errno !== 0) {
            throw new Exception(sprintf("Error connecting to CommissionJunction: [%s] %s", $errno, curl_error($ch)), $errno);
        }
        
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_status >= 400) {
            throw new Exception(sprintf("CommissionJunction Error [%s] %s", $http_status, strip_tags($body)), $http_status);
        }

        $body = preg_replace("/'/", "&#39;", $body);
        $body = preg_replace("/&#11/", "&amp;#11", $body);
        
        return json_decode(json_encode((array)simplexml_load_string($body)), true);
    }
public function api ( $ subdomain , $ resource , array $ parameters = array ( ) , $ version = 'v2' ) { $ ch = $ this -> getCurl ( ) ; $ url = sprintf ( $ this -> domain , $ subdomain , $ version , $ resource ) ; if ( ! empty ( $ parameters ) ) $ url .= "?" . http_build_query ( $ parameters ) ; curl_setopt_array ( $ ch , array ( CURLOPT_URL => $ url , CURLOPT_HTTPHEADER => array ( 'Accept: application/xml' , 'Authorization: ' . $ this -> api_key , ) ) ) ; $ body = curl_exec ( $ ch ) ; $ errno = curl_errno ( $ ch ) ; if ( $ errno !== 0 ) { throw new Exception ( sprintf ( "Error connecting to CommissionJunction: [%s] %s" , $ errno , curl_error ( $ ch ) ) , $ errno ) ; } $ http_status = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; if ( $ http_status >= 400 ) { throw new Exception ( sprintf ( "CommissionJunction Error [%s] %s" , $ http_status , strip_tags ( $ body ) ) , $ http_status ) ; } $ body = preg_replace ( "/'/" , "&#39;" , $ body ) ; $ body = preg_replace ( "/&#11/" , "&amp;#11" , $ body ) ; return json_decode ( json_encode ( ( array ) simplexml_load_string ( $ body ) ) , true ) ; }
Generic method to fire API requests at Commission Junctions servers

@param string $subdomain The subomdain portion of the REST API url
@param string $resource The resource portion of the REST API url (e.g. /v2/RESOURCE)
@param array $parameters GET request parameters to be appended to the url
@param string $version The version portion of the REST API url, defaults to v2
@return array Commission Junction API response, converted to a PHP array
@throws Exception on cURL failure or http status code greater than or equal to 400
Generic method to fire API requests at Commission Junctions servers