diff --git a/src/Helpers.php b/src/Helpers.php new file mode 100644 index 0000000..c78361d --- /dev/null +++ b/src/Helpers.php @@ -0,0 +1,16 @@ +id = $id; + } + + /** + * Get the Series + * + * @return json + */ + public function get() + { + try { + return json_decode($this->client()->login()->client->get('series/' . $this->id)->getBody()); + } catch(ClientException $e) { + throw new TVDBException($e); + } + } + + /** + * Series Actors + * + * @return json + */ + public function actors() + { + try { + return json_decode($this->client()->login()->client->get('series/' . $this->id . '/actors')->getBody()); + } catch(ClientException $e) { + throw new TVDBException($e); + } + } + + /** + * Series Episodes + * + * @return json + */ + public function episodes() + { + try { + return json_decode($this->client()->login()->client->get('series/' . $this->id . '/episodes')->getBody()); + } catch(ClientException $e) { + throw new TVDBException($e); + } + } + + /** + * Series Images + * + * @return json + */ + public function images() + { + try { + return json_decode($this->client()->login()->client->get('series/' . $this->id . '/images')->getBody()); + } catch(ClientException $e) { + throw new TVDBException($e); + } + } +} \ No newline at end of file diff --git a/src/TVDB.php b/src/TVDB.php new file mode 100644 index 0000000..5b1aae2 --- /dev/null +++ b/src/TVDB.php @@ -0,0 +1,36 @@ +client()->login()->client->get('search/series?name=' . $name)->getBody()); + } catch(ClientException $e) { + throw new TVDBException($e); + } + } +} \ No newline at end of file diff --git a/src/TBDB.php b/src/TVDBClient.php similarity index 69% rename from src/TBDB.php rename to src/TVDBClient.php index 930bcc7..98a1a7f 100644 --- a/src/TBDB.php +++ b/src/TVDBClient.php @@ -8,20 +8,15 @@ use GuzzleHttp\Exception\ClientException; use Psr\Http\Message\RequestInterface; -class TVDB +class TVDBClient { - /** - * Token for API Requests - * - * @var string - */ - protected $token; - /** * Constructor */ public function __construct() { + $this->token = null; + $this->username = config('tvdb.username'); $this->userkey = config('tvdb.userkey'); $this->apikey = config('tvdb.apikey'); @@ -40,46 +35,12 @@ public function __construct() ]); } - /** - * Search TBDB for Series - * - * @param string $name - * @return json - */ - public function search($name) - { - $this->login(); - - try { - return json_decode($this->client->get('search/series?name=' . $name)->getBody()); - } catch(ClientException $e) { - throw new TVDBException($e); - } - } - - /** - * Lookup a Series - * - * @param integer $id - * @return json - */ - public function lookup($id) - { - $this->login(); - - try { - return json_decode($this->client->get('series/' . $id)->getBody()); - } catch(ClientException $e) { - throw new TVDBException($e); - } - } - /** * Obtain a Token * * @return response */ - private function login() + public function login() { try { $response = $this->client->post('login', ['json' => [ @@ -89,6 +50,8 @@ private function login() ]])->getBody(); $this->token = json_decode($response->getContents())->token; + + return $this; } catch(ClientException $e) { throw new TVDBException($e); } diff --git a/src/TBDBServiceProvider.php b/src/TVDBServiceProvider.php similarity index 100% rename from src/TBDBServiceProvider.php rename to src/TVDBServiceProvider.php