/** * Test whether this movie is valid. * Connects to OMDb API to see whether a movie with a title the same as this page exists. * * @return boolean */ public function isValid() { $api = new RestfulService('http://www.omdbapi.com/'); $api->setQueryString(array('r' => 'xml', 'type' => 'movie', 't' => $this->Title, 'plot' => 'full', 'tomatoes' => 'true', 'v' => 1)); $results = $api->request(); $body = $results->getBody(); if (!strstr($body, "<")) { // An error with the xml return false; } if ($api->getAttribute($body, '', 'root', 'response') === 'False') { // server said no! return false; } if ($api->getAttributes($body, 'movie')->count() == 0) { // server SHOULD have said no return false; } // We should be good, return the body to save a query ;) return $body; }