Пример #1
0
 /**
  * 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;
     }
 }
Пример #2
0
 /**
  * Parse the given Offer element
  *
  * @param DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $this->MerchantId = (string) $xpath->query('./az:Merchant/az:MerchantId/text()', $dom)->item(0)->data;
     $name = $xpath->query('./az:Merchant/az:Name/text()', $dom);
     if ($name->length == 1) {
         $this->MerchantName = (string) $name->item(0)->data;
     }
     $this->GlancePage = (string) $xpath->query('./az:Merchant/az:GlancePage/text()', $dom)->item(0)->data;
     $this->Condition = (string) $xpath->query('./az:OfferAttributes/az:Condition/text()', $dom)->item(0)->data;
     $this->OfferListingId = (string) $xpath->query('./az:OfferListing/az:OfferListingId/text()', $dom)->item(0)->data;
     $Price = $xpath->query('./az:OfferListing/az:Price/az:Amount', $dom);
     if ($Price->length == 1) {
         $this->Price = (int) $xpath->query('./az:OfferListing/az:Price/az:Amount/text()', $dom)->item(0)->data;
         $this->CurrencyCode = (string) $xpath->query('./az:OfferListing/az:Price/az:CurrencyCode/text()', $dom)->item(0)->data;
     }
     $availability = $xpath->query('./az:OfferListing/az:Availability/text()', $dom)->item(0);
     if ($availability instanceof DOMText) {
         $this->Availability = (string) $availability->data;
     }
     $result = $xpath->query('./az:OfferListing/az:IsEligibleForSuperSaverShipping/text()', $dom);
     if ($result->length >= 1) {
         $this->IsEligibleForSuperSaverShipping = (bool) $result->item(0)->data;
     }
 }
Пример #3
0
 /**
  * Parse the given Offer Set Element
  *
  * @param  DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $offer = $xpath->query('./az:OfferSummary', $dom);
     if ($offer->length == 1) {
         $lowestNewPrice = $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount', $dom);
         if ($lowestNewPrice->length == 1) {
             $this->LowestNewPrice = (int) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount/text()', $dom)->item(0)->data;
             $this->LowestNewPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
         }
         $lowestUsedPrice = $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount', $dom);
         if ($lowestUsedPrice->length == 1) {
             $this->LowestUsedPrice = (int) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount/text()', $dom)->item(0)->data;
             $this->LowestUsedPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
         }
         $this->TotalNew = (int) $xpath->query('./az:OfferSummary/az:TotalNew/text()', $dom)->item(0)->data;
         $this->TotalUsed = (int) $xpath->query('./az:OfferSummary/az:TotalUsed/text()', $dom)->item(0)->data;
         $this->TotalCollectible = (int) $xpath->query('./az:OfferSummary/az:TotalCollectible/text()', $dom)->item(0)->data;
         $this->TotalRefurbished = (int) $xpath->query('./az:OfferSummary/az:TotalRefurbished/text()', $dom)->item(0)->data;
     }
     $offers = $xpath->query('./az:Offers/az:Offer', $dom);
     if ($offers->length >= 1) {
         foreach ($offers as $offer) {
             $this->Offers[] = new Offer($offer);
         }
     }
 }
Пример #4
0
 /**
  * Create an instance of Zend_Service_Amazon_ResultSet and create the necessary data objects
  *
  * @param  DOMDocument $dom
  * @return void
  */
 public function __construct(DOMDocument $dom)
 {
     $this->_dom = $dom;
     $this->_xpath = new DOMXPath($dom);
     $this->_xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $this->_results = $this->_xpath->query('//az:Item');
 }
Пример #5
0
 /**
  * Assigns values to properties relevant to Accessories
  *
  * @param  DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     foreach (array('ASIN', 'Title') as $el) {
         $this->{$el} = (string) $xpath->query("./az:{$el}/text()", $dom)->item(0)->data;
     }
 }
Пример #6
0
 /**
  * Assigns values to properties relevant to Image
  *
  * @param  DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $this->Url = Uri\UriFactory::factory($xpath->query('./az:URL/text()', $dom)->item(0)->data);
     $this->Height = (int) $xpath->query('./az:Height/text()', $dom)->item(0)->data;
     $this->Width = (int) $xpath->query('./az:Width/text()', $dom)->item(0)->data;
 }
Пример #7
0
 /**
  * Assigns values to properties relevant to CustomerReview
  *
  * @param  DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     foreach (array('Rating', 'HelpfulVotes', 'CustomerId', 'TotalVotes', 'Date', 'Summary', 'Content') as $el) {
         $result = $xpath->query("./az:{$el}/text()", $dom);
         if ($result->length == 1) {
             $this->{$el} = (string) $result->item(0)->data;
         }
     }
 }
Пример #8
0
 /**
  * Parse the given Offer element
  *
  * @param DOMElement $dom
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $map = array('MerchantId' => './az:Merchant/az:MerchantId/text()', 'MerchantName' => './az:Merchant/az:Name/text()', 'GlancePage' => './az:Merchant/az:GlancePage/text()', 'Condition' => './az:OfferAttributes/az:Condition/text()', 'OfferListingId' => './az:OfferListing/az:OfferListingId/text()', 'Price' => './az:OfferListing/az:Price/az:Amount/text()', 'CurrencyCode' => './az:OfferListing/az:Price/az:CurrencyCode/text()', 'Availability' => './az:OfferListing/az:Availability/text()', 'IsEligibleForSuperSaverShipping' => './az:OfferListing/az:IsEligibleForSuperSaverShipping/text()');
     foreach ($map as $param_name => $xquery) {
         $query_result = $xpath->query($xquery, $dom);
         if ($query_result->length <= 0) {
             continue;
         }
         $text = $query_result->item(0);
         if (!$text instanceof DOMText) {
             continue;
         }
         $this->{$param_name} = (string) $text->data;
     }
     if (isset($this->IsEligibleForSuperSaverShipping)) {
         $this->IsEligibleForSuperSaverShipping = (bool) $this->IsEligibleForSuperSaverShipping;
     }
 }
Пример #9
0
 /**
  * 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'));
 }
Пример #10
0
 /**
  * Checking if signature Encryption due on August 15th for Amazon Webservice API is working correctly.
  *
  * @dataProvider dataSignatureEncryption
  * @group ZF-7033
  */
 public function testSignatureEncryption($baseUri, $params, $expectedStringToSign, $expectedSignature)
 {
     $this->assertEquals($expectedStringToSign, Amazon\Amazon::buildRawSignature($baseUri, $params));
     $this->assertEquals($expectedSignature, rawurlencode(Amazon\Amazon::computeSignature($baseUri, '1234567890', $params)));
 }
Пример #11
0
 /**
  * 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;
 }
Пример #12
0
 /**
  * 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;
     }
 }
Пример #13
0
 /**
  * Parse the given <Item> element
  *
  * @param DOMElement $dom
  *
  * @group ZF-9547
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
     $this->ASIN = $xpath->query('./az:ASIN/text()', $dom)->item(0)->data;
     $result = $xpath->query('./az:DetailPageURL/text()', $dom);
     if ($result->length == 1) {
         $this->DetailPageURL = $result->item(0)->data;
     }
     if ($xpath->query('./az:ItemAttributes/az:ListPrice', $dom)->length >= 1) {
         $this->CurrencyCode = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
         $this->Amount = (int) $xpath->query('./az:ItemAttributes/az:ListPrice/az:Amount/text()', $dom)->item(0)->data;
         $this->FormattedPrice = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:FormattedPrice/text()', $dom)->item(0)->data;
     }
     $result = $xpath->query('./az:ItemAttributes/az:*/text()', $dom);
     if ($result->length >= 1) {
         foreach ($result as $v) {
             if (isset($this->{$v->parentNode->tagName})) {
                 if (is_array($this->{$v->parentNode->tagName})) {
                     array_push($this->{$v->parentNode->tagName}, (string) $v->data);
                 } else {
                     $this->{$v->parentNode->tagName} = array($this->{$v->parentNode->tagName}, (string) $v->data);
                 }
             } else {
                 $this->{$v->parentNode->tagName} = (string) $v->data;
             }
         }
     }
     foreach (array('SmallImage', 'MediumImage', 'LargeImage') as $im) {
         $result = $xpath->query("./az:ImageSets/az:ImageSet[position() = 1]/az:{$im}", $dom);
         if ($result->length == 1) {
             $this->{$im} = new Image($result->item(0));
         }
     }
     $result = $xpath->query('./az:SalesRank/text()', $dom);
     if ($result->length == 1) {
         $this->SalesRank = (int) $result->item(0)->data;
     }
     $result = $xpath->query('./az:CustomerReviews/az:Review', $dom);
     if ($result->length >= 1) {
         foreach ($result as $review) {
             $this->CustomerReviews[] = new CustomerReview($review);
         }
         $this->AverageRating = (double) $xpath->query('./az:CustomerReviews/az:AverageRating/text()', $dom)->item(0)->data;
         $this->TotalReviews = (int) $xpath->query('./az:CustomerReviews/az:TotalReviews/text()', $dom)->item(0)->data;
     }
     $result = $xpath->query('./az:EditorialReviews/az:*', $dom);
     if ($result->length >= 1) {
         foreach ($result as $r) {
             $this->EditorialReviews[] = new EditorialReview($r);
         }
     }
     $result = $xpath->query('./az:SimilarProducts/az:*', $dom);
     if ($result->length >= 1) {
         foreach ($result as $r) {
             $this->SimilarProducts[] = new SimilarProduct($r);
         }
     }
     $result = $xpath->query('./az:ListmaniaLists/*', $dom);
     if ($result->length >= 1) {
         foreach ($result as $r) {
             $this->ListmaniaLists[] = new ListmaniaList($r);
         }
     }
     $result = $xpath->query('./az:Tracks/az:Disc', $dom);
     if ($result->length > 1) {
         foreach ($result as $disk) {
             foreach ($xpath->query('./*/text()', $disk) as $t) {
                 // TODO: For consistency in a bugfix all tracks are appended to one single array
                 // Erroreous line: $this->Tracks[$disk->getAttribute('number')] = (string) $t->data;
                 $this->Tracks[] = (string) $t->data;
             }
         }
     } elseif ($result->length == 1) {
         foreach ($xpath->query('./*/text()', $result->item(0)) as $t) {
             $this->Tracks[] = (string) $t->data;
         }
     }
     $result = $xpath->query('./az:Offers', $dom);
     $resultSummary = $xpath->query('./az:OfferSummary', $dom);
     if ($result->length > 1 || $resultSummary->length == 1) {
         $this->Offers = new OfferSet($dom);
     }
     $result = $xpath->query('./az:Accessories/*', $dom);
     if ($result->length > 1) {
         foreach ($result as $r) {
             $this->Accessories[] = new Accessories($r);
         }
     }
     $this->_dom = $dom;
 }
Пример #14
0
 /**
  * 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;
 }