FileOptions class
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-01-12 14:00:06 +00:00
parent bd500406d3
commit e389e72844
6 changed files with 56 additions and 11 deletions

30
src/FileOptions.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace Nwb\MultiDownloaderClient;
class FileOptions
{
/**
* @var string
*/
private $name;
public function name(string $name)
{
$this->name = $name;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function toArray(): array
{
return [
'name' => $this->name
];
}
}

View File

@@ -4,14 +4,25 @@ namespace Nwb\MultiDownloaderClient;
class FileRequest
{
/**
* @var string
*/
private $url;
/**
* @var string
*/
private $fallbackUrl;
private $fileOptions = [];
/**
* @var FileOptions
*/
private $fileOptions;
public function __construct(string $url, string $fallbackUrl = null)
{
$this->url = $url;
$this->fallbackUrl = $fallbackUrl;
$this->fileOptions = new FileOptions();
}
public function url(string $url)
@@ -28,14 +39,14 @@ class FileRequest
return $this;
}
public function fileOptions(array $fileOptions)
public function fileOptions(FileOptions $fileOptions)
{
$this->fileOptions = $fileOptions;
return $this;
}
public function getFileOptions(): array
public function getFileOptions(): FileOptions
{
return $this->fileOptions;
}
@@ -55,7 +66,7 @@ class FileRequest
return array_filter([
'url' => $this->url,
'fallbackUrl' => $this->fallbackUrl,
'fileOptions' => $this->fileOptions,
'fileOptions' => $this->fileOptions->toArray(),
]);
}
}

View File

@@ -23,15 +23,19 @@ class MultiDownloaderClient
public function __construct(array $options = [])
{
$apiKey = $options['apiKey'] ?? getenv('MULTI_DOWNLOADER_ACCESS_KEY');
if (!$apiKey) {
throw new \InvalidArgumentException('API key is required');
}
$this->apiKey = $apiKey;
$apiSecret = $options['apiSecret'] ?? getenv('MULTI_DOWNLOADER_SECRET_KEY');
if (!$apiSecret) {
throw new \InvalidArgumentException('API secret key is required');
}
$this->apiSecret = $apiSecret;
$this->url = $options['url'] ?? getenv('MULTI_DOWNLOADER_URL') ?: 'https://multi-dl.kub.nwb.fr';