Skip to content

Commit

Permalink
Update to work with API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Jleagle committed Oct 2, 2017
1 parent 8fd37f2 commit 303a125
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions src/Imdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 303a125

Please sign in to comment.