|
|
|
@@ -1,234 +1,355 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use newznab\utility\Utility;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches and returns JSON documents from the Rotten Tomato API using a supplied API key.
|
|
|
|
|
* Copyright (c) 2011 Richard Hoppes.
|
|
|
|
|
*
|
|
|
|
|
* Class RottenTomato
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
|
* so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
* */
|
|
|
|
|
/**
|
|
|
|
|
* Rotten Tomatoes API
|
|
|
|
|
*/
|
|
|
|
|
class RottenTomato
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Main link for all the methods.
|
|
|
|
|
* API Urls
|
|
|
|
|
*/
|
|
|
|
|
const API_URL = 'http://api.rottentomatoes.com/api/public/v1.0/';
|
|
|
|
|
|
|
|
|
|
const ROTTEN_TOMATOES_API_LISTS_DIRECTORY = 'http://api.rottentomatoes.com/api/public/v1.0/lists.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_MOVIE_LISTS_DIRECTORY = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_DVD_LISTS_DIRECTORY = 'http://api.rottentomatoes.com/api/public/v1.0/lists/dvds.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_DVD_TOP_RENTALS = 'http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/top_rentals.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_MOVIE_SEARCH = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_OPENING_MOVIES = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/opening.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_UPCOMING_MOVIES = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_NEW_RELEASE_DVDS = 'http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/new_releases.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_IN_THEATERS = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_BOX_OFFICE = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_MOVIE_INFO = 'http://api.rottentomatoes.com/api/public/v1.0/movies/%s.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_MOVIE_CAST = 'http://api.rottentomatoes.com/api/public/v1.0/movies/%s/cast.json';
|
|
|
|
|
const ROTTEN_TOMATOES_API_MOVIE_REVIEWS = 'http://api.rottentomatoes.com/api/public/v1.0/movies/%s/reviews.json';
|
|
|
|
|
/**
|
|
|
|
|
* RT Api key.
|
|
|
|
|
* Review types
|
|
|
|
|
*/
|
|
|
|
|
const REVIEW_TYPE_TOP_CRITIC = 'top_critic';
|
|
|
|
|
const REVIEW_TYPE_ALL = 'all';
|
|
|
|
|
const REVIEW_TYPE_DVD = 'dvd';
|
|
|
|
|
/**
|
|
|
|
|
* API key
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $_apikey;
|
|
|
|
|
|
|
|
|
|
protected $apiKey;
|
|
|
|
|
/**
|
|
|
|
|
* @param string $apiKey RT Api Key.
|
|
|
|
|
* Timeout seconds
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($apiKey)
|
|
|
|
|
{
|
|
|
|
|
$this->_apikey = $apiKey;
|
|
|
|
|
protected $timeoutSeconds;
|
|
|
|
|
/**
|
|
|
|
|
* Country
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $country;
|
|
|
|
|
/**
|
|
|
|
|
* Initialize
|
|
|
|
|
* @param string $apiKey
|
|
|
|
|
* @param int $timeoutSeconds
|
|
|
|
|
* @param string $country
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($apiKey, $timeoutSeconds = 15, $country = 'us') {
|
|
|
|
|
$this->apiKey = $apiKey;
|
|
|
|
|
$this->timeoutSeconds = $timeoutSeconds;
|
|
|
|
|
$this->country = $country;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Movie search
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param string $query search term
|
|
|
|
|
* @param int $pageLimit results per page
|
|
|
|
|
* @param int $page current page
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function movieSearch($query, $pageLimit = 20, $page = 0) {
|
|
|
|
|
$params = array();
|
|
|
|
|
$params['q'] = $query;
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
if ($page)
|
|
|
|
|
$params['page'] = $page;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_MOVIE_SEARCH, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movie reviews
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $id rotten tomatoes id
|
|
|
|
|
* @param string $reviewType review type
|
|
|
|
|
* @param int $pageLimit results per page
|
|
|
|
|
* @param int $page current page
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getMovieReviews($id, $reviewType = self::REVIEW_TYPE_ALL, $pageLimit = 20, $page = 0) {
|
|
|
|
|
$url = sprintf(self::ROTTEN_TOMATOES_API_MOVIE_REVIEWS, $id);
|
|
|
|
|
$params = array();
|
|
|
|
|
$params['review_type'] = $reviewType;
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
if ($page)
|
|
|
|
|
$params['page'] = $page;
|
|
|
|
|
$result = $this->getResource($url, $params);
|
|
|
|
|
if(!isset($result['reviews']) && !empty($result['reviews']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movie cast
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $id rotten tomatoes id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public function getMovieCast($id) {
|
|
|
|
|
$url = sprintf(self::ROTTEN_TOMATOES_API_MOVIE_CAST, $id);
|
|
|
|
|
$result = $this->getResource($url);
|
|
|
|
|
if(!isset($result['cast']) || empty($result['cast']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result['cast'];
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movie info
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $id rotten tomatoes id
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getMovieInfo($id) {
|
|
|
|
|
$url = sprintf(self::ROTTEN_TOMATOES_API_MOVIE_INFO, $id);
|
|
|
|
|
$result = $this->getResource($url);
|
|
|
|
|
if(!isset($result['id']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get new DVD releases
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit results per page
|
|
|
|
|
* @param int $page current page
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getNewDvdReleases($pageLimit = 20, $page = 0) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
if ($page)
|
|
|
|
|
$params['page'] = $page;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_NEW_RELEASE_DVDS, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movies that are coming soon
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit results per page
|
|
|
|
|
* @param int $page current page
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getUpcomingMovies($pageLimit = 20, $page = 0) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
if ($page)
|
|
|
|
|
$params['page'] = $page;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_UPCOMING_MOVIES, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movies currently in theaters
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit results per page
|
|
|
|
|
* @param int $page current page
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getMoviesInTheaters($pageLimit = 5, $page = 0) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
if ($page)
|
|
|
|
|
$params['page'] = $page;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_IN_THEATERS, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get movies opening
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit number of results
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getOpeningMovies($pageLimit = 20) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_OPENING_MOVIES, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get top box office results
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit number of results
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getMoviesBoxOffice($pageLimit = 20) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_BOX_OFFICE, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get top DVD rentals
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @param int $pageLimit number of results
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getDvdTopRentals($pageLimit = 20) {
|
|
|
|
|
$params = array();
|
|
|
|
|
if ($pageLimit)
|
|
|
|
|
$params['page_limit'] .= $pageLimit;
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_DVD_TOP_RENTALS, $params);
|
|
|
|
|
if(!isset($result['movies']) && !empty($result['movies']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get Movie Urls
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getMovieListsDirectory() {
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_DVD_LISTS_DIRECTORY);
|
|
|
|
|
if(!isset($result['links']) && !empty($result['links']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get list Urls
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getListsDirectory() {
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_LISTS_DIRECTORY);
|
|
|
|
|
if(!isset($result['links']) && !empty($result['links']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get DVD API Urls
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @return array results
|
|
|
|
|
*/
|
|
|
|
|
public function getDvdListsDirectory() {
|
|
|
|
|
$result = $this->getResource(self::ROTTEN_TOMATOES_API_DVD_LISTS_DIRECTORY);
|
|
|
|
|
if(!isset($result['links']) && !empty($result['links']))
|
|
|
|
|
throw new Exception("No results");
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get resource
|
|
|
|
|
* @param string $url
|
|
|
|
|
* @param array $params parameters (key/value pairs) for query string
|
|
|
|
|
* @return array decoded json response
|
|
|
|
|
*/
|
|
|
|
|
protected function getResource($url, $params = array()) {
|
|
|
|
|
$params['apikey'] = $this->apiKey;
|
|
|
|
|
$params['country'] = $this->country;
|
|
|
|
|
$queryString = http_build_query($params);
|
|
|
|
|
$rawResponse = trim($this->httpRequest("{$url}?{$queryString}"));
|
|
|
|
|
if (!$rawResponse)
|
|
|
|
|
throw new Exception("No response");
|
|
|
|
|
$decodedResponse = json_decode($rawResponse, true);
|
|
|
|
|
if (!$decodedResponse)
|
|
|
|
|
throw new Exception('Error parsing JSON response');
|
|
|
|
|
if (isset($decodedResponse['error']))
|
|
|
|
|
throw new Exception('API Error: ' + $decodedResponse['error']);
|
|
|
|
|
return $decodedResponse;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Perform HTTP Request
|
|
|
|
|
* @param string $url url for request
|
|
|
|
|
* @return string|boolean result
|
|
|
|
|
*/
|
|
|
|
|
protected function httpRequest($url) {
|
|
|
|
|
//Test for allow_url_fopen to be enabled.
|
|
|
|
|
//Many hosts disable this for security
|
|
|
|
|
if(function_exists('curl_init')){
|
|
|
|
|
return $this->httpRequestCurl($url);
|
|
|
|
|
}elseif(ini_get('allow_url_fopen')){
|
|
|
|
|
return $this->httpRequestFopen($url);
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Displays Top Box Office Earning Movies, Sorted by Most Recent Weekend Gross Ticket Sales.
|
|
|
|
|
*
|
|
|
|
|
* @param int $limit Limits the number of box office movies returned.
|
|
|
|
|
* @param string $country Provides localized data for the selected country (ISO 3166-1 alpha-2) if available.
|
|
|
|
|
* Otherwise, returns US data.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* Perform HTTP Request with fopen
|
|
|
|
|
* @param string $url url for request
|
|
|
|
|
* @return string|boolean result
|
|
|
|
|
*/
|
|
|
|
|
public function getBoxOffice($limit = 10, $country = 'us')
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'lists/movies/box_office.json',
|
|
|
|
|
array(
|
|
|
|
|
'limit' => $limit,
|
|
|
|
|
'country' => $country
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
protected function httpRequestFopen($url){
|
|
|
|
|
$http = array();
|
|
|
|
|
$http['method'] = 'GET';
|
|
|
|
|
$http['timeout'] = $this->timeoutSeconds;
|
|
|
|
|
$response = @fopen($url, 'r', false, stream_context_create(array('http' => $http)));
|
|
|
|
|
$result = false;
|
|
|
|
|
if ($response)
|
|
|
|
|
$result = $response;
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves movies currently in theaters.
|
|
|
|
|
*
|
|
|
|
|
* @param int $limit The amount of movies in theaters to show per page.
|
|
|
|
|
* @param int $page The selected page of in theaters movies.
|
|
|
|
|
* @param string $country Provides localized data for the selected country (ISO 3166-1 alpha-2) if available.
|
|
|
|
|
* Otherwise, returns US data.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* Perform HTTP Request with curl
|
|
|
|
|
* @param string $url url for request
|
|
|
|
|
* @return string|boolean result
|
|
|
|
|
*/
|
|
|
|
|
public function getInTheaters($limit = 16, $page = 1, $country = 'us')
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'lists/movies/in_theaters.json',
|
|
|
|
|
array(
|
|
|
|
|
'page_limit' => $limit,
|
|
|
|
|
'page' => $page,
|
|
|
|
|
'country' => $country
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
protected function httpRequestCurl($url){
|
|
|
|
|
// create curl resource
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves current opening movies.
|
|
|
|
|
*
|
|
|
|
|
* @param int $limit Limits the number of opening movies returned.
|
|
|
|
|
* @param string $country Provides localized data for the selected country (ISO 3166-1 alpha-2) if available.
|
|
|
|
|
* Otherwise, returns US data.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getOpening($limit = 16, $country = 'us')
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'lists/movies/opening.json',
|
|
|
|
|
array(
|
|
|
|
|
'limit' => $limit,
|
|
|
|
|
'country' => $country
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// set url
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves upcoming movies. Results are paginated if they go past the specified page limit.
|
|
|
|
|
*
|
|
|
|
|
* @param int $limit The amount of upcoming movies to show per page.
|
|
|
|
|
* @param int $page The selected page of upcoming movies.
|
|
|
|
|
* @param string $country Provides localized data for the selected country (ISO 3166-1 alpha-2) if available.
|
|
|
|
|
* Otherwise, returns US data.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getUpcoming($limit = 16, $page = 1, $country = 'us')
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'lists/movies/upcoming.json',
|
|
|
|
|
array(
|
|
|
|
|
'page_limit' => $limit,
|
|
|
|
|
'page' => $page,
|
|
|
|
|
'country' => $country
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
//return the transfer as a string
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
//set timeout
|
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeoutSeconds);
|
|
|
|
|
// $output contains the output string
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shows the DVD lists RT has available.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDVDReleases()
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall('lists/dvds/new_releases.json');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The movies search endpoint for plain text queries. Allows you to search for movies!
|
|
|
|
|
*
|
|
|
|
|
* @param string $title The plain text search query to search for a movie. Remember to URI encode this!
|
|
|
|
|
* @param int $limit The amount of movie search results to show per page.
|
|
|
|
|
* @param int $page The selected page of movie search results.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function searchMovie($title, $limit = 50, $page = 1)
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'movies.json',
|
|
|
|
|
array(
|
|
|
|
|
'q' => $title,
|
|
|
|
|
'page_limit' => $limit,
|
|
|
|
|
'page' => $page
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detailed information on a specific movie specified by Id.
|
|
|
|
|
* You can use the movies search endpoint or peruse the lists of movies/dvds to get the urls to movies.
|
|
|
|
|
*
|
|
|
|
|
* @param int $ID The RT id.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getMovie($ID)
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall('movies/' . $ID . '.json');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the reviews for a movie.
|
|
|
|
|
* Results are paginated if they go past the specified page limit.
|
|
|
|
|
*
|
|
|
|
|
* @param int $ID The RT id.
|
|
|
|
|
* @param string $type Three different review types are possible:
|
|
|
|
|
* "all", "top_critic" and "dvd".
|
|
|
|
|
* "top_critic" shows all the Rotten Tomatoes designated top critics.
|
|
|
|
|
* "dvd" pulls the reviews given on the DVD of the movie.
|
|
|
|
|
* "all" as the name implies retrieves all reviews.
|
|
|
|
|
* @param int $limit The number of reviews to show per page.
|
|
|
|
|
* @param int $page The selected page of reviews.
|
|
|
|
|
* @param string $country Provides localized data for the selected country (ISO 3166-1 alpha-2) if available.
|
|
|
|
|
* Otherwise, returns US data.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getReviews($ID, $type = 'top_critic', $limit = 20, $page = 1, $country = 'us')
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall(
|
|
|
|
|
'movies/' . $ID . '/reviews.json',
|
|
|
|
|
array(
|
|
|
|
|
'review_type' => $type,
|
|
|
|
|
'page_limit' => $limit,
|
|
|
|
|
'page' => $page,
|
|
|
|
|
'country' => $country
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pulls the complete movie cast for a movie.
|
|
|
|
|
*
|
|
|
|
|
* @param int $ID The RT id.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getCast($ID)
|
|
|
|
|
{
|
|
|
|
|
return $this->_makeCall('movies/' . $ID . '/cast.json');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a request to RT.
|
|
|
|
|
*
|
|
|
|
|
* @param string $function The type of request.
|
|
|
|
|
* @param array $params Extra HTTP parameters.
|
|
|
|
|
*
|
|
|
|
|
* @return string JSON data from RT.
|
|
|
|
|
*/
|
|
|
|
|
private function _makeCall($function, $params = [])
|
|
|
|
|
{
|
|
|
|
|
return trim(
|
|
|
|
|
Utility::getUrl([
|
|
|
|
|
'url' => \RottenTomato::API_URL .
|
|
|
|
|
$function .
|
|
|
|
|
'?limit=' .
|
|
|
|
|
mt_rand(15, 20) .
|
|
|
|
|
'&apikey=' .
|
|
|
|
|
$this->_apikey .
|
|
|
|
|
(!empty($params) ? ('&' . http_build_query($params)) : '')
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the RT api key.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getApiKey()
|
|
|
|
|
{
|
|
|
|
|
return $this->_apikey;
|
|
|
|
|
// close curl resource to free up system resources
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
$result = false;
|
|
|
|
|
if ($response)
|
|
|
|
|
$result = $response;
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|