/** * Performs the API request and sets the cache. * * @return string The response string of xml. * @access public * @remark The scope is public since the cache renewal event also uses it. */ public function setAPIRequestCache($sRequestURI, $aHTTPArgs, $sTransientID = '', $iDuration = 0) { // Perform the API request. $_asXMLResponse = $this->requestSigned($sRequestURI, $aHTTPArgs); // If it has a HTTP connection error, an array is returned. if (is_array($_asXMLResponse)) { return $_asXMLResponse; } // If it's not a string, something went wrong. if (!is_string($_asXMLResponse)) { return $_asXMLResponse; } $_boXML = AmazonAutoLinks_WPUtility::getXMLObject($_asXMLResponse); // If it's not a valid XML, it returns false. if (!is_object($_boXML)) { return array('Error' => array('Message' => strip_tags($_asXMLResponse), 'Code' => 'Invalid XML')); } $aResponse = AmazonAutoLinks_WPUtility::convertXMLtoArray($_boXML); // If empty, return an empty array. if (empty($aResponse)) { return array(); } // If the result is not an array, something went wrong. if (!is_array($aResponse)) { return (array) $aResponse; } // If an error occurs, do not set the cache. if (isset($aResponse['Error'])) { return $aResponse; } // Save the cache $sTransientID = empty($sTransientID) ? AmazonAutoLinks_Registry::TRANSIENT_PREFIX . "_" . md5(trim($sRequestURI)) : $sTransientID; $this->setCache($sTransientID, $_asXMLResponse, $iDuration, $sRequestURI); return $_asXMLResponse; }