Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ index.php
composer.lock
/.idea
.php_cs.cache
.DS_Store
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
],
"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": {
"Kunnu\\Dropbox\\": "src/Dropbox"
}
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^6.0|^7.0|^8.0"
}
}
6 changes: 5 additions & 1 deletion src/Dropbox/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class DropboxGuzzleHttpClient implements DropboxHttpClientInterface
*/
protected $client;

/**
* @var string|null
*/
protected $namespaceId = null;

/**
* Create a new DropboxGuzzleHttpClient instance.
*
Expand All @@ -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.
*
Expand All @@ -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);

Expand Down