Documentation

In this page, you will learn how to use feed-io and useful tips to extend it.

Table of contents

  1. Getting a TMDB instance
  2. Movie
  3. TV Show
  4. Collection
  5. People
  6. Company
  7. Authentication
  8. Media Helper

Getting a TMDB instance

TMDB is the main class of the library. It has two dependencies :

Using the Factory

It is the easiest way to load TMDB

<?php
require 'vendor/autoload.php';

use VfacTmdb\Factory;

$tmdb = Factory::create()->getTmdb('your_api_key');

In a Slim application

If your application is built with Slim, you can add TMDB in your dependencies and inject Slim's Monolog instance into it. Just add this in dependencies.php

$container['tmdb'] = function ($c) {
    $api_key = $c->get('settings')['tmdb']['api_key'];
    $tmdb = new \vfalies\tmdb\Tmdb($api_key, $c->logger);
}

In this example, API key is declared in settings.php

return [
    'settings' = [
        'tmdb' = [
            'api_key' = 'your_api_key';
        ]
    ]
];

Do it yourself

Convenient if you need too inject your own dependencies. In the example below, we inject Monolog configured to write logs on standards output.

<?php
require 'vendor/autoload.php';

use VfacTmdb\Tmdb;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('default', [new StreamHandler('php://stdout')])

$tmdb = Tmdb('your_api_key', $logger);

Movie

Search a movie

$search    = new Search($tmdb);
$responses = $search->movie('star wars');

The search returns Generator object of Result\Movie object.

See demo

Get a movie

$item  = new Item($tmdb);
$movie = $item->getMovie($movie_id);

echo $movie->getTitle();

The getter returns a Movie object.

See demo

TV Show

Search a TV Show

$search    = new Search($tmdb);
$responses = $search->tvshow('game of thrones');

The search returns Generator object of Result\TVShow object.

See demo

Get a TV Show

$item   = new Item($tmdb);
$tvshow = $item->getTVShow($tvshow_id);

echo $tvshow->getTitle();

The getter returns a TVShow object.

See demo

Get a TV Season

$item     = new Item($tmdb);
$tvseason = $item->getTVSeason($tvshow_id, $season_number);

echo $tvseason->getName();

The getter returns a TVSeason object.

Get a TV Episode

$item      = new Item($tmdb);
$tvepisode = $item->getTVEpisode($tvshow_id, $season_number, $episode_number);

echo $tvepisode->getName();

The getter returns a TVEpisode object.

Collection

Search a Collection

$search    = new Search($tmdb);
$responses = $search->collection('alien');

The search returns Generator object of Result\Collection object.

See demo

Get a Collection

$item       = new Item($tmdb);
$collection = $item->getCollection($collection_id);

echo $collection->getName();

The getter returns a Collection object.

See demo

People

Search a People

$search    = new Search($tmdb);
$responses = $search->people('alec baldwin');

The search returns Generator object of Result\People object.

See demo

Get a People

$item   = new Item($tmdb);
$people = $item->getPeople($people_id);

echo $people->getName();

The getter returns a People object.

See demo

Company

Search a company

$search    = new Search($tmdb);
$responses = $search->company('lucasfilms');

The search returns Generator object of Result\Company object.

See demo

Get a Company

$item   = new Item($tmdb);
$company = $item->getCompany($company_id);

echo $company->getName();

The getter returns a Company object.

See demo

Authentication

The connection to your account is in 3 steps:

  • Getting a request token
  • Connection to TMDb website
  • Create a session

Getting a request token

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($tmdb);
echo $Auth->getRequestToken();

Connect to TMDb website

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($tmdb);
$Auth->connect($_POST['request_token']);

This call redirect the page to TMDb website login page for identification and authorisations. By default, after the connection, the user stay on TMDb website. To redirect to your website after the connection, use the following code:

$tmdb = Factory::create()->getTmdb('your_api_key');

$Auth = new Auth($tmdb);
$Auth->connect($_POST['request_token'], 'http://your_url');

Create a session

To use all account methods, we must use a valid session.

$tmdb = Factory::create()->getTmdb('62dfe9839b8937e595e325a4144702ad');

$Auth = new Auth($tmdb);
echo $Auth->createSession($_POST['request_token']);

Media Helper

All media informations delivered by the library are relative pathfile.

To get a valid media URL, use the Media class to generate the URL and check the media size

$media = new Media($tmdb);
$url = $media->getPosterUrl('/AbJBXaVPrdXROwb8KmgWUPU2XJX.jpg');

The following type of media are supported :

  • Backdrop
  • Poster
  • Logo
  • Profile
  • Still