/** * Performs paged API requests. * * This enables to retrieve more than 10 items. However, for it, it performs multiple requests, thus, it will be slow. * * @since 2.0.1 */ protected function getRequest($iCount) { $_oAPI = new AmazonAutoLinks_ProductAdvertisingAPI($this->arrArgs['country'], $this->oOption->getAccessPublicKey(), $this->oOption->getAccessPrivateKey(), $this->arrArgs['associate_id']); // First, perform the search for the first page regardless the specified count (number of items). // Keys with an empty value will be filtered out when performing the request. $_aResponse = $_oAPI->request($this->getAPIParameterArray($this->arrArgs['Operation']), '', $this->arrArgs['cache_duration']); if ($iCount <= 10) { return $_aResponse; } // Check necessary key is set if (!isset($_aResponse['Items']['Item']) || !is_array($_aResponse['Items']['Item'])) { return $_aResponse; } // Calculate the required number of pages. $_iPage = $this->_getTotalPageNumber($iCount, $_aResponse, $this->arrArgs['SearchIndex']); $_aResponseTrunk = $_aResponse; // First perform fetching data in the background if caches are not available. Parse backwards $_fScheduled = null; for ($_i = $_iPage; $_i >= 2; $_i--) { $_fResult = $_oAPI->scheduleInBackground($this->getAPIParameterArray($this->arrArgs['Operation'], $_i)); $_fScheduled = $_fScheduled ? $_fScheduled : $_fResult; } if ($_fScheduled) { // there are items scheduled to fetch in the background, do it right now. AmazonAutoLinks_Shadow::gaze(); } // Start from the second page since the first page has been already done. for ($_i = 2; $_i <= $_iPage; $_i++) { $_aResponse = $_oAPI->request($this->getAPIParameterArray($this->arrArgs['Operation'], $_i), '', $this->arrArgs['cache_duration']); if (isset($_aResponse['Items']['Item']) && is_array($_aResponse['Items']['Item'])) { $_aResponseTrunk['Items']['Item'] = $this->_addItems($_aResponseTrunk['Items']['Item'], $_aResponse['Items']['Item']); } } return $_aResponseTrunk; }
/** * Performs an Amazon Product API request. * * @since 2.0.2 */ protected function getRequest($iCount) { $_oAPI = new AmazonAutoLinks_ProductAdvertisingAPI($this->oUnitOption->get('country'), $this->oOption->get('authentication_keys', 'access_key'), $this->oOption->get('authentication_keys', 'access_key_secret'), $this->oUnitOption->get('associate_id')); // Perform the search for the first page regardless the specified count (number of items). // Keys with an empty value will be filtered out when performing the request. return $_oAPI->request($this->getAPIParameterArray($this->oUnitOption->get('Operation')), $this->oUnitOption->get('country'), $this->oUnitOption->get('cache_duration')); }
/** * Performs an Amazon Product API request. * * @since 2.0.2 */ protected function getRequest($iCount) { $_oAPI = new AmazonAutoLinks_ProductAdvertisingAPI($this->arrArgs['country'], $this->oOption->getAccessPublicKey(), $this->oOption->getAccessPrivateKey(), $this->arrArgs['associate_id']); // Perform the search for the first page regardless the specified count (number of items). // Keys with an empty value will be filtered out when performing the request. return $_oAPI->request($this->getAPIParameterArray($this->arrArgs['Operation']), '', $this->arrArgs['cache_duration']); }
public function _replyToRenewAPITransients($arrRequestInfo) { $strLocale = $arrRequestInfo['locale']; $arrParams = $arrRequestInfo['parameters']; $oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI($strLocale, $GLOBALS['oAmazonAutoLinks_Option']->getAccessPublicKey(), $GLOBALS['oAmazonAutoLinks_Option']->getAccessPrivateKey()); $oAmazonAPI->request($arrParams, $strLocale, null); // passing null will fetch the data right away and sets the cache. }
/** * * @callback action aal_action_api_transient_renewal */ public function doAction() { $_oOption = AmazonAutoLinks_Option::getInstance(); if (!$_oOption->isAPIConnected()) { return; } $_aParams = func_get_args() + array(null); $aRequestInfo = $_aParams[0]; $_sLocale = $aRequestInfo['locale']; $_aParameters = $aRequestInfo['parameters']; $_oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI($_sLocale, $_oOption->get(array('authentication_keys', 'access_key'), ''), $_oOption->get(array('authentication_keys', 'access_key_secret'), '')); $_oAmazonAPI->request($_aParameters, $_sLocale, null); }
/** * Extracts product data from the response data fetched from amazon server with the Product Advertising API. * @return array * @see http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html */ private function _getProductData($sASIN, $sLocale, $sAssociateID) { $_oOption = AmazonAutoLinks_Option::getInstance(); if (!$_oOption->isAPIConnected()) { return array(); } $_sPublicKey = $_oOption->get(array('authentication_keys', 'access_key'), ''); $_sPrivateKey = $_oOption->get(array('authentication_keys', 'access_key_secret'), ''); if (empty($_sPublicKey) || empty($_sPrivateKey)) { return array(); } // Construct API arguments $_aAPIArguments = array('Operation' => 'ItemLookup', 'Condition' => 'All', 'IdType' => 'ASIN', 'IncludeReviewsSummary' => "True", 'ItemId' => $sASIN, 'ResponseGroup' => 'Large'); $_oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI($sLocale, $_sPublicKey, $_sPrivateKey, $sAssociateID); $_aRawData = $_oAmazonAPI->request($_aAPIArguments, $sLocale, 60); return $this->getElement($_aRawData, array('Items', 'Item'), array()); }
protected function getNodeListByCategory($arrPreviousPageInput) { // Determine the locale. if (!empty($arrPreviousPageInput)) { $strLocale = $arrPreviousPageInput['country']; } else { if ($GLOBALS['strAmazonAutoLinks_UnitType'] == 'search') { $strLocale = get_post_meta($_GET['post'], 'country', true); } else { return array('error' => 'ERROR'); } } // Prepare API object $strPublicKey = $GLOBALS['oAmazonAutoLinks_Option']->getAccessPublicKey(); $strPrivateKey = $GLOBALS['oAmazonAutoLinks_Option']->getAccessPrivateKey(); $oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI($strLocale, $strPublicKey, $strPrivateKey); // Now fetch the category node. $arrBrowseNodes = array(); $arrNodeLabels = array(0 => __('All', 'amazon-auto-links')); foreach (AmazonAutoLinks_Properties::getRootNoeds($strLocale) as $arrNodeIDs) { $arrResult = $oAmazonAPI->request(array("Operation" => "BrowseNodeLookup", "BrowseNodeId" => implode(',', $arrNodeIDs)), $strLocale, 30); if (!isset($arrResult['BrowseNodes']['BrowseNode'])) { continue; } $arrBrowseNodes = array_merge($arrResult['BrowseNodes']['BrowseNode'], $arrBrowseNodes); } foreach ($arrBrowseNodes as $arrNode) { if (isset($arrNode['Ancestors'])) { $arrNode = $arrNode['Ancestors']['BrowseNode']; } $arrNodeLabels[$arrNode['BrowseNodeId']] = $arrNode['Name']; } // AmazonAutoLinks_Debug::logArray( $arrNodeLabels ); return $arrNodeLabels; }