/** * Performs an API request from the given request API parameters and returns the result as associative array. * * @param string $strType The return type, either 'array', 'json' */ public function request(array $arrParams, $strLocale = '', $intCacheDuration = 3600, $strType = 'array', $intTimeout = 20, $intRedirection = 5, $strHeaders = '', $strUserAgent = '') { // Arguments $arrHTTPArgs = array('timeout' => $intTimeout, 'redirection' => $intRedirection, 'sslverify' => $this->strScheme == 'https' ? false : true, 'headers' => !empty($strHeaders) ? $strHeaders : null, 'user-agent' => $strUserAgent ? $strUserAgent : $this->strUserAgent); $arrHTTPArgs = array_filter($arrHTTPArgs); // drop non value elements. // Request $vResponse = $this->requestWithCache($this->getSignedRequestURI($arrParams, $strLocale), $arrHTTPArgs, $arrParams, $intCacheDuration, $strLocale ? $strLocale : $this->strLocale); // If an error occurs, if (!is_string($vResponse)) { return $vResponse; } $_sXMLResponse = $vResponse; // It returns a string if it's not a valid XML content. $_osXML = AmazonAutoLinks_Utilities::getXMLObject($_sXMLResponse); if (is_string($_osXML)) { return array('Error' => array('Message' => $_osXML, 'Code' => 'Invalid XML')); // compose an error array. } // Return the result with the specified type. if ($strType == 'xml') { return $_sXMLResponse; } if ($strType == 'array') { return AmazonAutoLinks_Utilities::convertXMLtoArray($_osXML); } if ($strType == 'json') { return AmazonAutoLinks_Utilities::convertXMLtoJSON($_osXML); } }