-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from andreia/add_transcode_api
Add Transcode API
- Loading branch information
Showing
11 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@andreia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Bug Report | ||
description: Report an Issue or Bug with the Package | ||
title: "[Bug]: " | ||
labels: ["bug"] | ||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
We're sorry to hear you have a problem. Can you help us solve it by providing the following details. | ||
- type: textarea | ||
id: what-happened | ||
attributes: | ||
label: What happened? | ||
description: What did you expect to happen? | ||
placeholder: I cannot currently do X thing because when I do, it breaks X thing. | ||
validations: | ||
required: true | ||
- type: textarea | ||
id: how-to-reproduce | ||
attributes: | ||
label: How to reproduce the bug | ||
description: How did this occur, please add any config values used and provide a set of reliable steps if possible. | ||
placeholder: When I do X I see Y. | ||
validations: | ||
required: true | ||
- type: input | ||
id: package-version | ||
attributes: | ||
label: Package Version | ||
description: What version of our Package are you running? Please be as specific as possible | ||
placeholder: 2.0.0 | ||
validations: | ||
required: true | ||
- type: input | ||
id: php-version | ||
attributes: | ||
label: PHP Version | ||
description: What version of PHP are you running? Please be as specific as possible | ||
placeholder: 8.2.0 | ||
validations: | ||
required: true | ||
- type: input | ||
id: laravel-version | ||
attributes: | ||
label: Laravel Version | ||
description: What version of Laravel are you running? Please be as specific as possible | ||
placeholder: 9.0.0 | ||
validations: | ||
required: true | ||
- type: dropdown | ||
id: operating-systems | ||
attributes: | ||
label: Which operating systems does with happen with? | ||
description: You may select more than one. | ||
multiple: true | ||
options: | ||
- macOS | ||
- Windows | ||
- Linux | ||
- type: textarea | ||
id: notes | ||
attributes: | ||
label: Notes | ||
description: Use this field to provide any other notes that you feel might be relevant to the issue. | ||
validations: | ||
required: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
blank_issues_enabled: false | ||
contact_links: | ||
- name: Ask a question | ||
url: https://github.com/andreia/php-sdk-dolby-api/discussions/new?category=q-a | ||
about: Ask the community for help | ||
- name: Request a feature | ||
url: https://github.com/andreia/php-sdk-dolby-api/discussions/new?category=ideas | ||
about: Share ideas for new features | ||
- name: Report a security issue | ||
url: https://github.com/andreia/php-sdk-dolby-api/security/policy | ||
about: Learn how to notify us for sensitive bugs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DolbyApi\Requests\MediaApi; | ||
|
||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
|
||
class GetTranscodeResults extends Request | ||
{ | ||
/** | ||
* HTTP Method | ||
*/ | ||
protected Method $method = Method::GET; | ||
|
||
public function __construct( | ||
protected string $jobId, | ||
) {} | ||
|
||
protected function defaultQuery(): array | ||
{ | ||
return [ | ||
'job_id' => $this->jobId, | ||
]; | ||
} | ||
|
||
/** | ||
* Get Transcode Results | ||
* | ||
* For a given job_id, this method will check if the transcoding task | ||
* has completed and return transcoding results. | ||
* | ||
* @see https://docs.dolby.io/media-apis/reference/media-transcode-get | ||
*/ | ||
public function resolveEndpoint(): string | ||
{ | ||
return '/media/transcode'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DolbyApi\Requests\MediaApi; | ||
|
||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class StartTranscoding extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
/** | ||
* HTTP Method | ||
*/ | ||
protected Method $method = Method::POST; | ||
|
||
public function __construct( | ||
protected array $inputs, | ||
protected array $outputs, | ||
protected ?array $storage = null, | ||
protected ?array $onComplete = null, | ||
) {} | ||
|
||
protected function defaultBody(): array | ||
{ | ||
$body = [ | ||
'inputs' => [$this->inputs], | ||
'outputs' => [$this->outputs], | ||
]; | ||
|
||
if ($this->storage !== null) { | ||
$body['storage'] = $this->storage; | ||
} | ||
|
||
if ($this->onComplete !== null) { | ||
$body['on_complete'] = $this->onComplete; | ||
} | ||
|
||
return $body; | ||
} | ||
|
||
/** | ||
* Start Transcoding | ||
* | ||
* Start transcoding to modify the size, bitrates, and formats for your media. | ||
* | ||
* @see https://docs.dolby.io/media-apis/reference/media-transcode-post | ||
*/ | ||
public function resolveEndpoint(): string | ||
{ | ||
return '/media/transcode'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use DolbyApi\DolbyApi; | ||
use DolbyApi\Requests\MediaApi\GetTranscodeResults; | ||
use DolbyApi\Responses\DolbyResponse; | ||
use Saloon\Contracts\Request; | ||
use Saloon\Contracts\Response; | ||
|
||
test('can retrieve transcoding results from the api', function () { | ||
$mockClient = mockClient(); | ||
$dolbyApi = new DolbyApi('my-api-token'); | ||
$dolbyApi->withMockClient($mockClient); | ||
|
||
$jobId = 'tr988637-9fb8-4123-62lt-1485r04627st'; | ||
|
||
$response = $dolbyApi->send(new GetTranscodeResults($jobId)); | ||
|
||
$mockClient->assertSent(GetTranscodeResults::class); | ||
|
||
$mockClient->assertSent(function (Request $request, Response $response) { | ||
return $request instanceof GetTranscodeResults | ||
&& $response->body() == '{"path":"/media/transcode","status":"Success","progress":100,"api_version":"v1.7","result":{}}'; | ||
}); | ||
|
||
expect($response)->toBeInstanceOf(DolbyResponse::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use DolbyApi\DolbyApi; | ||
use DolbyApi\Requests\MediaApi\StartTranscoding; | ||
use DolbyApi\Responses\DolbyResponse; | ||
use Saloon\Contracts\Request; | ||
use Saloon\Contracts\Response; | ||
|
||
/** | ||
* @see https://docs.dolby.io/media-apis/docs/transcoding-media | ||
*/ | ||
test('can post to transcode', function () { | ||
$mockClient = mockClient(); | ||
$dolbyApi = new DolbyApi('my-api-token'); | ||
$dolbyApi->withMockClient($mockClient); | ||
|
||
$inputs = [ | ||
'source' => 'https://dolbyio.s3-us-west-1.amazonaws.com/public/shelby/indoors.original.mp4', | ||
]; | ||
|
||
$outputs = [ | ||
'id' => 'my_mp4', | ||
'destination' => 'dlb://out/airplane-transcoded.mp4', | ||
'kind' => 'mp4', | ||
]; | ||
|
||
$response = $dolbyApi->send(new StartTranscoding($inputs, $outputs)); | ||
|
||
$mockClient->assertSent(StartTranscoding::class); | ||
|
||
$mockClient->assertSent(function (Request $request, Response $response) { | ||
return $request instanceof StartTranscoding | ||
&& $response->body() == '{"job_id":"tr988637-9fb8-4123-62lt-1485r04627st"}'; | ||
}); | ||
|
||
expect($response)->toBeInstanceOf(DolbyResponse::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"statusCode":200,"headers":{"Content-Type":"application\/json","Content-Length":"98","Connection":"keep-alive","Server":"CloudFront","Date":"Sun, 29 Sep 2024 17:29:05 GMT","Apigw-Requestid":"{\"0\": \"BNzjHhs-vHcESEA=\",\"1\":\"BNzjEjIFIAMEYnQ=\"}","x-cache":"Miss from cloudfront","Via":"1.1 071a100b70812281a393c7b4228a4288.cloudfront.net (CloudFront)","X-Amz-Cf-Pop":"GRU3-P2","X-Amz-Cf-Id":"LAmYbsQaWmZZcz7NkP5_fSMerBLTScPYQG0SQx6BwvzLTEHdZ_JTQ==","Vary":"Origin"},"data":"{\"path\":\"/media/transcode\",\"status\":\"Success\",\"progress\":100,\"api_version\":\"v1.7\",\"result\":{}}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"statusCode":200,"headers":{"Content-Type":"application\/json","Content-Length":"49","Connection":"keep-alive","Server":"CloudFront","Date":"Sun, 29 Sep 2024 17:29:05 GMT","Apigw-Requestid":"{\"0\": \"BNzjHhs-vHcESEA=\",\"1\":\"BNzjEjIFIAMEYnQ=\"}","x-cache":"Miss from cloudfront","Via":"1.1 071a100b70811081a393c7b4228a4288.cloudfront.net (CloudFront)","X-Amz-Cf-Pop":"GRU3-P6","X-Amz-Cf-Id":"LAmYbsQaWmZZcz7NkP5_fSDerBLTScPYQG1EWx6BwvzLTEHdZ_JTQ==","Vary":"Origin"},"data":"{\"job_id\":\"tr988637-9fb8-4123-62lt-1485r04627st\"}"} |