fileOptions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mathieu 2024-01-12 13:04:17 +00:00
parent 4ca5d048d9
commit 345e6a0c51
4 changed files with 31 additions and 9 deletions

View File

@ -64,3 +64,10 @@ Get html form
```php
$form = $client->htmlForm();
```
Rename files inside zip
```php
$file = (new FileRequest('http://example.com/image.png'))
->fileOptions([
'name' => 'my-new-name.png'
]);
```

View File

@ -6,6 +6,7 @@ class FileRequest
{
private $url;
private $fallbackUrl;
private $fileOptions = [];
public function __construct(string $url, string $fallbackUrl = null)
{
@ -27,6 +28,18 @@ class FileRequest
return $this;
}
public function fileOptions(array $fileOptions)
{
$this->fileOptions = $fileOptions;
return $this;
}
public function getFileOptions(): array
{
return $this->fileOptions;
}
public function getUrl(): string
{
return $this->url;
@ -39,9 +52,10 @@ class FileRequest
public function toArray(): array
{
return [
return array_filter([
'url' => $this->url,
'fallback_url' => $this->fallbackUrl,
];
'fallbackUrl' => $this->fallbackUrl,
'fileOptions' => $this->fileOptions,
]);
}
}

View File

@ -15,9 +15,10 @@ class MultiDownloaderClientTest extends TestCase
private function testFiles()
{
return array_map(function ($url) {
return new FileRequest($url);
}, $this->testFiles);
return array_map(function ($url, $i) {
return (new FileRequest($url))
->fileOptions(['name' => 'test' . $i . '.png']);
}, $this->testFiles, array_keys($this->testFiles));
}
public function testDownloadAsString()
@ -30,14 +31,14 @@ class MultiDownloaderClientTest extends TestCase
$md5 = md5($response);
$this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5);
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5);
}
public function testDownloadTo()
{
$client = new MultiDownloaderClient(['apiKey' => 'test', 'apiSecret' => 'test']);
$path = sys_get_temp_dir() . '/testDownloadTo.zip';
$path = __DIR__ . '/testDownloadTo.zip';
$client->setFiles($this->testFiles());
$client->downloadTo($path);
@ -45,7 +46,7 @@ class MultiDownloaderClientTest extends TestCase
$md5 = md5_file($path);
$this->assertFileExists($path);
$this->assertEquals('ea9726d2ecbe6b820899ba125bf0ae94', $md5);
$this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5);
}
public function testForm()

BIN
tests/testDownloadTo.zip Normal file

Binary file not shown.