/**
  * 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($strRequestURI, $arrHTTPArgs, $strTransientID = '')
 {
     // Perform the API request. - requestSigned() should be defined in the extended class.
     $asXMLResponse = $this->requestSigned($strRequestURI, $arrHTTPArgs);
     // 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;
     }
     $osXML = AmazonAutoLinks_Utilities::getXMLObject($asXMLResponse);
     // If it's not a valid XML, it returns a string.
     if (!is_object($osXML)) {
         return array('Error' => array('Message' => $osXML, 'Code' => 'Invalid XML'));
     }
     // compose an error array.
     $arrResponse = AmazonAutoLinks_Utilities::convertXMLtoArray($osXML);
     // If empty, return an empty array.
     if (empty($arrResponse)) {
         return array();
     }
     // If the result is not an array, something went wrong.
     if (!is_array($arrResponse)) {
         return (array) $arrResponse;
     }
     // If an error occurs, do not set the cache.
     if (isset($arrResponse['Error'])) {
         return $arrResponse;
     }
     // Save the cache
     $strTransientID = empty($strTransientID) ? AmazonAutoLinks_Commons::TransientPrefix . "_" . md5(trim($strRequestURI)) : $strTransientID;
     $this->setTransient($strTransientID, $asXMLResponse);
     return $asXMLResponse;
 }
 /**
  * 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);
     }
 }