testrequest
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Nwb\MultiDownloaderClient;
|
||||
|
||||
class MultiDownloaderClient
|
||||
{
|
||||
private string $apiUrl = 'https://multi-dl.kub.nwb.fr';
|
||||
private string $apiKey;
|
||||
|
||||
public function __construct(string $apiKey = null)
|
||||
@@ -16,4 +17,40 @@ class MultiDownloaderClient
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
public function download(array $files)
|
||||
{
|
||||
$files = array_map(function (FileRequest $file) {
|
||||
return $file->toArray();
|
||||
}, $files);
|
||||
|
||||
return $this->sendRequest($files);
|
||||
}
|
||||
|
||||
private function sendRequest(array $files)
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->apiUrl . '/v2/zip');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($files));
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
throw new MultiDownloaderException('Error while requesting API: ' . $response);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user