From 610908dba8dcd7cac83dd11dfc166c8dda330e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Hansson?= Date: Thu, 19 Dec 2019 17:16:28 +0100 Subject: [PATCH] New: downloadZip --- src/Dropbox/Dropbox.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b017c38..c5a695a 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -1203,6 +1203,42 @@ public function download($path, $dropboxFile = null) return new File($metadata, $contents); } + /** + * Download a folder as a zip file + * + * @param string $path Path to the file you want to download + * @param null|string|DropboxFile $dropboxFile DropboxFile object or Path to target file + * + * @return \Kunnu\Dropbox\Models\File + * + * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException + * + * @link https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip + * + */ + public function downloadZip($path, $dropboxFile = null) + { + //Path cannot be null + if (is_null($path)) { + throw new DropboxClientException("Path cannot be null."); + } + + //Make Dropbox File if target is specified + $dropboxFile = $dropboxFile ? $this->makeDropboxFile($dropboxFile, null, null, DropboxFile::MODE_WRITE) : null; + + //Download File + $response = $this->postToContent('/files/download_zip', ['path' => $path], null, $dropboxFile); + + //Get file metadata from response headers + $metadata = $this->getMetadataFromResponseHeaders($response); + + //File Contents + $contents = $dropboxFile ? $this->makeDropboxFile($dropboxFile) : $response->getBody(); + + //Make and return a File model + return new File($metadata, $contents); + } + /** * Get Current Account *