/** * @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; }
public function testApaiIOTransformResponse() { $conf = new GenericConfiguration(); $operation = new Search(); $request = $this->prophesize('\\ApaiIO\\Request\\RequestInterface'); $request->perform($operation, $conf)->shouldBeCalledTimes(1)->willReturn(['a' => 'b']); $conf->setRequest($request->reveal()); $responseTransformer = $this->prophesize('\\ApaiIO\\ResponseTransformer\\ResponseTransformerInterface'); $responseTransformer->transform(['a' => 'b'])->shouldBeCalledTimes(1); $conf->setResponseTransformer($responseTransformer->reveal()); $apaiIO = new ApaiIO($conf); $apaiIO->runOperation($operation); }
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; }
/** * @param string $ASIN * * @return \SimpleXMLElement * * @throws \Exception */ public function findAlbumDetail($ASIN) { if (!isset($this->conf) && !isset($this->apaiIO)) { $this->setUp(); } $search = new Lookup(); $search->setCondition('All')->setItemId($ASIN)->setIdType("ASIN")->setRelationshipType('Tracks')->setResponseGroup(array('RelatedItems', 'Small')); $xmlResponse = $this->apaiIO->runOperation($search); $xml = new \SimpleXMLElement($xmlResponse); return $xml; }
* * 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\CartAdd; use ApaiIO\Operations\CartCreate; $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); $cartCreate = new CartCreate(); $cartCreate->addItem("B0040PBK32", 1); $formattedResponse = $apaiIO->runOperation($cartCreate); echo $formattedResponse; echo "<hr>"; $cartAdd = new CartAdd(); $cartAdd->setCartId('280-6695255-7497359'); $cartAdd->setHMAC('LxQ0BKVBeQTrzFCXvIoa/262EcU='); $cartAdd->addItem('B003YL444A', 1); $formattedResponse = $apaiIO->runOperation($cartAdd); echo $formattedResponse;
protected function runOperation($operation) { $apaiIo = new ApaiIO($this->conf); $response = $apaiIo->runOperation($operation); $xml = simplexml_load_string($response); $xml->registerXPathNamespace('a', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01'); return $xml; }
}); $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();
* 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\SimilarityLookup; $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); $lookup = new SimilarityLookup(); $lookup->setItemId('B0040PBK32'); $lookup->setResponseGroup(array('Large', 'Small')); $formattedResponse = $apaiIO->runOperation($lookup); echo $formattedResponse; echo "<hr>"; // Changing to SOAP and ObjectToArray ResponseTransformer $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); var_dump($formattedResponse);
/** * @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; }
/** * @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())); }
protected function runOperation($operation) { $apaiIo = new ApaiIO($this->conf); $response = $apaiIo->runOperation($operation); return $response; }
* 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; $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); } catch (\Exception $e) { echo $e->getMessage(); } $apaiIO = new ApaiIO($conf); $search1 = new \ApaiIO\Operations\Search(); $search1->setCategory('DVD'); $search1->setActor('Bruce Willis'); $search1->setKeywords('Stirb Langsam'); $search1->setPage(3); $search2 = new \ApaiIO\Operations\Search(); $search2->setCategory('DVD'); $search2->setActor('Arnold Schwarzenegger'); $search2->setKeywords('Terminator'); $batch = new \ApaiIO\Operations\Batch(); $batch->addOperation($search1); $batch->addOperation($search2); $formattedResponse = $apaiIO->runOperation($batch); echo $formattedResponse;
* 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\BrowseNodeLookup; $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); // Changing to SOAP and ObjectToArray ResponseTransformer $conf->setRequest('\\ApaiIO\\Request\\Soap\\Request'); $conf->setResponseTransformer(new \ApaiIO\ResponseTransformer\ObjectToArray()); $browseNodeLookup = new BrowseNodeLookup(); $browseNodeLookup->setNodeId(542064); $formattedResponse = $apaiIO->runOperation($browseNodeLookup); var_dump($formattedResponse);
use ApaiIO\Configuration\GenericConfiguration; 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');
* 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\Search; $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;
/** * @expectedException Exception */ public function testApaiIOWithoutConfig() { $operation = new Search(); $apaiIO = new ApaiIO(); $apaiIO->runOperation($operation); }