Skip to content

Commit 303a125

Browse files
committed
Update to work with API keys
1 parent 8fd37f2 commit 303a125

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
A package to retrieve movies and TV information from IMDB using the API at omdbapi.com
44

5+
Now that OMDB requires an API key you can set it using:
6+
7+
```php
8+
Imdb::setApiKey('xxx');
9+
```
10+
511
Retrieve full movie details, if you know the name or ID of the movie:
612

713
```php

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
],
1919
"require": {
2020
"php": ">=5.4",
21-
"jleagle/curl-wrapper": "~0.1"
21+
"jleagle/curl-wrapper": "~1.0.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "~5.0"
24+
"phpunit/phpunit": "~6.3.1"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/Imdb.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class Imdb
1212
const TYPE_MOVIE = 'movie';
1313
const TYPE_SERIES = 'series';
1414
const TYPE_EPISODE = 'episode';
15+
16+
protected static $_apiKey;
17+
18+
public static function setApiKey($apiKey)
19+
{
20+
self::$_apiKey = $apiKey;
21+
}
1522

1623
/**
1724
* @param string $movie
@@ -125,10 +132,16 @@ protected static function isValidId($string)
125132
*/
126133
protected static function _get($params)
127134
{
135+
if (!self::$_apiKey)
136+
{
137+
throw new ImdbException('OMDB now requires an API key');
138+
}
139+
128140
$params = array_filter($params);
129141

130142
$params['r'] = 'json';
131143
$params['v'] = '1';
144+
$params['apikey'] = self::$_apiKey;
132145

133146
try
134147
{

0 commit comments

Comments
 (0)