/** * @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; }
protected function getObjectBy($identifier, $country, $idType = Lookup::TYPE_ASIN) { $this->getConfiguration()->setCountry($country); $apaiIO = new ApaiIO($this->getConfiguration()); $lookup = new Lookup(); $lookup->setIdType($idType); $lookup->setItemId($identifier); $lookup->setResponseGroup(array('Large')); // More detailed information $response = $apaiIO->runOperation($lookup); $xmlResponse = simplexml_load_string($response); return $xmlResponse; }
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; }
$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='); // $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());
public function testGetItemId() { $lookup = new Lookup(); $this->assertEquals(null, $lookup->getItemId()); $lookup->setItemId('B0117IJ4LE'); $this->assertEquals('B0117IJ4LE', $lookup->getItemId()); }
}); $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();
$levtwo = array("data" => array()); //SQL 1 //$result = $mysqli->query("SELECT isbn FROM books_ok ORDER BY RAND() limit 1"); $result = $mysqli->query("SELECT * FROM ranks WHERE b_isbn= (\n\t\t\t\t\t\t\t\tSELECT b_isbn\n\t\t\t\t\t\t\t\tFROM ranks \n\t\t\t\t\t\t\t\tgroup by b_isbn \n\t\t\t\t\t\t\t\torder by count(published_date) DESC\n\t\t\t\t\t\t\t\tlimit 1\n\t\t\t\t\t\t\t\toffset " . $offsetSql . "\t)\n\t\t\t\t\t\t\t\tgroup by published_date\n\t\t\t\t\t\t\t\tORDER BY ranks.bestsellers_date DESC\n\t\t\t\t\t\t\t\tlimit 20"); // SELECT b_isbn, count(published_date) as cca, FROM ranks group by b_isbn order by cca DESC limit 1 offset 3 // while ($aditional = $result->fetch_assoc()) { // $isbn = $aditional['isbn']; // } while ($aditional = $result->fetch_assoc()) { array_push($chart["labels"], $aditional["published_date"]); $levtwo["data"][] = $aditional["rank"]; //$chart["datasets"]["data"][]=$aditional["rank"]; $isbn = $aditional["b_isbn"]; } // AMAZON API new $search->setItemId($isbn); $formattedResponse = $apaiIO->runOperation($search); $xml = simplexml_load_string($formattedResponse, "SimpleXMLElement", LIBXML_NOCDATA); //$json = json_encode($xml); //$array['amz'] = json_decode($json); //$array['amz'] = $json; //var_dump($array) ; ///////////////////////////////////// //$amz_api ->Items->Item->LargeImage->URL; $search->setItemId('1455521256'); //array_push($new, $xml); $new["amz"] = $xml; $g_api = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:" . $isbn); //$nvar['gog'] = json_decode($g_api); // $nvar['gog'] = $g_api; //array_push($new, $g_api); $new["gog"] = json_decode($g_api);
public function testSchemeSwitch() { $body = $this->prophesize('\\Psr\\Http\\Message\\StreamInterface'); $body->getContents()->shouldBeCalledTimes(1)->willReturn('ABC'); $response = $this->prophesize('\\Psr\\Http\\Message\\ResponseInterface'); $response->getBody()->shouldBeCalledTimes(1)->willReturn($body->reveal()); $client = $this->prophesize('\\GuzzleHttp\\ClientInterface'); $client->send(Argument::that(function ($request) { if (!$request instanceof RequestInterface) { return false; } $uri = $request->getUri(); $this->assertSame('https', $uri->getScheme()); return true; }))->shouldBeCalledTimes(1)->willReturn($response->reveal()); $request = new GuzzleRequest($client->reveal()); $request->setScheme('HTTPS'); $operation = new Lookup(); $operation->setItemId('1'); $config = new GenericConfiguration(); $config->setAccessKey('abc'); $config->setAssociateTag('def'); $config->setCountry('DE'); $config->setSecretKey('ghi'); $config->setAccessKey('jkl'); $request->perform($operation, $config); }
* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'bootstrap.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Config.php'; use ApaiIO\ApaiIO; use ApaiIO\Configuration\GenericConfiguration; use ApaiIO\Operations\Lookup; $conf = new GenericConfiguration(); $client = new \GuzzleHttp\Client(); $request = new \ApaiIO\Request\GuzzleRequest($client); try { $conf->setCountry('de')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG)->setRequest($request)->setResponseTransformer(new \ApaiIO\ResponseTransformer\XmlToDomDocument()); } catch (\Exception $e) { echo $e->getMessage(); } $apaiIO = new ApaiIO($conf); $lookup = new Lookup(); $lookup->setItemId('B0040PBK32,B00MEKHLLA'); $lookup->setResponseGroup(array('Large', 'Small')); $formattedResponse = $apaiIO->runOperation($lookup); var_dump($formattedResponse);
public function testSetter() { $lookup = new Lookup(); $lookup->setItemId('B1234'); }
/** * @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())); } }
public function getitemdet($itemid) { $lookup = new Lookup(); $lookup->setItemId($itemid); $lookup->setResponseGroup(array('Large')); // More detailed information $ret = $this->apaiIO->runOperation($lookup); return $ret; }