Example #1
0
 /**
  * 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'));
 }
Example #2
0
 /**
  * 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());
     }
 }
Example #3
0
 /** 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);
 }
Example #4
0
 /** 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>';
     }
 }
 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;
 }