コード例 #1
0
ファイル: OnlineTest.php プロジェクト: tillk/vufind
 /**
  * Sets up this test case
  *
  * @return void
  */
 public function setUp()
 {
     if (!constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')) {
         $this->markTestSkipped('Zend_Service_Amazon_S3 online tests are not enabled');
     }
     if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')) {
         $this->markTestSkipped('Constants AccessKeyId and SecretKey have to be set.');
     }
     $this->_amazon = new Amazon\Amazon(TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID, 'US', TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY);
     $this->_query = new Amazon\Query(TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID, 'US', TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY);
     $this->_httpClientAdapterSocket = new \Zend\Http\Client\Adapter\Socket();
     $this->_amazon->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterSocket);
     // terms of use compliance: no more than one query per second
     sleep(1);
 }
コード例 #2
0
ファイル: AmazonEditorial.php プロジェクト: tillk/vufind
 /**
  * Amazon Editorial
  *
  * This method is responsible for connecting to Amazon AWS and abstracting
  * editorial reviews for the specific ISBN
  *
  * @param string           $key     API key
  * @param \VuFindCode\ISBN $isbnObj ISBN object
  *
  * @throws \Exception
  * @return array     Returns array with review data.
  * @author Andrew Nagy <*****@*****.**>
  */
 public function loadByIsbn($key, \VuFindCode\ISBN $isbnObj)
 {
     try {
         $amazon = new Amazon($key, 'US', $this->secret);
         $amazon->getRestClient()->setHttpClient($this->getHttpClient());
         $params = ['ResponseGroup' => 'EditorialReview', 'AssociateTag' => $this->associate];
         $isbn = $this->getIsbn10($isbnObj);
         $data = $amazon->itemLookup($isbn, $params);
     } catch (\Exception $e) {
         // Something went wrong?  Just return empty list.
         return [];
     }
     if ($data) {
         $i = 0;
         $result = [];
         $reviews = isset($data->EditorialReviews) ? $data->EditorialReviews : null;
         if (!empty($reviews)) {
             foreach ($reviews as $review) {
                 // Filter out product description
                 if ((string) $review->Source != 'Product Description') {
                     foreach ($review as $key => $value) {
                         $result[$i][$key] = (string) $value;
                     }
                     if (!isset($result[$i]['Copyright'])) {
                         $result[$i]['Copyright'] = $this->getCopyright($isbn);
                     }
                     $i++;
                 }
             }
         }
         return $result;
     }
 }
コード例 #3
0
ファイル: Amazon.php プロジェクト: grharry/vufind
 /**
  * Get an AmazonService object for the specified key.
  *
  * @param string $key API key
  *
  * @return AmazonService
  */
 protected function getAmazonService($key)
 {
     $service = new AmazonService($key, 'US', $this->secret);
     $service->getRestClient()->setHttpClient($this->getHttpClient());
     return $service;
 }