api-video/php-api-client

PHP client for api.video web services.


README

badge   badge   badge

api.video PHP client

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Table of contents

Project description

api.video's PHP API client streamlines the coding process. Chunking files is handled for you, as is pagination and refreshing your tokens.

Getting started

Installation

composer require api-video/php-api-client

Initialization

Due to PHP PSR support, you must initialize the client with 3 to 5 arguments:

  1. Base URI, which can be either https://sandbox.api.video or https://ws.api.video
  2. Your API key, available on your account
  3. HTTP client
  4. (Request factory)
  5. (Stream factory)

Note : If the HTTP client also implements RequestFactoryInterface and StreamFactoryInterface, then it is not necessary to pass this object in 4th and 5th argument.

Symfony HTTP client example

The Symfony HTTP client has the triple advantage of playing the role of HTTP client, but also of request factory and stream factory. It is therefore sufficient to pass it as an argument 3 times.

If the HTTP client isn't yet in your project, you can add it with:

composer require symfony/http-client
composer require nyholm/psr7

Code sample

Client initialization

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

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client\Client(
    'https://sandbox.api.video',
    'YOUR_API_TOKEN',
    $httpClient
);
?>

Create a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

// the `$client` must already be initialized.
$video = $client->videos()->create($payload);

Upload a video

$payload = (new VideoCreationPayload())
    ->setTitle('Test video creation');

$video = $client->videos()->create($payload);

// the `$client` must already be initialized.
$client->videos()->upload(
    $video->getVideoId(),
    new SplFileObject(__DIR__.'/../earth.mp4')
);

Documentation

API Endpoints

All URIs are relative to https://ws.api.video.

CaptionsApi

Retrieve an instance of CaptionsApi

// The $client must already be initialized
$captions = $client->captions();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId}/captions/{language} Delete a caption
list GET /videos/{videoId}/captions List video captions
get GET /videos/{videoId}/captions/{language} Show a caption
update PATCH /videos/{videoId}/captions/{language} Update caption
upload POST /videos/{videoId}/captions/{language} Upload a caption

ChaptersApi

Retrieve an instance of ChaptersApi

// The $client must already be initialized
$chapters = $client->chapters();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId}/chapters/{language} Delete a chapter
list GET /videos/{videoId}/chapters List video chapters
get GET /videos/{videoId}/chapters/{language} Show a chapter
upload POST /videos/{videoId}/chapters/{language} Upload a chapter

LiveStreamsApi

Retrieve an instance of LiveStreamsApi

// The $client must already be initialized
$liveStreams = $client->liveStreams();

Endpoints

Method HTTP request Description
delete DELETE /live-streams/{liveStreamId} Delete a live stream
deleteThumbnail DELETE /live-streams/{liveStreamId}/thumbnail Delete a thumbnail
list GET /live-streams List all live streams
get GET /live-streams/{liveStreamId} Show live stream
update PATCH /live-streams/{liveStreamId} Update a live stream
create POST /live-streams Create live stream
uploadThumbnail POST /live-streams/{liveStreamId}/thumbnail Upload a thumbnail

PlayerThemesApi

Retrieve an instance of PlayerThemesApi

// The $client must already be initialized
$playerThemes = $client->playerThemes();

Endpoints

Method HTTP request Description
delete DELETE /players/{playerId} Delete a player
deleteLogo DELETE /players/{playerId}/logo Delete logo
list GET /players List all players
get GET /players/{playerId} Show a player
update PATCH /players/{playerId} Update a player
create POST /players Create a player
uploadLogo POST /players/{playerId}/logo Upload a logo

RawStatisticsApi

Retrieve an instance of RawStatisticsApi

// The $client must already be initialized
$rawStatistics = $client->rawStatistics();

Endpoints

Method HTTP request Description
listLiveStreamSessions GET /analytics/live-streams/{liveStreamId} List live stream player sessions
listSessionEvents GET /analytics/sessions/{sessionId}/events List player session events
listVideoSessions GET /analytics/videos/{videoId} List video player sessions

UploadTokensApi

Retrieve an instance of UploadTokensApi

// The $client must already be initialized
$uploadTokens = $client->uploadTokens();

Endpoints

Method HTTP request Description
deleteToken DELETE /upload-tokens/{uploadToken} Delete an upload token
list GET /upload-tokens List all active upload tokens.
getToken GET /upload-tokens/{uploadToken} Show upload token
createToken POST /upload-tokens Generate an upload token

VideosApi

Retrieve an instance of VideosApi

// The $client must already be initialized
$videos = $client->videos();

Endpoints

Method HTTP request Description
delete DELETE /videos/{videoId} Delete a video
get GET /videos/{videoId} Show a video
getStatus GET /videos/{videoId}/status Show video status
list GET /videos List all videos
update PATCH /videos/{videoId} Update a video
pickThumbnail PATCH /videos/{videoId}/thumbnail Pick a thumbnail
uploadWithUploadToken POST /upload Upload with an upload token
create POST /videos Create a video
upload POST /videos/{videoId}/source Upload a video
uploadThumbnail POST /videos/{videoId}/thumbnail Upload a thumbnail

WebhooksApi

Retrieve an instance of WebhooksApi

// The $client must already be initialized
$webhooks = $client->webhooks();

Endpoints

Method HTTP request Description
delete DELETE /webhooks/{webhookId} Delete a Webhook
get GET /webhooks/{webhookId} Show Webhook details
list GET /webhooks List all webhooks
create POST /webhooks Create Webhook

Models

Authentication

Some endpoints don't require authentication. These one can be called with a Client instantiated with a null API token:

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

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client\Client(
    'https://sandbox.api.video',
    null,
    $httpClient
);
?>

Chunks

The video is automatically split into 50 Mb chunks.

To modify the size of the chunks, fill in the last argument $contentRange as follows:

  • bytes 0-{size}/0 where {size} is the size of the chunk.

For example : bytes 0-500000/0 for 500 Kb chunks.

The chunks size value must be between 5 Mb and 128mb.

Tests

In order to run the PhpUnit tests, it is necessary to enter two variables in the command line:

  • BASE_URI (for example : https://sandbox.api.video)
  • API_KEY

These identifiers must belong to a real Api.video account.

$ BASE_URI="" API_KEY="..." vendor/bin/phpunit

Have you gotten use from this API client?

Please take a moment to leave a star on the client ⭐

This helps other users to find the clients and also helps us understand which clients are most popular. Thank you!

Contribution

Since this API client is generated from an OpenAPI description, we cannot accept pull requests made directly to the repository. If you want to contribute, you can open a pull request on the repository of our client generator. Otherwise, you can also simply open an issue detailing your need on this repository.