Example #1
0
 private function getAlbumXMLFromAmazon($albumInfoArray)
 {
     if (count($albumInfoArray) >= 2) {
         // Some data from cds.csv is passing in empty arrays to this method
         $strippedAlbumName = $albumInfoArray[0] . "-" . $albumInfoArray[1];
         //This should be a unique and human readable file name
         $strippedAlbumName = preg_replace("/[^a-zA-Z0-9]/", "", $strippedAlbumName);
         if (is_array($albumInfoArray) && strlen($strippedAlbumName) > 0) {
             $myCache = new Caching("./MashupCache/Amazon/", $strippedAlbumName, 'xml');
             if ($myCache->needToRenewData()) {
                 try {
                     $result = $this->amazonAPI->getAlbumCoverByArtistAndTitle($albumInfoArray[0], $albumInfoArray[1]);
                 } catch (Exception $e) {
                     echo $e->getMessage();
                 }
                 $myCache->saveXMLToFile($result);
                 // Save new data before we return it to the caller of the method
             } else {
                 // It doesn't need to be renewed so use local copy
                 $result = $myCache->getLocalXML();
             }
         } else {
             throw new Exception('Incorrect data type passed to getAlbumXMLFromAmazon()');
         }
     } else {
         // What to do about this?  Currently it is throwing a warning...
         $result = null;
     }
     return $result;
 }
 /**
  * This method like many before it, searches Amazon's Product API for information about the quotation described in the array.
  * I use a third field/column to give hints on what too look for in Amazon and other APIs.  I also cache the results and in some
  * cases we may have the information we are looking for already cached locally.  A lot of information can be returned, we usually just use the
  * first item ie $result->Items->Item[0]
  *
  * @param array
  * @return Simple XML object
  */
 private function getInfoFromAmazonFor($quotation)
 {
     if (count($quotation) >= 3) {
         $validFilename = preg_replace("/[^a-zA-Z0-9]/", "", $quotation[0]);
         if (is_array($quotation) && strlen($validFilename) > 0) {
             $myCache = new Caching("./MashupCache/Amazon/", $validFilename, 'xml');
             if ($myCache->needToRenewData()) {
                 try {
                     // Going to have a three (or eventually more) pronged approach that will require new methods in the Amazon API class.
                     if ($this->isFromFilm($quotation)) {
                         // We have a quotation from a movie, look in Film section of Amazon
                         $result = $this->amazonAPI->getDVDCoverByTitle($quotation[0]);
                     } else {
                         if ($this->isFromSong($quotation) || $this->isFromMusician($quotation)) {
                             // We have a quotation from a song or musician, looks in music section of Amazon
                             $result = $this->amazonAPI->getInfoForSongwriter($quotation[0]);
                         } else {
                             // We have a quotation, look for book by or about author
                             $result = $this->amazonAPI->getBookForKeyword($quotation[0]);
                         }
                     }
                 } catch (Exception $e) {
                     echo $e->getMessage();
                 }
                 $myCache->saveXMLToFile($result);
                 // Save new data before we return it to the caller of the method
             } else {
                 // It doesn't need to be renewed so use local copy
                 $result = $myCache->getLocalXML();
             }
         } else {
             throw new Exception('Incorrect data type passed to getInfoFromAmazonFor()');
         }
     } else {
         $result = null;
         // No info found in Amazon
     }
     return $result;
 }
Example #3
0
 private function getXMLFromAmazon($dvdTitle, $director)
 {
     if (strcmp($director, "various") != 0) {
         $strippedDVDTitle = $dvdTitle . "-" . $director;
         $strippedDVDTitle = preg_replace("/[^a-zA-Z0-9]/", "", $strippedDVDTitle);
     } else {
         $strippedDVDTitle = preg_replace("/[^a-zA-Z0-9]/", "", $dvdTitle);
     }
     if (strlen($strippedDVDTitle) > 0) {
         $myCache = new Caching("./MashupCache/Amazon/", $strippedDVDTitle, 'xml');
         if ($myCache->needToRenewData() && strcmp($director, "various") != 0) {
             try {
                 $result = $this->amazonAPI->getDVDCoverByTitleAndDirector($dvdTitle, $director);
             } catch (Exception $e) {
                 echo $e->getMessage();
             }
             $myCache->saveXMLToFile($result);
             // Save new data before we return it to the caller of the method
         } else {
             if ($myCache->needToRenewData()) {
                 try {
                     $result = $this->amazonAPI->getDVDCoverByTitle($dvdTitle);
                 } catch (Exception $e) {
                     echo $e->getMessage();
                 }
                 $myCache->saveXMLToFile($result);
                 // Save new data before we return it to the caller of the method
             } else {
                 // It doesn't need to be renewed so use local copy
                 $result = $myCache->getLocalXML();
             }
         }
     } else {
         throw new Exception('Incorrect data type passed to getXMLFromAmazon()');
     }
     return $result;
 }