Skip to content

Commit

Permalink
Created interface for OmdbApi.php
Browse files Browse the repository at this point in the history
  • Loading branch information
david_smith committed Dec 30, 2024
1 parent 72a4528 commit 035a369
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/OmdbApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* A wrapper for https://www.omdbapi.com/
*/
class OmdbApi
class OmdbApi implements OmdbApiInterface
{
public function __construct(
public readonly string $apikey,
Expand Down Expand Up @@ -165,7 +165,7 @@ public function search(
);
}

public function curl(array $options = []): array
private function curl(array $options = []): array
{
$ch = curl_init();
if ($ch === false) {
Expand Down
113 changes: 113 additions & 0 deletions src/OmdbApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace Zerotoprod\OmdbApi;

/**
* A wrapper for https://www.omdbapi.com/
*/
interface OmdbApiInterface
{
/**
* Returns the Poster Image.
*
* @link https://www.omdbapi.com/
*/
public function poster(string $imdbID): string;

/**
* Retrieve detailed information about a specific movie, TV series, or episode by either its IMDb ID or title.
*
* @param string|null $title *Optional. Production title to search for (e.g. 'Avatar'). *Either `$t` or `$i` must be specified.
* @param string|null $imdbID *Optional. A valid IMDb ID (e.g. 'tt1285016'). *Either `$t` or `$i` must be specified.
* @param string|null $type Optional. Type of result to return (movie, series, episode)
* @param int|null $year Optional. Year of release.
* @param bool $full_plot Optional. Return short or full plot.
* @param mixed|null $callback Optional. JSONP callback name.
* @param string|null $version Optional. API version (reserved for future use).
* @param array|null $CURLOPT cURL options.
*
* @return array{
* Title: string,
* Year: string,
* Rated: string,
* Released: string,
* Runtime: string,
* Genre: string,
* Director: string,
* Writer: string,
* Actors: string,
* Plot: string,
* Language: string,
* Country: string,
* Awards: string,
* Poster: string,
* Ratings?: array<array{ Source: string, Value: string}>,
* Metascore: int,
* imdbRating: float,
* imdbVotes: string,
* imdbID: string,
* Type: string,
* DVD: string,
* BoxOffice: string,
* Production: string,
* Website: string,
* Response: bool
* }|array{
* ErrorType: string,
* message: string,
* extra?: mixed
* }
*
*
* @link https://www.omdbapi.com/
*/
public function byIdOrTitle(
?string $title = null,
?string $imdbID = null,
?string $type = null,
?int $year = null,
?bool $full_plot = false,
mixed $callback = null,
?string $version = null,
?array $CURLOPT = [CURLOPT_TIMEOUT => 10]
): array;

/**
* Search for multiple titles using a keyword.
*
* @param string $title Required. Production title to search for (e.g. 'Avatar').
* @param string|null $type Optional. Type of result to return (movie, series, episode)
* @param int|null $year Optional. Year of release.
* @param int|null $page Optional. Search page number.
* @param mixed|null $callback Optional. JSONP callback name.
* @param string|null $version Optional. API version (reserved for future use).
* @param array|null $CURLOPT cURL options.
*
* @return array{
* Search: array<array{
* Title: string,
* Year: string,
* imdbID: string,
* Type: string,
* Poster: string
* }>,
* totalResults: int,
* Response: bool
* }|array{
* ErrorType: string,
* message: string,
* extra?: mixed
* }
*
* @link https://www.omdbapi.com/
*/
public function search(
string $title,
?string $type = null,
?int $year = null,
?int $page = 1,
mixed $callback = null,
?string $version = null,
?array $CURLOPT = [CURLOPT_TIMEOUT => 10]
): array;
}

0 comments on commit 035a369

Please sign in to comment.