downloads
This commit is contained in:
@@ -18,7 +18,7 @@ class MultiDownloaderClient
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
public function download(array $files)
|
||||
public function downloadAsString(array $files)
|
||||
{
|
||||
$files = array_map(function (FileRequest $file) {
|
||||
return $file->toArray();
|
||||
@@ -27,20 +27,36 @@ class MultiDownloaderClient
|
||||
return $this->sendRequest($files);
|
||||
}
|
||||
|
||||
private function sendRequest(array $files)
|
||||
public function downloadTo(string $path, array $files)
|
||||
{
|
||||
$files = array_map(function (FileRequest $file) {
|
||||
return $file->toArray();
|
||||
}, $files);
|
||||
|
||||
$response = $this->sendRequest($files, [
|
||||
CURLOPT_RETURNTRANSFER => false,
|
||||
CURLOPT_FILE => fopen($path, 'w'),
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function sendRequest(array $files, array $options = [])
|
||||
{
|
||||
$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',
|
||||
$options = array_replace($options, [
|
||||
CURLOPT_URL => $this->apiUrl . '/v2/zip',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($files),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
curl_setopt_array($ch, $options);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
Reference in New Issue
Block a user