diff --git a/.gitignore b/.gitignore index 3938932..6724e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ index.php composer.lock /.idea .php_cs.cache +.DS_Store diff --git a/composer.json b/composer.json index b94df2c..d9bea41 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ ], "require": { "guzzlehttp/guzzle": "~6.0|~7.0", - "illuminate/collections": "^8.0|^9.0|^10.0" + "illuminate/collections": "^8.0|^9.0|^10.0", + "ext-json": "*" }, "autoload": { "psr-4": { @@ -19,6 +20,6 @@ } }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.0|^7.0|^8.0" } } diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index d59c276..6b6af05 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -105,7 +105,8 @@ public function __construct(DropboxApp $app, array $config = []) $config = array_merge([ 'http_client_handler' => null, 'random_string_generator' => null, - 'persistent_data_store' => null + 'persistent_data_store' => null, + 'namespace_id' => null ], $config); //Set the app @@ -117,6 +118,9 @@ public function __construct(DropboxApp $app, array $config = []) //Make the HTTP Client $httpClient = DropboxHttpClientFactory::make($config['http_client_handler']); + //Set the namespace id for the global header Dropbox-API-Path-Root + $httpClient->setNamespace($config['namespace_id']); + //Make and Set the DropboxClient $this->client = new DropboxClient($httpClient); diff --git a/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php b/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php index de1200d..f3fc0b3 100644 --- a/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php +++ b/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php @@ -23,6 +23,11 @@ class DropboxGuzzleHttpClient implements DropboxHttpClientInterface */ protected $client; + /** + * @var string|null + */ + protected $namespaceId = null; + /** * Create a new DropboxGuzzleHttpClient instance. * @@ -34,6 +39,14 @@ public function __construct(Client $client = null) $this->client = $client ?: new Client(); } + /** + * @param int $namespaceId The namespace id + */ + public function setNamespace( $namespaceId ){ + $this->namespaceId = $namespaceId; + } + + /** * Send request to the server and fetch the raw response. * @@ -49,6 +62,19 @@ public function __construct(Client $client = null) */ public function send($url, $method, $body, $headers = [], $options = []) { + //Create a global header for the namespace + if ($this->namespaceId) { + $headers = array_merge( + $headers, + [ + 'Dropbox-API-Path-Root' => json_encode([ + '.tag' => 'namespace_id', + 'namespace_id' => $this->namespaceId, + ]), + ] + ); + } + //Create a new Request Object $request = new Request($method, $url, $headers, $body);