Пример #1
0
 /**
  * @param $asin
  * @return mixed
  * @throws \Exception
  */
 protected function runImageLookup($asin)
 {
     $lookup = new Lookup();
     $lookup->setItemId($asin);
     $lookup->setResponseGroup(array('Images'));
     return $this->apaiIO->runOperation($lookup);
 }
 /**
  * @param $asinList
  */
 public function getCompetivePriceForAsin($asinList)
 {
     $lookup = new Lookup();
     $lookup->setItemId($asinList);
     //$lookup->setMerchantId("test");
     $lookup->setResponseGroup(array('Offers'));
     $formattedResponse = $this->service->runOperation($lookup);
     $simpleXML = simplexml_load_string($formattedResponse);
     return $simpleXML;
 }
function GetProductInfo($arrIsbn)
{
    $conf = new GenericConfiguration();
    $isbns = implode(',', $arrIsbn);
    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);
    $lookup = new Lookup();
    // $lookup->setItemId('B0040PBK32,B00MEKHLLA');
    $lookup->setItemId($isbns);
    $lookup->setResponseGroup(array('Large', 'Small'));
    $formattedResponse = $apaiIO->runOperation($lookup);
    $dom = new DOMDocument();
    $dom->loadXML($formattedResponse);
    $arrResponse = xml_to_array($dom);
    return $arrResponse;
}
Пример #4
0
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=');
// $cartAdd->addItem('B003YL444A', 1);
// $formattedResponse = $apaiIO->runOperation($cartAdd);
// var_dump($formattedResponse);
$conf->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\XmlToDomDocument');
$lookup = new Lookup();
$lookup->setItemId('B0040PBK32');
$lookup->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($lookup, $configuration);
//var_dump($formattedResponse);
$lookup = new SimilarityLookup();
$lookup->setItemId('B0040PBK32');
$lookup->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($lookup);
$conf->setRequest('\\ApaiIO\\Request\\Soap\\Request');
$conf->setResponseTransformer('\\ApaiIO\\ResponseTransformer\\ObjectToArray');
$lookup = new SimilarityLookup();
$lookup->setItemId('B0040PBK32');
$lookup->setResponseGroup(array('Large', 'Small'));
$formattedResponse = $apaiIO->runOperation($lookup, $conf);
//var_dump($formattedResponse);
$conf->setResponseTransformer(new \ApaiIO\ResponseTransformer\ObjectToArray());
$browseNodeLookup = new BrowseNodeLookup();
Пример #5
0
});
$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));
});
$app->get('/amazon/lookup/:asin', function ($asin) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $apaiIo = new ApaiIO($conf);
    $lookup = new Lookup();
    $lookup->setItemId($asin);
    $lookup->setResponseGroup(array('Large'));
    // More detailed information
    $response = $apaiIo->runOperation($lookup);
    echo json_encode(simplexml_load_string($response));
});
$app->get('/amazon/similar/:asin', function ($asin) {
    $conf = new GenericConfiguration();
    $conf->setCountry('com')->setAccessKey(getenv('AMAZON_ACCESS'))->setSecretKey(getenv('AMAZON_SECRET'))->setAssociateTag(getenv('AMAZON_ASSOCIATE_TAG'));
    $apaiIo = new ApaiIO($conf);
    $similaritylookup = new SimilarityLookup();
    $similaritylookup->setItemId($asin);
    $response = $apaiIo->runOperation($similaritylookup);
    echo json_encode(simplexml_load_string($response));
});
$app->run();
 /**
  * @param array $asins
  * @param $countryCode
  * @param string $idType
  * @return \SimpleXMLElement
  * @throws \Exception
  */
 protected function fetchByASINs($asins = array(), $countryCode, $idType = Lookup::TYPE_ASIN)
 {
     $this->getConfiguration()->setCountry($countryCode);
     $apaiIO = new ApaiIO($this->getConfiguration());
     $lookup = new Lookup();
     $lookup->setIdType($idType);
     $lookup->setItemIds($asins);
     $lookup->setResponseGroup(array('Large'));
     // More detailed information
     $response = $apaiIO->runOperation($lookup);
     $xmlResponse = simplexml_load_string($response);
     return $xmlResponse;
 }
Пример #7
0
<?php

include 'config.php';
require_once "lib/phpfastcache.php";
//AMAZON API
require __DIR__ . '/vendor/autoload.php';
use ApaiIO\Configuration\GenericConfiguration;
use ApaiIO\Operations\Lookup;
use ApaiIO\ApaiIO;
$conf = new GenericConfiguration();
$conf->setCountry('com')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ANOTHER_ASSOCIATE_TAG);
$apaiIO = new ApaiIO($conf);
$search = new Lookup();
$search->setIdType('ISBN');
$search->setSearchIndex('Books');
$search->setResponseGroup(array('Images'));
//MYSQL
$mysqli = new mysqli($host, $user, $pass, $db);
if ($mysqli->connect_error) {
    die('Connect Error: ' . $mysqli->connect_error);
}
if (isset($_GET["off"]) && $_GET["off"] != '') {
    $offsetSql = $_GET["off"];
}
//API vars
//var holder for output
$json = array('books' => array());
$new = array();
// var for chart data
$chart = array("labels" => array(), "datasets" => array("label" => "My First dataset", "fillColor" => "rgba(220,220,220,0.2)", "strokeColor" => "rgba(220,220,220,1)", "pointColor" => "rgba(220,220,220,1)", "pointStrokeColor" => "#fff", "pointHighlightFill" => "#fff", "pointHighlightStroke" => "rgba(220,220,220,1)"));
$levtwo = array("data" => array());
Пример #8
0
 /**
  * @Route(
  *    path = "/insert/insertByUPC/{upc}",
  *    name = "insertByUPC",
  *    defaults={"upc" = "012345678901"}
  * )
  */
 public function insertByUPCAction(Request $request, $upc)
 {
     /* TODO: DISPLAYING A MESSAGE WHEN UPC VALUE HAS NOT BEEN FOUND */
     /* DISPLAYING THE INPUT FORM */
     $upcQuery = array('upc' => '');
     $form = $this->createFormBuilder($upcQuery)->setAction($this->generateUrl('insertByUPC'))->setMethod('GET')->add('upc', TextType::class)->add('save', SubmitType::class, array('label' => 'UPC search and possible insertion'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted()) {
         // Form has been submitted or upc has been passed in the URL
         $data = $form->getData();
         if ($data['upc'] != '') {
             $upc = $data['upc'];
         }
         // ... perform some action, such as saving the task to the database
         //$resString = print_r($data);
         //return(new Response($resString));
         /*
         searching by UPC,
         if found creating an object and
         setting its properties accordingly
         */
         // 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');
         $lookup = new Lookup();
         $lookup->setIdType('UPC');
         //$lookup->setItemId('724384062026');
         //$lookup->setItemId('724382912521');
         $lookup->setItemId($upc);
         $lookup->setResponseGroup(array('ItemAttributes', 'Images', 'Tracks'));
         // More detailed information
         $apaiIo = new ApaiIO($conf);
         $response = $apaiIo->runOperation($lookup);
         $logger = $this->get('logger');
         // Cozy variable to shorten object invocation
         $item = $response->Items->Item;
         // TODO:
         // refining the way to decide if a result has been found
         if (property_exists($item->ItemAttributes, 'UPC')) {
             /* Item with that UPC has been found */
             $newRecord = new Record();
             $newRecord->setUpc($item->ItemAttributes->UPC);
             $newRecord->setAsin($item->ASIN);
             $newRecord->setCoverImageUrl($item->LargeImage->URL);
             if (property_exists($item->ItemAttributes, 'Brand')) {
                 $newRecord->setRecordLabel($item->ItemAttributes->Brand);
             } else {
                 $newRecord->setRecordLabel($item->ItemAttributes->Label);
             }
             $newRecord->setYear(substr($item->ItemAttributes->ReleaseDate, 0, 4));
             $logger->info('Vediamo: ' . json_encode($item));
             if (property_exists($item->ItemAttributes, 'Artist')) {
                 if (is_array($item->ItemAttributes->Artist)) {
                     // MEMO
                     // "implode" and "join" are the same, they are alias
                     $newRecord->setArtist(implode(', ', $item->ItemAttributes->Artist));
                 } else {
                     $newRecord->setArtist($item->ItemAttributes->Artist);
                 }
             } else {
                 if (property_exists($item->ItemAttributes, 'Creator')) {
                     // UPC: 828767523224
                     // ASIN: B000C6NONM
                     // Fabrizio De André, "In direzione ostinata e contraria"
                     $newRecord->setArtist($item->ItemAttributes->Creator->_);
                     // "Creator":{"_":"Fabrizio De Andr\u00e9","Role":"Performer"},
                     // TODO
                     // Porting this mechanism in searchByText
                 } else {
                     // Couldn't extract artist info
                 }
             }
             $newRecord->setTitle($item->ItemAttributes->Title);
             $newRecord->setMediaType($item->ItemAttributes->Binding);
             $newRecord->setMediaCount($item->ItemAttributes->NumberOfItems);
             // each media item has a track list
             $trackLists = array();
             if (property_exists($item, 'Tracks')) {
                 // Having the number of items does not mean tracks info is available...
                 // 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 ' . $newRecord->getMediaCount() . ' media, but all tracks are in just one list.');
                     $oneListOnly = 1;
                 }
                 if ($item->ItemAttributes->NumberOfItems < 2 || $oneListOnly) {
                     //$newRecord->setMediaCount(1);
                     // One item only, one list, see EX00 at the bottom
                     $totalTracks = sizeof($item->Tracks->Disc->Track);
                     for ($i = 0; $i < $totalTracks; $i++) {
                         $tracksLists[0][] = $item->Tracks->Disc->Track[$i]->_;
                     }
                 } else {
                     // More than one media (EX01 ath the bottom)
                     for ($j = 0; $j < $item->ItemAttributes->NumberOfItems; $j++) {
                         $totalTracks = sizeof($item->Tracks->Disc[$j]->Track);
                         for ($i = 0; $i < $totalTracks; $i++) {
                             $tracksLists[$j][] = $item->Tracks->Disc[$j]->Track[$i]->_;
                         }
                     }
                 }
             } else {
                 // Tracks info is not available (no property "Tracks" in the object)
                 $logger->info('Tracks info is not available');
             }
             $newRecord->setTracksLists($tracksLists);
             $em = $this->getDoctrine()->getManager();
             $em->persist($newRecord);
             $em->flush();
             return $this->redirectToRoute('record_show', array('id' => $newRecord->getId()));
         } else {
             // TODO: DISPLAYING message telling the upc has not been found
             return new Response('upc not found');
         }
     } else {
         // Form has not been submitted and UPC has not been passed via URL
         return $this->render('AppBundle:Record:insertByUPC.html.twig', array('form' => $form->createView()));
     }
 }
Пример #9
0
 public function getitemdet($itemid)
 {
     $lookup = new Lookup();
     $lookup->setItemId($itemid);
     $lookup->setResponseGroup(array('Large'));
     // More detailed information
     $ret = $this->apaiIO->runOperation($lookup);
     return $ret;
 }