See also: http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/ItemSearch.html
Author: Jan Eichhorn (exeu65@googlemail.com)
Inheritance: extends AbstractOperation
Ejemplo n.º 1
0
 public function testGetResponseGroup()
 {
     $search = new Search();
     $this->assertEquals(null, $search->getResponseGroup());
     $search->setResponseGroup(['Small', 'Medium', 'Large']);
     $this->assertEquals(['Small', 'Medium', 'Large'], $search->getResponseGroup());
 }
Ejemplo n.º 2
0
 public function testGetResponseGroup()
 {
     $search = new Search();
     static::assertEquals(null, $search->getResponseGroup());
     $search->setResponseGroup(array('Small', 'Medium', 'Large'));
     static::assertEquals(array('Small', 'Medium', 'Large'), $search->getResponseGroup());
 }
Ejemplo n.º 3
0
 public function testRestErrorRequest()
 {
     $search = new Search();
     $search->setCategory('DVD')->setPage(2);
     $res = $this->runOperation($search);
     $this->assertEquals("False", $res->Items->Request->IsValid);
 }
Ejemplo n.º 4
0
 public function search($term)
 {
     $search = new Search();
     $search->setCategory('All');
     $search->setKeywords($term);
     $search->setResponseGroup(array('Large', 'Small'));
     $ret = $this->apaiIO->runOperation($search);
     return $ret;
 }
Ejemplo n.º 5
0
 public function testamazon()
 {
     $conf = new GenericConfiguration();
     $conf->setCountry('com')->setAccessKey('AKIAIUHJDBWAEKOQI2KQ')->setSecretKey('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')->setAssociateTag('IDTAG')->setRequest('\\ApaiIO\\Request\\Soap\\Request')->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
     $search = new Search();
     $search->setCategory('All');
     $search->setKeywords('Iphone 6s');
     $search->setResponsegroup(array('Offers', 'Images'));
     $apaiIo = new ApaiIO($conf);
     $response = $apaiIo->runOperation($search);
     //return $response["Items"]["Item"][0]["ItemAttributes"]["Title"];
     return $response;
     //test
 }
function GetProductInfoByTitle($title)
{
    $conf = new GenericConfiguration();
    try {
        $conf->setCountry('com')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG);
    } catch (\Exception $e) {
        echo $e->getMessage();
    }
    $apaiIO = new ApaiIO($conf);
    $search = new Search();
    // $lookup->setItemId('B0040PBK32,B00MEKHLLA');
    $search->setCategory('Books');
    $search->setKeywords($title);
    $formattedResponse = $apaiIO->runOperation($search);
    $dom = new DOMDocument();
    $dom->loadXML($formattedResponse);
    $arrResponse = xml_to_array($dom);
    return $arrResponse;
}
Ejemplo n.º 7
0
 public function testAddOperation()
 {
     $op = new Search();
     $op->setTest('test');
     $batch = new Batch();
     $batch->addOperation($op);
     $this->assertSame('ItemSearch', $batch->getName());
     $this->assertSame(['ItemSearch.1.Test' => 'test'], $batch->getOperationParameter());
     $op2 = new Lookup();
     $batch->addOperation($op2);
     $this->assertSame('ItemSearch', $batch->getName());
     $this->assertSame(['ItemSearch.1.Test' => 'test'], $batch->getOperationParameter());
     $batch = new Batch([$op, $op2]);
     $this->assertSame('ItemSearch', $batch->getName());
     $this->assertSame(['ItemSearch.1.Test' => 'test'], $batch->getOperationParameter());
     $op3 = new Search();
     $op3->setTest2('test');
     $batch->addOperation($op3);
     $this->assertSame('ItemSearch', $batch->getName());
     $this->assertSame(['ItemSearch.1.Test' => 'test', 'ItemSearch.2.Test2' => 'test'], $batch->getOperationParameter());
 }
Ejemplo n.º 8
0
use ApaiIO\Operations\Search;
use ApaiIO\ResponseTransformer\ObjectToArray;
use ApaiIO\Operations\Lookup;
use ApaiIO\Operations\SimilarityLookup;
use ApaiIO\Operations\CartCreate;
use ApaiIO\ApaiIO;
use ApaiIO\Operations\BrowseNodeLookup;
use ApaiIO\Operations\CartAdd;
$conf = new GenericConfiguration();
try {
    $conf->setCountry('de')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG);
} catch (\Exception $e) {
    echo $e->getMessage();
}
$apaiIO = new ApaiIO($conf);
$search = new Search();
$search->setCategory('DVD');
$search->setActor('Bruce Willis');
$search->setKeywords('Stirb Langsam');
$search->setPage(3);
$search->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($search);
echo $formattedResponse;
exit;
// var_dump($formattedResponse);
// $cartCreate = new CartCreate();
// $cartCreate->addItem("B0040PBK32", 1);
// $formattedResponse = $apaiIO->runOperation($cartCreate);
// $cartAdd = new CartAdd();
// $cartAdd->setCartId('280-6695255-7497359');
// $cartAdd->setHMAC('LxQ0BKVBeQTrzFCXvIoa/262EcU=');
Ejemplo n.º 9
0
 /**
  * @expectedException RuntimeException
  */
 public function testOverrideOptionsOverSetOptionsWithInvalidKey()
 {
     $request = new Request();
     $request->setOptions(array(-11 => __METHOD__));
     $request->setConfiguration($this->conf);
     $search = new Search();
     $search->setCategory('DVD')->setPage(2);
     $request->perform($search);
 }
Ejemplo n.º 10
0
require 'vendor/autoload.php';
//for amazon
use ApaiIO\ApaiIO;
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Search;
use ApaiIO\Operations\BrowseNodeLookup;
use ApaiIO\Operations\Lookup;
use ApaiIO\Operations\SimilarityLookup;
error_reporting(-1);
//tell me stuff
$app = new \Slim\Slim();
$app->get('/amazon/search/:keywords', function ($keywords) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $search = new Search();
    $search->setResponseGroup(array('Large'));
    // More detailed information
    $search->setKeywords($keywords);
    $apaiIo = new ApaiIO($conf);
    $response = $apaiIo->runOperation($search);
    echo json_encode(simplexml_load_string($response));
});
$app->get('/amazon/node/:browsenode', function ($browsenode) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $browseNodeLookup = new BrowseNodeLookup();
    $browseNodeLookup->setNodeId($browsenode);
    $apaiIo = new ApaiIO($conf);
    $response = $apaiIo->runOperation($browseNodeLookup);
    echo json_encode(simplexml_load_string($response));
Ejemplo n.º 11
0
 /**
  * @Route(
  *    path = "/search/searchByText/{text}",
  *    name = "searchByText",
  *    defaults={"text" = "012345678901"}
  * )
  */
 public function searchByTextAction(Request $request)
 {
     /* TODO: DISPLAYING A MESSAGE WHEN NOTHING HAS BEEN FOUND */
     /* DISPLAYING THE INPUT FORM */
     $textQuery = array('text' => '');
     $form = $this->createFormBuilder($textQuery)->setAction($this->generateUrl('searchByText'))->setMethod('GET')->add('text', TextType::class, array('label' => 'Keywords', 'attr' => array('class' => 'form-control')))->add('submit', SubmitType::class, array('label' => 'Look for possible equivalent items', 'attr' => array('class' => 'btn btn-default')))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted()) {
         // Form has been submitted or some text has been passed in the URL
         $data = $form->getData();
         if ($data['text'] != '') {
             $text = $data['text'];
         }
         // ... perform some action, such as saving the task to the database
         //$resString = print_r($data);
         //return(new Response($resString));
         /*
         searching by text,
         if found displaying what has been found
         */
         // TODO:
         // moving configuration data outside in a configuration file
         $conf = new GenericConfiguration();
         $conf->setCountry('com')->setAccessKey('AKIAJD57F37W2KGLXEVQ')->setSecretKey('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')->setAssociateTag('quercusroburn-20')->setRequest('\\ApaiIO\\Request\\Soap\\Request');
         $query = new Search();
         $query->setKeywords($text);
         $query->setCategory('Music');
         $query->setResponseGroup(array('ItemAttributes', 'Images', 'Tracks'));
         // More detailed information
         $apaiIo = new ApaiIO($conf);
         $response = $apaiIo->runOperation($query);
         $logger = $this->get('logger');
         $records = array();
         if (property_exists($response, 'Items')) {
             // handlig the case when one item only is returned,
             // in that case $response->Items->Item is not an array!!!
             $results = array();
             if (is_array($response->Items->Item)) {
                 $results = $response->Items->Item;
             } else {
                 $results[] = $response->Items->Item;
             }
             foreach ($results as $item) {
                 $logger->info('----------------------------');
                 $record = new Record();
                 // ASIN
                 $logger->info("ASIN: {$item->ASIN}");
                 $record->setAsin($item->ASIN);
                 // TODO:
                 // now getting UPC just for testing purposes,
                 // this should be stopped...
                 if (property_exists($item->ItemAttributes, 'UPC')) {
                     $logger->info('UPC: ' . $item->ItemAttributes->UPC);
                 } else {
                     $logger->info('NO UPC!');
                 }
                 // Artist
                 // Structure changes if several artists are listed
                 if (property_exists($item->ItemAttributes, 'Artist')) {
                     if (!is_array($item->ItemAttributes->Artist)) {
                         $record->setArtist($item->ItemAttributes->Artist);
                     } else {
                         $logger->info('Here it is the array: ' . print_r($item->ItemAttributes->Artist, true) . ' - Seen as: ' . gettype($item->ItemAttributes->Artist) . ' - size: ' . sizeof($item->ItemAttributes->Artist));
                         $artist = 'Various artists (';
                         for ($i = 1; $i < sizeof($item->ItemAttributes->Artist); $i++) {
                             $artist .= $item->ItemAttributes->Artist[$i];
                             if ($i < sizeof($item->ItemAttributes->Artist) - 1) {
                                 $artist .= ', ';
                             }
                         }
                         $artist .= ')';
                         $record->setArtist($artist);
                         $logger->info('Values: ' . join(' - ', $item->ItemAttributes->Artist));
                     }
                     $logger->info('Artist: ' . $record->getArtist());
                 }
                 // title
                 $record->setTitle($item->ItemAttributes->Title);
                 $logger->info('Title: ' . $record->getTitle());
                 // label
                 if (property_exists($item->ItemAttributes, 'Brand')) {
                     $record->setRecordLabel($item->ItemAttributes->Brand);
                 } else {
                     if (property_exists($item->ItemAttributes, 'Label')) {
                         $record->setRecordLabel($item->ItemAttributes->Label);
                     } else {
                         //
                     }
                 }
                 $logger->info('Label: ' . $record->getRecordLabel());
                 // Year
                 if (property_exists($item->ItemAttributes, 'ReleaseDate')) {
                     $record->setYear(substr($item->ItemAttributes->ReleaseDate, 0, 4));
                     $logger->info('Label: ' . $record->getYear());
                 } else {
                     $logger->info('\'ReleaseDate\' not available, so dunno how to get the year...');
                 }
                 // Media count
                 if (property_exists($item->ItemAttributes, 'NumberOfItems')) {
                     $record->setMediaCount($item->ItemAttributes->NumberOfItems);
                     $logger->info('Media count: ' . $record->getMediaCount());
                 } else {
                     if (property_exists($item->ItemAttributes, 'NumberOfDiscs')) {
                         $record->setMediaCount($item->ItemAttributes->NumberOfDiscs);
                         $logger->info('Media count: ' . $record->getMediaCount());
                     } else {
                         //$logger->info(print_r($item->ItemAttributes, true));
                         $logger->info('Number of media not available. Now what?! Tentatively I guess the value \'1\'.');
                         $record->setMediaCount('1');
                         $item->ItemAttributes->NumberOfItems = '1';
                     }
                 }
                 // Media type
                 $record->setMediaType($item->ItemAttributes->Binding);
                 $logger->info('Media type: ' . $record->getMediaType());
                 // Cover image (it may be unavailable)
                 if (property_exists($item, 'LargeImage')) {
                     $record->setCoverImageUrl($item->LargeImage->URL);
                     $logger->info('Cover image URL: ' . $record->getCoverImageUrl());
                 }
                 // each media item has a track list
                 $trackLists = array();
                 if (property_exists($item, 'Tracks')) {
                     // Tracks info is not for granted...
                     // When number of media/items is greater than 1, but
                     // the tracks list is just one
                     // (it happened at least once with B000B66OVW, see EX03 below)
                     // then ->Tracks->Disc is not an array at it should be
                     // when more than one media are actually present
                     $oneListOnly = 0;
                     if (!is_array($item->Tracks->Disc)) {
                         $logger->info('The web service reported ' . $record->getMediaCount() . ' media, but all tracks are in just one list.');
                         $oneListOnly = 1;
                     }
                     if ($record->getMediaCount() < 2 || $oneListOnly) {
                         // one item only, one list
                         if (property_exists($item->Tracks, 'Disc')) {
                             $totalTracks = sizeof($item->Tracks->Disc->Track);
                             for ($i = 0; $i < $totalTracks; $i++) {
                                 $tracksLists[0][] = $item->Tracks->Disc->Track[$i]->_;
                             }
                         } else {
                             $logger->info('Couldn\'t find "Disc"...   ' . print_r($item->Tracks, true));
                         }
                     } else {
                         for ($j = 0; $j < $record->getMediaCount(); $j++) {
                             $totalTracks = sizeof($item->Tracks->Disc[$j]->Track);
                             for ($i = 0; $i < $totalTracks; $i++) {
                                 $tracksLists[$j][] = $item->Tracks->Disc[$j]->Track[$i]->_;
                             }
                         }
                     }
                     $record->setTracksLists($tracksLists);
                 } else {
                     // Tracks info is not available (no property "Tracks" in the object)
                     $logger->info('Tracks info is not available');
                 }
                 // Appending the record to the list of possible records
                 $records[] = $record;
             }
         }
         // TODO:
         // saving the array of results in session
         $session = new Session();
         //$session->start();
         $session->set('results', $records);
         $logger->info('Session ID: ' . $session->getId());
         // Returning the list of the results
         // TODO:
         // handling in the template the id of each record, so that in can be passed
         // afterwards for insertion and recovered from session without re-fetching
         // its data
         return $this->render('AppBundle:Record:results.html.twig', array('records' => $records));
     }
     // The form has not been submitted, displaying the form
     return $this->render('AppBundle:Record:searchByText.html.twig', array('form' => $form->createView()));
 }
Ejemplo n.º 12
0
 /**
  * @expectedException BadFunctionCallException
  */
 public function testAbstractOperationInvalidMethodName()
 {
     $search = new Search();
     $search->foo();
 }
Ejemplo n.º 13
0
 public function testGetBrowseNode()
 {
     $search = new Search();
     static::assertEquals(null, $search->getBrowseNode());
     $search->setBrowseNode(123);
     static::assertEquals(123, $search->getBrowseNode());
 }
Ejemplo n.º 14
0
 public function testNodeGetterAndSetter()
 {
     $search = new Search();
     $search->setBrowseNode(10967581);
     $this->assertEquals(10967581, $search->getBrowseNode());
 }
Ejemplo n.º 15
0
 /**
  * @param string  $artist
  * @param string  $albumName
  * @param boolean $titlePrecision
  *
  * @return \SimpleXMLElement
  *
  * @throws \Exception
  */
 public function tracksSearch($artist = "", $albumName = "", $titlePrecision = false)
 {
     if (!isset($this->conf) && !isset($this->apaiIO)) {
         $this->setUp();
     }
     if (empty($artist)) {
         throw new \InvalidArgumentException(sprintf("artist argument passed to %s must be a string and cannot be null", __METHOD__));
     }
     if (empty($albumName)) {
         throw new \InvalidArgumentException(sprintf("albumName argument passed to %s must be a string and cannot be null", __METHOD__));
     }
     $search = new Search();
     $search->setCategory('Music')->setCondition('All')->setRelationshipType('Tracks')->setResponseGroup(array('ItemAttributes', 'Tracks', 'Images'))->setKeywords(sprintf("%s %s", $artist, $albumName));
     // title value makes search fail more often
     if ($titlePrecision) {
         $search->setTitle($albumName);
     }
     $xmlResponse = $this->apaiIO->runOperation($search);
     return new \SimpleXMLElement($xmlResponse);
 }
Ejemplo n.º 16
0
// https://aws.amazon.com/fr/api-gateway/pricing/
// https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
namespace Acme\Demo;

require __DIR__ . '/vendor/autoload.php';
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Search;
use ApaiIO\ApaiIO;
include_once 'param.php';
$conf = new GenericConfiguration();
$conf->setCountry('fr')->setAccessKey(AMAZON_API_KEY)->setSecretKey(AMAZON_API_SECRET_KEY)->setAssociateTag(AMAZON_ASSOCIATE_TAG)->setRequest('\\ApaiIO\\Request\\Soap\\Request')->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
// ->setResponseTransformer('\ApaiIO\ResponseTransformer\ObjectToArray');
$apaiIO = new ApaiIO($conf);
// http://exeu.github.io/apai-io/
// http://exeu.github.io/apai-io/basic-usage.html
$search = new Search();
$search->setCategory('Books');
// DVD
// $search->setActor('Bruce Willis');
// http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html
$search->setKeywords('Le seigneur des anneaux');
$search->setResponsegroup(array('Images', 'EditorialReview'));
$formattedResponse = $apaiIO->runOperation($search);
file_put_contents('amazon.json', json_encode($formattedResponse));
file_put_contents('image.jpg', file_get_contents($formattedResponse['Items']['Item'][0]["LargeImage"]['URL']));
var_dump($formattedResponse['Items']['Item'][0]["EditorialReviews"]["EditorialReview"]["Content"]);
// echo $formattedResponse['Items']['Item'][0]["LargeImage"]['URL']
// use ApaiIO\Operations\BrowseNodeLookup;
// $browseNodeLookup = new BrowseNodeLookup();
// $browseNodeLookup->setNodeId(163357);
// $response = $apaiIO->runOperation($browseNodeLookup);