/** Get the amazon data using Zend Service Amazon * Remember that calls now need the associate tag * @param string $isbn */ protected function getAmazonData($isbn) { $key = md5($isbn); if (!$this->_cache->test($key)) { $amazon = new Zend_Service_Amazon($this->_amazon['apikey'], $this->_amazon['country'], $this->_amazon['secretkey']); $book = $amazon->itemLookup($isbn, array('AssociateTag' => $this->_amazon['AssociateTag'], 'ResponseGroup' => 'Large')); $this->_cache->save($book); } else { $book = $this->_cache->load($key); } return $this->parseData($book); }
/** * Ensures that itemSearch() throws an exception if the SearchIndex option is missing * * @return void */ public function testItemSearchOptionSearchIndexMissing() { try { $this->_amazon->itemSearch(array()); $this->fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { } }
/** * Ensures that itemLookup() throws an exception when given a SearchIndex * * @return void */ public function testItemLookupExceptionSearchIndex() { $this->setExpectedException( 'Zend\Service\Amazon\Exception\RuntimeException', 'Your request contained a restricted parameter combination. When IdType equals ASIN, SearchIndex cannot be present.' ); $this->_amazon->itemLookup('oops', array('SearchIndex' => 'Books')); }
/** * Ensures that itemLookup() throws an exception when given a SearchIndex * * @return void */ public function testItemLookupExceptionSearchIndex() { try { $this->_amazon->itemLookup('oops', array('SearchIndex' => 'Books')); $this->fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { $this->assertContains('restricted parameter combination', $e->getMessage()); } }
/** Get the amazon data using Zend Service Amazon * Remember that calls now need the associate tag * @param string $isbn */ protected function getAmazonData() { $isbn = $this->getIsbn(); if (!is_null($isbn) && is_string($isbn) && strlen($isbn) < 11) { $key = md5($isbn); if (!$this->getCache()->test($key)) { $amazonDetails = $this->getAmazon(); $amazon = new Zend_Service_Amazon($amazonDetails['apikey'], $amazonDetails['country'], $amazonDetails['secretkey']); $book = $amazon->itemLookup($isbn, array('AssociateTag' => $amazonDetails['AssociateTag'], 'ResponseGroup' => 'Large')); $this->getCache()->save($book); } else { $book = $this->getCache()->load($key); } return $this->parseData($book); } else { return '<p>Nothing returned from Amazon</p>'; } }
/** * Ensures that itemSearch() throws an exception if the SearchIndex option is missing * * @return void */ public function testItemSearchOptionSearchIndexMissing() { try { $this->_amazon->itemSearch(array()); $this->fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { $this->assertContains('Required parameters include SearchIndex', $e->getMessage()); } }
public function __construct($appId = null, $countryCode = 'DE', $secretKey = null) { if (!$appId || !$secretKey) { $a = Kwf_Registry::get('config')->amazon; if (!$a) { throw new Kwf_Exception("Set amazon.key and amazon.secret in config"); } if (!$appId) { $appId = $a->key; } if (!$secretKey) { $secretKey = $a->secret; } } parent::__construct($appId, $countryCode, $secretKey); }
/** * Checking if signature Encryption due on August 15th for Amazon Webservice API is working correctly. * * @dataProvider dataSignatureEncryption * @group ZF-7033 */ public function testSignatureEncryption($baseUri, $params, $expectedStringToSign, $expectedSignature) { $this->assertEquals($expectedStringToSign, Zend_Service_Amazon::buildRawSignature($baseUri, $params)); $this->assertEquals($expectedSignature, rawurlencode(Zend_Service_Amazon::computeSignature($baseUri, '1234567890', $params))); }
/** * * @return array of Books (of type Book) from Amazon */ private function getAmazonResults($searchTerm, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested, $amazonSite) { $amazonService = new \Zend_Service_Amazon($amazonApiKey, $amazonSite, $amazonSecretKey); $amazonResults = null; // tableau d'amazon item recu directement $booksFromAmazon = null; // tableau d'objet Book reçu depuis amazon $responsesGroups = 'Small,ItemAttributes,Images,EditorialReview,Reviews,BrowseNodes,OfferSummary'; //$version = '2005-10-05'; $nbPageRequested = $amazonNumberOfPageRequested; $nbMaxPageRequested = 5; if ($nbPageRequested > $nbMaxPageRequested) { $nbPageRequested = $nbMaxPageRequested; } for ($itemPageNum = 1; $itemPageNum <= $nbPageRequested; $itemPageNum++) { $tmpAmazonResults = null; // recherche faite sur le code isbn10 if (strlen($searchTerm) == 10) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Power' => 'isbn:' . $searchTerm, 'ItemPage' => $itemPageNum)); if (!$tmpAmazonResults || $tmpAmazonResults->totalResults() == 0) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Power' => 'asin:' . $searchTerm, 'ItemPage' => $itemPageNum)); } } // recherche faite sur le mot clé if (!$tmpAmazonResults || $tmpAmazonResults->totalResults() == 0) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Keywords' => $searchTerm, 'ItemPage' => $itemPageNum)); } $amazonResults = $tmpAmazonResults; // mapping des résultats amazon en objet Book if ($amazonResults) { foreach ($amazonResults as $amazonResult) { $result = new \Sb\Db\Model\Book(); \Sb\Db\Mapping\BookMapper::mapFromAmazonResult($result, $amazonResult); // Book is added to the collection only if // author is set // and ISBN10, ISBN13 or ASIN is set if (count($result->getContributors()) > 0) { if ($result->getISBN10() || $result->getISBN13() || $result->getASIN()) { $booksFromAmazon[$result->getISBN10()] = $result; } } } } } return $booksFromAmazon; }
public function __construct($appId, $countryCode = 'DE', $secretKey = null) { parent::__construct($appId, $countryCode, $secretKey); }
private function getBooksFromAmazon($isbns, Config $config) { \Sb\Trace\Trace::addItem(count($isbns) . " Isbns vont être requetés à Amazon : " . implode(",", $isbns)); $booksFromAmazon = array(); for ($index = 0; $index < count($isbns); $index = $index + 10) { $isbnsSlice = array_slice($isbns, $index, 10); \Sb\Trace\Trace::addItem(count($isbnsSlice) . " Isbns requetés par requête Amazon : " . implode(",", $isbnsSlice)); $amazonService = new Zend_Service_Amazon($config->getAmazonApiKey(), 'FR', $config->getAmazonSecretKey()); $responsesGroups = 'Small,ItemAttributes,Images,EditorialReview,Reviews'; // Recherche d'une liste de livre $amazonResults = $amazonService->itemLookup(implode(",", $isbnsSlice), array('SearchIndex' => 'Books', 'AssociateTag' => $config->getAmazonAssociateTag(), 'ResponseGroup' => $responsesGroups, 'IdType' => 'ISBN')); if ($amazonResults) { $i = 0; foreach ($amazonResults as $amazonResult) { $result = new \Sb\Db\Model\Book(); \Sb\Db\Mapping\BookMapper::mapFromAmazonResult($result, $amazonResult); if ($result->IsValid()) { $i++; $booksFromAmazon[] = $result; } //var_dump($booksFromAmazon); } \Sb\Trace\Trace::addItem($i . " trouvés lors de cette requête amazon."); } } return $booksFromAmazon; }