This API client leverages the GuzzleHttp client and serves as a wrapper for the MediaFoundry API.
It provides a consistent interface to the API data, hiding some of its structure, and making interacting with the data simpler.
Require the client in your project's composer.json
file:
{
"repositories": [
{
"type": "vcs",
"url": "git@hwkpcode.hostworks.com.au:MediaFoundry/MediaFoundry-API-Client.git"
}
],
"require": {
"mediafoundry/api-client": "~1.0"
}
}
Then execute composer install
.
<?php
require dirname(__FILE__) . '/vendor/autoload.php');
use MediaFoundry\Api\Client;
use GuzzleHttp\Client as GuzzleClient;
$client = new Client('http://admin-latest.pp.mediafoundry.com.au/api/v1.0', new GuzzleClient);
This package also includes a Laravel Service Provider, making using it within any Laravel project simple.
<?php
// config/app.php
providers => [
// ...
\MediaFoundry\Api\MediaFoundryApiClientServiceProvider::class,
];
Ensure that the environment variable MEDIAFOUNDRY_API_BASE_URI
is configured and points to the versioned endpoint base url. This value should not have a trailing slash.
# .env
MEDIAFOUNDRY_API_BASE_URI=http://admin-latest.pp.mediafoundry.com.au/api/v1.0
The API client can now be resolved out of the Service Container.
<?php
namespace App\Http\Controllers;
use MediaFoundry\Api\Contracts\ApiClient;
class PageController extends Controller
{
// Via method injection
public function index(ApiClient $client)
{
$videos = $client->videos();
return view('home', compact('videos'));
}
public function showVideo($video_id, ApiClient $client)
{
// Get the video identified by $video_id
$video = $client->videos($video_id);
return view('video.show', compact('video'));
}
}
Method | Description |
---|---|
categories($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific category identified by $entity_id .If $entity_id is null, return all categories configured in the API.If $filter is a non-empty array, filter the returned categories (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned categories (ignored if $entity_id is supplied).
|
episodes($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific episode identified by $entity_id .If $entity_id is null, return all episodes configured in the API.If $filter is a non-empty array, filter the returned episodes (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned episodes (ignored if $entity_id is supplied).
|
events($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific event identified by $entity_id .If $entity_id is null, return all events configured in the API.If $filter is a non-empty array, filter the returned events (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned events (ignored if $entity_id is supplied).
|
genres($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific genre identified by $entity_id .If $entity_id is null, return all genres configured in the API.If $filter is a non-empty array, filter the returned genres (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned genres (ignored if $entity_id is supplied).
|
seasons($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific season identified by $entity_id .If $entity_id is null, return all seasons configured in the API.If $filter is a non-empty array, filter the returned seasons (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned seasons (ignored if $entity_id is supplied).
|
series($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific series identified by $entity_id .If $entity_id is null, return all series configured in the API.If $filter is a non-empty array, filter the returned series (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned series (ignored if $entity_id is supplied).
|
videos($entity_id = null, $filter = [], $sort = []) |
If $entity_id is supplied, return a specific video identified by $entity_id .If $entity_id is null, return all videos configured in the API.If $filter is a non-empty array, filter the returned videos (ignored if $entity_id supplied).If $sort is a non-empty array, sort the returned videos (ignored if $entity_id is supplied).
|
Each of the available methods will return either an array of, or a single instance of, their corresponding entity. Each of the entities extend the base MediaFoundry\Api\Entities\Entity
class, providing access to generic methods.
Generic Entity Method | Description |
---|---|
id |
Get the entity's identifier |
self |
Get the URL to the entity |
created |
Get the entity created datetime |
changed |
Get the entity changed datetime |
The Entity
class also provides a __get
implementation, allowing you to access properties on the underlying entity directly.
Each child class may also present its own public methods, to handle properties specific to itself.
Note: The self
method provided on the base Entity
class works for the majority of child entities, however, the underlying API is not consistent in how to access this property.
Where stated in parentheses, the method returns an entity. For example, series (Series)
indicates that the series
method will return an instance of MediaFoundry\Api\Entities\Series
.
API Method | Entity | Entity-Specific Methods |
---|---|---|
categories() |
MediaFoundry\Api\Entities\Category |
– |
episodes() |
MediaFoundry\Api\Entities\Episode |
thumbnail , manifest , series (Series) , season (Season) |
events() |
MediaFoundry\Api\Entities\Event |
scheduled , schedule (EventSchedule|null) , image , manifest , ad |
genres() |
MediaFoundry\Api\Entities\Genre |
– |
seasons() |
MediaFoundry\Api\Entities\Season |
icon , series (Series) , episodes
|
series() |
MediaFoundry\Api\Entities\Series |
icon , genres , season (Season) |
videos() |
MediaFoundry\Api\Entities\Video |
image , manifest , embed , release_date , ogTitle , ogType , ogAuthor , ogPublisher , ogImage , ogDescription
|
The Video
entity implements the OpenGraphable
interface, and provides methods to access information with which to generate Open Graph meta tags.
The EventSchedule
object exposes two methods, start
and end
. Each returns an instance of DateTime
.
The API interactions, and handling of response data is covered by PHPUnit tests. This will perform queries against the API identified by the API_BASE_URI
environment variable.
This is http://admin-latest.pp.mediafoundry.com.au/api/v1.0
by default, but can be changed on the command line, in order to run tests against a customer-specific deployment of the API.
$ export API_BASE_URI="http://admin-tdu.pp.mediafoundry.com.au/api/v1.0"
$ ./vendor/bin/phpunit
// this will execute tests against the TDU deployment of the API, rather than the default pre-production instance.
It is worth nothing that all of the unit tests, with exception to MediaFoundryApiTest.php
are executed against response fixtures. This means that for testing that a customer-specific API deployment is functioning correctly, you may wish to run a single set of tests, rather than the entire test suite. In this instance:
$ export API_BASE_URI="http://admin-tdu.pp.mediafoundry.com.au/api/v1.0"
$ ./vendor/bin/phpunit --group core