/** * 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; } }
/** * Amazon Editorial * * This method is responsible for connecting to Amazon AWS and abstracting * editorial reviews for the specific ISBN * * @param string $id Amazon access key * * @return array Returns array with review data, otherwise a PEAR_Error. * @author Andrew Nagy <*****@*****.**> */ protected function loadAmazoneditorial($id) { try { $amazon = new Amazon($id, 'US', $this->config->Content->amazonsecret); $params = array('ResponseGroup' => 'EditorialReview', 'AssociateTag' => isset($this->config->Content->amazonassociate) ? $this->config->Content->amazonassociate : null); $data = $amazon->itemLookup($this->getIsbn10(), $params); } catch (\Exception $e) { // Something went wrong? Just return empty list. return array(); } if ($data) { $i = 0; $result = array(); $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; } $i++; } } } return $result; } }
/** * Ensures that itemLookup() throws an exception when given a SearchIndex * * @return void */ public function testItemLookupExceptionSearchIndex() { $this->setExpectedException('ZendService\\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')); }
/** * Retrieve an Amazon cover. * * @param string $id Amazon Web Services client ID. * * @return bool True if image displayed, false otherwise. */ protected function amazon($id) { try { $amazon = new Amazon($id, 'US', $this->config->Content->amazonsecret); $params = array('ResponseGroup' => 'Images', 'AssociateTag' => isset($this->config->Content->amazonassociate) ? $this->config->Content->amazonassociate : null); $result = $amazon->itemLookup($this->isn, $params); } catch (\Exception $e) { // Something went wrong? Just report failure: return false; } // Where in the response can we find the URL we need? switch ($this->size) { case 'small': $imageIndex = 'SmallImage'; break; case 'medium': $imageIndex = 'MediumImage'; break; case 'large': $imageIndex = 'LargeImage'; break; default: $imageIndex = false; break; } if ($imageIndex && isset($result->{$imageIndex}->Url)) { $imageUrl = (string) $result->{$imageIndex}->Url; return $this->processImageURL($imageUrl, false); } return false; }