/** * 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); }
/** * 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; } }
/** * 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; }