Skip to content

Commit

Permalink
Files to an array of objects. (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Davis Puciriuss <davis.puciriuss@ltv.lv>
  • Loading branch information
DavisPuciriuss and Davis Puciriuss authored May 20, 2024
1 parent f90c220 commit 6a0eeb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
17 changes: 14 additions & 3 deletions src/Endpoints/Media/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Create extends AbstractEndpoint implements EndpointContract

protected ?string $timezone = null;

protected ?Files $files = null;
/** @var Files[]|null $files */
protected ?array $files = null;

protected ?Tags $tags = null;

Expand Down Expand Up @@ -137,7 +138,10 @@ public function timezone(?string $timezone): static
return $this;
}

public function files(?Files $files): static
/**
* @param Files[]|null $files
*/
public function files(?array $files): static
{
$this->files = $files;

Expand Down Expand Up @@ -241,7 +245,14 @@ public function prepareHttpRequest(PendingRequest $http): void
}

if ($this->files !== null) {
$files = $this->files->compileAsArray();
$files = [];

foreach ($this->files as $value) {
$file = $value->compileAsArray();
if (!empty($file)) {
$files[] = $file;
}
}

if (!empty($files)) {
$data['files'] = $files;
Expand Down
16 changes: 9 additions & 7 deletions tests/Endpoints/Media/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,18 @@ public function test_with_files(): void
$files->bitrate(3000);
$files->lang('lv');

$endpoint->files($files);
$endpoint->files([$files]);

$this->makeBearerAuthEndpointTest($endpoint, [], [
'asset_id' => "123",
'files' => [
'url' => 'https://mysite.com',
'username' => 'username',
'password'=> 'password',
'bitrate'=> 3000,
'lang'=> 'lv',
[
'url' => 'https://mysite.com',
'username' => 'username',
'password'=> 'password',
'bitrate'=> 3000,
'lang'=> 'lv',
]
],
]);
}
Expand All @@ -180,7 +182,7 @@ public function test_with_empty_files(): void
$endpoint = new Create('123');

$files = new Files();
$endpoint->files($files);
$endpoint->files([$files]);

$this->makeBearerAuthEndpointTest($endpoint, [], [
'asset_id' => "123",
Expand Down

0 comments on commit 6a0eeb5

Please sign in to comment.