Example #1
0
 /**
  * Ensures that itemSearch() throws an exception when provided an invalid city
  *
  * @return void
  */
 public function testItemSearchExceptionCityInvalid()
 {
     try {
         $this->_amazon->itemSearch(array('SearchIndex' => 'Restaurants', 'Keywords' => 'seafood', 'City' => 'Des Moines'));
         $this->fail('Expected Zend_Service_Exception not thrown');
     } catch (Zend_Service_Exception $e) {
     }
 }
Example #2
0
 /**
  * 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) {
     }
 }
Example #3
0
 /**
  * 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());
     }
 }
Example #4
0
 /**
  * Ensures that itemSearch() throws an exception when provided an invalid city
  *
  * @return void
  */
 public function testItemSearchExceptionCityInvalid()
 {
     $this->setExpectedException(
         'Zend\Service\Amazon\Exception\RuntimeException', 
         'The value you specified for SearchIndex is invalid.'
     );
     $this->_amazon->itemSearch(array(
         'SearchIndex' => 'Restaurants',
         'Keywords'    => 'seafood',
         'City'        => 'Des Moines'
         ));
 }
Example #5
0
 /**
  *
  * @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;
 }