From 2223cd5ffa4c64726b21a13a84ea9aff5a4534ea Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Wed, 29 Apr 2020 15:28:31 -0600 Subject: [PATCH 1/5] Enable dropbox sdk search v2 Dropbox.php - created a new method "searchV2" to enable dropbox search version 2 since search version 1 is deprecated. --- .gitignore | 1 + src/Dropbox/Dropbox.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) 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/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b017c38..d79565b 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -469,6 +469,39 @@ public function search($path, $query, array $params = []) return $this->makeModelFromResponse($response); } + /** + * Search a folder for files/folders + * + * @param string $path Path to search + * @param string $query Search Query + * @param array $params Additional Params + * + * @link https://www.dropbox.com/developers/documentation/http/documentation#files-search + * + * @return \Kunnu\Dropbox\Models\SearchResults + */ + public function searchV2($query, array $params = []) + { + //Specify the root folder as an + //empty string rather than as "/" + if ($path === '/') { + $path = ""; + } + + //Set the path and query + $params['query'] = $query; + + if( !array_key_exists( 'include_highlights', $params ) ){ + $params['include_highlights'] = false; + } + + //Fetch Search Results + $response = $this->postToAPI('/files/search_v2', $params); + + //Make and Return the Model + return $this->makeModelFromResponse($response); + } + /** * Create a folder at the given path * From 3cad564e7f4b32853826698748acd7ac901e4ca5 Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Tue, 17 Oct 2023 10:08:35 -0600 Subject: [PATCH 2/5] updated v2 search --- src/Dropbox/Dropbox.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index 1097139..4a65517 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -475,18 +475,17 @@ public function search($path, $query, array $params = []) return $this->makeModelFromResponse($response); } - /** + /** * Search a folder for files/folders * - * @param string $path Path to search - * @param string $query Search Query - * @param array $params Additional Params + * @param string $path Path to search + * @param string $query Search Query + * @param array $params Additional Params * - * @link https://www.dropbox.com/developers/documentation/http/documentation#files-search - * - * @return \Kunnu\Dropbox\Models\SearchResults + * @return \Kunnu\Dropbox\Models\ModelInterface + * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException */ - public function searchV2($query, array $params = []) + public function searchV2($path, $query, array $params = []) { //Specify the root folder as an //empty string rather than as "/" @@ -495,10 +494,15 @@ public function searchV2($query, array $params = []) } //Set the path and query + $params['path'] = $path; $params['query'] = $query; - if( !array_key_exists( 'include_highlights', $params ) ){ - $params['include_highlights'] = false; + if( !array_key_exists( 'match_field_options', $params ) ){ + if( array_key_exists( 'include_highlights', $params ) ){ + $params['match_field_options'] = '{"include_highlights": ' . ( $params["include_highlights"] ? 'true' : 'false' ) . "}"; + } else { + $params['match_field_options'] = '{ "include_highlights": false }'; + } } //Fetch Search Results From ea00145d3190bdaacba2ffb588161e6a0986ad71 Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Tue, 17 Oct 2023 10:35:55 -0600 Subject: [PATCH 3/5] Updated composer to support php v8 and to add ext-json --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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" } } From 3a4d3d958e9a562b5f5c8b959ba3afcd93c37a25 Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Tue, 17 Oct 2023 10:36:43 -0600 Subject: [PATCH 4/5] Added Dropbox-API-Path-Root support --- src/Dropbox/Dropbox.php | 6 ++++- .../Http/Clients/DropboxGuzzleHttpClient.php | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index 4a65517..b6139b3 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); From 7cfb90851febe0c9efb1369f7febda5eae85b9ac Mon Sep 17 00:00:00 2001 From: Adam Wasserman Date: Tue, 17 Oct 2023 10:39:13 -0600 Subject: [PATCH 5/5] removed v2 search to create PR to main repo --- src/Dropbox/Dropbox.php | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/src/Dropbox/Dropbox.php b/src/Dropbox/Dropbox.php index b6139b3..6b6af05 100644 --- a/src/Dropbox/Dropbox.php +++ b/src/Dropbox/Dropbox.php @@ -479,43 +479,6 @@ public function search($path, $query, array $params = []) return $this->makeModelFromResponse($response); } - /** - * Search a folder for files/folders - * - * @param string $path Path to search - * @param string $query Search Query - * @param array $params Additional Params - * - * @return \Kunnu\Dropbox\Models\ModelInterface - * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException - */ - public function searchV2($path, $query, array $params = []) - { - //Specify the root folder as an - //empty string rather than as "/" - if ($path === '/') { - $path = ""; - } - - //Set the path and query - $params['path'] = $path; - $params['query'] = $query; - - if( !array_key_exists( 'match_field_options', $params ) ){ - if( array_key_exists( 'include_highlights', $params ) ){ - $params['match_field_options'] = '{"include_highlights": ' . ( $params["include_highlights"] ? 'true' : 'false' ) . "}"; - } else { - $params['match_field_options'] = '{ "include_highlights": false }'; - } - } - - //Fetch Search Results - $response = $this->postToAPI('/files/search_v2', $params); - - //Make and Return the Model - return $this->makeModelFromResponse($response); - } - /** * Create a folder at the given path *