public function testapiTest() { $obj = new AmazonProductAPI(); try { $result = $obj->searchProducts("spice girls", AmazonProductAPI::DVD, "TITLE"); $data = $result->Items->Item->ItemAttributes->Title; echo $data . "\n"; $this->assertNotNull($data); } catch (Exception $e) { echo $e->getMessage(); } try { $result = $obj->searchProducts("024543602859", AmazonProductAPI::DVD, "UPC"); $data = $result->Items->Item->ItemAttributes->Title; echo $data . "\n"; $this->assertNotNull($data); } catch (Exception $e) { echo $e->getMessage(); } try { $result = $obj->getItemByUpc("014633190168", AmazonProductAPI::GAMES); $data = $result->Items->Item->ItemAttributes->Title; echo $data . "\n"; $this->assertNotNull($data); } catch (Exception $e) { echo $e->getMessage(); } try { $result = $obj->getItemByAsin("B001AVCFK6", AmazonProductAPI::DVD); $data = $result->Items->Item->ItemAttributes->Title; echo $data . "\n"; $this->assertNotNull($data); } catch (Exception $e) { echo $e->getMessage(); } try { $result = $obj->getItemByKeyword("tom petty", AmazonProductAPI::MUSIC); $data = $result->Items->Item->ItemAttributes->Title; echo $data . "\n"; $this->assertNotNull($data); } catch (Exception $e) { echo $e->getMessage(); } }
private function doAmazon($q, $name = '', $id = 0, $nfo = '', $region = 'com', $case = false, $row = '') { $amazon = new \AmazonProductAPI($this->pdo->getSetting('amazonpubkey'), $this->pdo->getSetting('amazonprivkey'), $this->pdo->getSetting('amazonassociatetag')); $ok = false; try { switch ($case) { case 'upc': $amaz = $amazon->getItemByUpc(trim($q), $region); break; case 'asin': $amaz = $amazon->getItemByAsin(trim($q), $region); break; case 'isbn': $amaz = $amazon->searchProducts(trim($q), '', "ISBN"); break; default: $amaz = false; } } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage() . PHP_EOL; unset($s, $amaz, $amazon); } if (isset($amaz) && isset($amaz->Items->Item)) { sleep(2); $type = $amaz->Items->Item->ItemAttributes->ProductGroup; switch ($type) { case 'Audible': case 'Book': case 'eBooks': $ok = $this->_doAmazonBooks($amaz, $id); break; case 'Digital Music Track': case 'Digital Music Album': case 'Music': $ok = $this->_doAmazonMusic($amaz, $id); break; case 'Bluray': case 'Movies': case 'DVD': case 'DVD & Bluray': $ok = $this->_doAmazonMovies($nfo, $amaz, $id); break; case 'Video Games': $ok = $this->_doAmazonVG($amaz, $id); break; default: echo PHP_EOL . $this->pdo->log->error("Amazon category {$type} could not be parsed for " . $name) . PHP_EOL; } } return $ok; }