From 303a125513a1a8e1c9bf9d88154fdc8fd3f9cb93 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Mon, 2 Oct 2017 23:05:13 +0100 Subject: [PATCH] Update to work with API keys --- README.md | 6 ++++++ composer.json | 4 ++-- src/Imdb.php | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f3007b..067bdb7 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ A package to retrieve movies and TV information from IMDB using the API at omdbapi.com +Now that OMDB requires an API key you can set it using: + +```php +Imdb::setApiKey('xxx'); +``` + Retrieve full movie details, if you know the name or ID of the movie: ```php diff --git a/composer.json b/composer.json index fc1ffc6..956a0b8 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,10 @@ ], "require": { "php": ">=5.4", - "jleagle/curl-wrapper": "~0.1" + "jleagle/curl-wrapper": "~1.0.0" }, "require-dev": { - "phpunit/phpunit": "~5.0" + "phpunit/phpunit": "~6.3.1" }, "autoload": { "psr-4": { diff --git a/src/Imdb.php b/src/Imdb.php index d640018..fa687ce 100644 --- a/src/Imdb.php +++ b/src/Imdb.php @@ -12,6 +12,13 @@ class Imdb const TYPE_MOVIE = 'movie'; const TYPE_SERIES = 'series'; const TYPE_EPISODE = 'episode'; + + protected static $_apiKey; + + public static function setApiKey($apiKey) + { + self::$_apiKey = $apiKey; + } /** * @param string $movie @@ -125,10 +132,16 @@ protected static function isValidId($string) */ protected static function _get($params) { + if (!self::$_apiKey) + { + throw new ImdbException('OMDB now requires an API key'); + } + $params = array_filter($params); $params['r'] = 'json'; $params['v'] = '1'; + $params['apikey'] = self::$_apiKey; try {