From 7fd7485eb725e0a383e5c00420640d27f2449bcc Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 15 Jan 2014 22:59:44 +0100 Subject: [PATCH] Updating docs --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- TODO | 2 -- 2 files changed, 71 insertions(+), 4 deletions(-) delete mode 100644 TODO diff --git a/README.md b/README.md index 5f37e089..21267fae 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,78 @@ require_once dirname(__DIR__).'/vendor/autoload.php'; General API Usage ----------------- -Please take a look at the (currently few) examples in the examples directory. +If your looking for a simple array entry point the API namespace is the place to be. + +```php +$token = new \Tmdb\ApiToken('your_tmdb_api_key_here'); +$client = new \Tmdb\Client($token); + +$images = $client->getMoviesApi()->getMovie(550); +``` + +If you want to provide any other query arguments. + +```php +$token = new \Tmdb\ApiToken('your_tmdb_api_key_here'); +$client = new \Tmdb\Client($token); + +$images = $client->getMoviesApi()->getMovie(550, array('language' => 'en')); +``` Model Usage ----------- -Basically the Repositories are used as the entry-point, take a look in the examples or better yet browse the code. \ No newline at end of file +However the library can be used in an object oriented manner. + +First we always have to construct the client: + +```php +$token = new \Tmdb\ApiToken('your_tmdb_api_key_here'); +$client = new \Tmdb\Client($token); +``` + +Then you pass this client onto one of the many repositories and do some work on it. + +```php +$repository = new \Tmdb\Repository\MovieRepository($client); +$movie = $repository->load(87421); + +echo $movie->getTitle(); +``` + +__The repositories also contain the other API methods that are available through the API namespace.__ + +An `ImageHelper` class is provided to take care of the images, which does require the configuration to be loaded: + +```php +$configRepository = new \Tmdb\Repository\ConfigurationRepository($client); +$config = $configRepository->load(); + +$imageHelper = new \Tmdb\Helper\ImageHelper($config); + +echo $imageHelper->getHtml($image, 'w154', 154, 80); +``` + +We also provide some easy methods to filter any collection, you should note however you can always implement your own filter easily by using Closures: + +```php +foreach($movie->getImages()->filter( + function($key, $value){ + if ($value instanceof \Tmdb\Model\Image\PosterImage) { return true; } + } + ) as $image) { + + // do something with all poster images +} +``` + +These basic filters however are already covered in the `Images` collection object: + +```php +$backdrop = $movie + ->getImages() + ->filterBackdrops() +; +``` + +__And there are more Collections which provide filters, but you will find those out along the way.__ \ No newline at end of file diff --git a/TODO b/TODO deleted file mode 100644 index 23bf34e1..00000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -- Add event subscribers to supply language and adult filters -- Figure out a way to slim down the seemingly dependency on Guzzle \ No newline at end of file