-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathexercise-uploads.php
44 lines (37 loc) · 2.1 KB
/
exercise-uploads.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once(__DIR__ . '/../assert.php');
require_once 'vendor/autoload.php';
// Exercises all direct upload operations.
// Authentication Setup
$config = MuxPhp\Configuration::getDefaultConfiguration()
->setUsername(getenv('MUX_TOKEN_ID'))
->setPassword(getenv('MUX_TOKEN_SECRET'));
// API Client Initialization
$uploadsApi = new MuxPhp\Api\DirectUploadsApi(
new GuzzleHttp\Client(),
$config
);
// ========== create-direct-upload ==========
$subtitles = new MuxPhp\Models\AssetGeneratedSubtitleSettings(["language_code" => "en", "name" => "English (Generated)"]);
$input = new MuxPhp\Models\InputSettings(["generated_subtitles" => [$subtitles]]);
$createAssetRequest = new MuxPhp\Models\CreateAssetRequest(["input" => [$input], "playback_policy" => [MuxPhp\Models\PlaybackPolicy::_PUBLIC]]);
$createUploadRequest = new MuxPhp\Models\CreateUploadRequest(["timeout" => 3600, "new_asset_settings" => $createAssetRequest, "cors_origin" => "philcluff.co.uk"]);
$upload = $uploadsApi->createDirectUpload($createUploadRequest);
assert($upload->getData()->getId() !== null);
print("create-direct-upload OK ✅\n");
// ========== list-direct-uploads ==========
$uploads = $uploadsApi->listDirectUploads();
assert($uploads->getData()[0]->getId() !== null);
assert($uploads->getData()[0]->getId() === $upload->getData()->getId());
print("list-direct-uploads OK ✅\n");
// ========== get-direct-upload ==========
$getUpload = $uploadsApi->getDirectUpload($upload->getData()->getId());
assert($getUpload->getData()->getId() !== null);
assert($getUpload->getData()->getId() === $upload->getData()->getId());
print("get-direct-upload OK ✅\n");
// ========== cancel-direct-upload ==========
$cancelled = $uploadsApi->cancelDirectUpload($upload->getData()->getId());
assert($cancelled->getData()->getId() !== null);
assert($cancelled->getData()->getId() === $upload->getData()->getId());
assert($cancelled->getData()->getStatus() === "cancelled");
print("cancel-direct-upload OK ✅\n");