Class: MD_Core
A class containing core functions used to connect and fetch data from OMDb API.
Properties
get_api_key()
- no parameters
- Returns: If set, the user's personal API key. If no key has been set, the constant
MD_DEFAULT_API_KEY
will be used which contains the key38c8f7d6
- Returns: If set, the user's personal API key. If no key has been set, the constant
- no parameters
get_api_url($title_or_imdb_id, $api_key, $encode_url)
$title_or_imdb_id
(string): Movie title or corresponding ID on IMDb.com$api_key
(string): The required API key. Default:$this->get_api_key()
$encode_url
(bool): Default:false
- Returns (string): API URL with implemented API key and movie title/ID to fetch movie details
get_api_data($title_or_imdb_id, $options)
$title_or_imdb_id
(string): Movie title or corresponding ID on IMDb.com$options
(array): Default:array()
- Returns (string): Raw JSON containing all movie details
get_encoded_api_data($title_or_imdb_id, $options, $output)
$title_or_imdb_id
(string): Movie title or corresponding ID on IMDb.com$options
(array): Additional optionsencode_url
(bool): Encode the URL. Default:false
$output
(string): Output type. Default:"object"
- Returns (array | object): Movie details as array or object
- test_api_key($api_key)
$api_key
(string): API key to test connection to OMDb API. Default:$this->get_api_key()
- Returns (bool):
true
if connection has been established,false
if not.
Example
Retrieves movie details, encodes it into an array and displays the keys and values.
<?php
$class_core = new MD_Core();
$movie_title = "Taken";
$json_api_data = $class_core->get_api_data($movie_title);
$array_api_data = json_encode($json_api_data, true);
foreach($array_api_data as $name => $value) {
?>
<p>
The value of <?php echo $name; ?> is <?php echo $value; ?>.
</p>
<?php
}