From ba2623f6639b09af34cea7405b60718b14e08e95 Mon Sep 17 00:00:00 2001 From: partyzone Date: Tue, 3 Mar 2015 09:01:28 +0300 Subject: [PATCH 1/2] Unified MetaData methods, added optional parameters 'hash', 'list' and 'include_deleted'. --- DropNet/Client/Files.Async.cs | 17 ++++------------- DropNet/Client/Files.Sync.cs | 8 ++++---- DropNet/Client/Files.Task.cs | 17 ++++------------- DropNet/Client/IDropNetClient.cs | 22 +++++++++++++--------- DropNet/Helpers/RequestHelper.cs | 9 ++++++++- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/DropNet/Client/Files.Async.cs b/DropNet/Client/Files.Async.cs index 889443c..00489f5 100644 --- a/DropNet/Client/Files.Async.cs +++ b/DropNet/Client/Files.Async.cs @@ -9,25 +9,16 @@ namespace DropNet { public partial class DropNetClient { - public void GetMetaDataAsync(string path, Action success, Action failure) + public void GetMetaDataAsync(Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false) { - if (!string.IsNullOrEmpty(path) && !path.StartsWith("/")) - { - path = "/" + path; - } - - var request = _requestHelper.CreateMetadataRequest(path, Root); - - ExecuteAsync(ApiType.Base, request, success, failure); + GetMetaDataAsync(String.Empty, success, failure, hash, list, include_deleted); } - public void GetMetaDataAsync(string path, string hash, Action success, Action failure) + public void GetMetaDataAsync(String path, Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); - - request.AddParameter("hash", hash); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); ExecuteAsync(ApiType.Base, request, success, failure); } diff --git a/DropNet/Client/Files.Sync.cs b/DropNet/Client/Files.Sync.cs index 6b38c04..30a3952 100644 --- a/DropNet/Client/Files.Sync.cs +++ b/DropNet/Client/Files.Sync.cs @@ -14,16 +14,16 @@ namespace DropNet { public partial class DropNetClient { - public MetaData GetMetaData() + public MetaData GetMetaData(String hash = null, Boolean list = false, Boolean include_deleted = false) { - return GetMetaData(string.Empty); + return GetMetaData(String.Empty, hash, list, include_deleted); } - public MetaData GetMetaData(string path) + public MetaData GetMetaData(String path, String hash = null, Boolean list = false, Boolean include_deleted = false) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); return Execute(ApiType.Base, request); } diff --git a/DropNet/Client/Files.Task.cs b/DropNet/Client/Files.Task.cs index f290c04..3ac30b8 100644 --- a/DropNet/Client/Files.Task.cs +++ b/DropNet/Client/Files.Task.cs @@ -11,25 +11,16 @@ namespace DropNet { public partial class DropNetClient { - public Task GetMetaDataTask(string path) + public Task GetMetaDataTask(String hash, Boolean list, Boolean include_deleted) { - if (!string.IsNullOrEmpty(path) && !path.StartsWith("/")) - { - path = "/" + path; - } - - var request = _requestHelper.CreateMetadataRequest(path, Root); - - return ExecuteTask(ApiType.Base, request); + return GetMetaDataTask(String.Empty, hash, list, include_deleted); } - public Task GetMetaDataTask(string path, string hash) + public Task GetMetaDataTask(String path, String hash, Boolean list, Boolean include_deleted) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); - - request.AddParameter("hash", hash); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); return ExecuteTask(ApiType.Base, request); } diff --git a/DropNet/Client/IDropNetClient.cs b/DropNet/Client/IDropNetClient.cs index 0c1626e..08241e6 100644 --- a/DropNet/Client/IDropNetClient.cs +++ b/DropNet/Client/IDropNetClient.cs @@ -51,23 +51,21 @@ public interface IDropNetClient string BuildAuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string redirectUri, string state = null); /// - /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. + /// Gets MetaData for the root folder. /// /// The path of the file or folder /// Success call back /// Failure call back - void GetMetaDataAsync(string path, Action success, Action failure); + void GetMetaDataAsync(Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. - /// Optional 'hash' param returns HTTP code 304 (Directory contents have not changed) if contents have not changed since the - /// hash was retrieved on a previous call. /// /// The path of the file or folder /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. /// Success callback /// Failure callback - void GetMetaDataAsync(string path, string hash, Action success, Action failure); + void GetMetaDataAsync(String path, Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets list of metadata for search string @@ -326,8 +324,8 @@ public interface IDropNetClient /// Failure callback void GetCopyRefAsync(string path, Action success, Action failure); - Task GetMetaDataTask(string path); - Task GetMetaDataTask(string path, string hash); + Task GetMetaDataTask(String hash = null, Boolean list = false, Boolean include_deleted = false); + Task GetMetaDataTask(String path, String hash = null, Boolean list = false, Boolean include_deleted = false); Task> SearchTask(string searchString); Task> SearchTask(string searchString, int fileLimit); Task> SearchTask(string searchString, string path); @@ -352,15 +350,21 @@ public interface IDropNetClient /// /// Gets MetaData for the root folder. /// + /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. + /// If true, the folder's metadata will include a contents field with a list of metadata entries for the contents of the folder. If false, the contents field will be omitted. + /// Only applicable when list is set. If this parameter is set to true, then contents will include the metadata of deleted children. Note that the target of the metadata call is always returned even when it has been deleted (with is_deleted set to true) regardless of this flag. /// - MetaData GetMetaData(); + MetaData GetMetaData(String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. /// /// The path of the file or folder + /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. + /// If true, the folder's metadata will include a contents field with a list of metadata entries for the contents of the folder. If false, the contents field will be omitted. + /// Only applicable when list is set. If this parameter is set to true, then contents will include the metadata of deleted children. Note that the target of the metadata call is always returned even when it has been deleted (with is_deleted set to true) regardless of this flag. /// - MetaData GetMetaData(string path); + MetaData GetMetaData(String path, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets List of MetaData for a File versions. Each metadata item contains info about file in certain version on Dropbox. diff --git a/DropNet/Helpers/RequestHelper.cs b/DropNet/Helpers/RequestHelper.cs index 5ca911f..17b03e2 100644 --- a/DropNet/Helpers/RequestHelper.cs +++ b/DropNet/Helpers/RequestHelper.cs @@ -18,7 +18,7 @@ public RequestHelper(string version) _version = version; } - public RestRequest CreateMetadataRequest(string path, string root) + public RestRequest CreateMetadataRequest(String path, String root, String hash, Boolean list, Boolean include_deleted) { var request = new RestRequest(Method.GET); request.Resource = "{version}/metadata/{root}{path}"; @@ -26,6 +26,13 @@ public RestRequest CreateMetadataRequest(string path, string root) request.AddParameter("path", path, ParameterType.UrlSegment); request.AddParameter("root", root, ParameterType.UrlSegment); + if (list) + { + request.AddParameter("hash", hash); + request.AddParameter("list", list.ToString().ToLower()); + request.AddParameter("include_deleted", include_deleted.ToString().ToLower()); + } + return request; } From 79e98895216dd41beb422818a73fe23eee07a573 Mon Sep 17 00:00:00 2001 From: partyzone Date: Tue, 3 Mar 2015 09:01:28 +0300 Subject: [PATCH 2/2] Unified MetaData methods, added optional parameters 'hash', 'list' and 'include_deleted'. Updated tests. --- DropNet.Tests/FileSyncTests.cs | 4 ++-- DropNet.Tests/FileTaskTests.cs | 4 ++-- DropNet.Tests/FileTests1.Sandbox.cs | 4 ++-- DropNet.Tests/Helpers/RequestHelperTest.cs | 2 +- DropNet/Client/Files.Async.cs | 17 ++++------------- DropNet/Client/Files.Sync.cs | 8 ++++---- DropNet/Client/Files.Task.cs | 17 ++++------------- DropNet/Client/IDropNetClient.cs | 22 +++++++++++++--------- DropNet/Helpers/RequestHelper.cs | 9 ++++++++- 9 files changed, 40 insertions(+), 47 deletions(-) diff --git a/DropNet.Tests/FileSyncTests.cs b/DropNet.Tests/FileSyncTests.cs index b7f7f11..73f7144 100644 --- a/DropNet.Tests/FileSyncTests.cs +++ b/DropNet.Tests/FileSyncTests.cs @@ -25,7 +25,7 @@ public FileSyncTests() [TestMethod] public void Can_Get_MetaData_With_Special_Char() { - var fileInfo = _client.GetMetaData("/Test/Getting'Started.rtf"); + var fileInfo = _client.GetMetaData("/Test/Getting'Started.rtf", null); Assert.IsNotNull(fileInfo); } @@ -169,7 +169,7 @@ public void Can_Delete_File() [TestMethod] public void Can_Get_MetaData() { - var metaData = _client.GetMetaData("/Public"); + var metaData = _client.GetMetaData("/Public", null); Assert.IsNotNull(metaData); Assert.IsNotNull(metaData.Contents); diff --git a/DropNet.Tests/FileTaskTests.cs b/DropNet.Tests/FileTaskTests.cs index 03ed35b..899e0d3 100644 --- a/DropNet.Tests/FileTaskTests.cs +++ b/DropNet.Tests/FileTaskTests.cs @@ -25,7 +25,7 @@ public FileTaskTests() public void Task_Get_MetaData() { var path = "/Test"; - var metaTask = _client.GetMetaDataTask(path); + var metaTask = _client.GetMetaDataTask(path, null); metaTask.Wait(); @@ -38,7 +38,7 @@ public void Task_Get_MetaData() public void Task_Get_MetaData_With_Special_Char() { var path = "/Test/Getting'Started.rtf"; - var metaTask = _client.GetMetaDataTask(path); + var metaTask = _client.GetMetaDataTask(path, null); metaTask.Wait(); diff --git a/DropNet.Tests/FileTests1.Sandbox.cs b/DropNet.Tests/FileTests1.Sandbox.cs index 66bf772..1c922ae 100644 --- a/DropNet.Tests/FileTests1.Sandbox.cs +++ b/DropNet.Tests/FileTests1.Sandbox.cs @@ -29,7 +29,7 @@ public FileTests_Sandbox() [TestMethod] public void SANDBOX_Can_Get_MetaData_With_Special_Char() { - var fileInfo = _client.GetMetaData("/test'.txt"); + var fileInfo = _client.GetMetaData("/test'.txt", null); Assert.IsNotNull(fileInfo); } @@ -163,7 +163,7 @@ public void SANDBOX_Can_Delete_File() [TestMethod] public void SANDBOX_Can_Get_MetaData() { - var metaData = _client.GetMetaData("/"); + var metaData = _client.GetMetaData("/", null); Assert.IsNotNull(metaData); Assert.IsNotNull(metaData.Contents); diff --git a/DropNet.Tests/Helpers/RequestHelperTest.cs b/DropNet.Tests/Helpers/RequestHelperTest.cs index 6d0f679..90ed653 100644 --- a/DropNet.Tests/Helpers/RequestHelperTest.cs +++ b/DropNet.Tests/Helpers/RequestHelperTest.cs @@ -198,7 +198,7 @@ public void CreateLoginRequestTest() public void CreateMetadataRequestTest() { string path = fixture.CreateAnonymous(); - RestRequest actual = _target.CreateMetadataRequest(path, "dropbox"); + RestRequest actual = _target.CreateMetadataRequest(path, "dropbox", null, false, false); Assert.IsNotNull(actual); Assert.IsTrue(actual.Method == Method.GET); diff --git a/DropNet/Client/Files.Async.cs b/DropNet/Client/Files.Async.cs index 889443c..00489f5 100644 --- a/DropNet/Client/Files.Async.cs +++ b/DropNet/Client/Files.Async.cs @@ -9,25 +9,16 @@ namespace DropNet { public partial class DropNetClient { - public void GetMetaDataAsync(string path, Action success, Action failure) + public void GetMetaDataAsync(Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false) { - if (!string.IsNullOrEmpty(path) && !path.StartsWith("/")) - { - path = "/" + path; - } - - var request = _requestHelper.CreateMetadataRequest(path, Root); - - ExecuteAsync(ApiType.Base, request, success, failure); + GetMetaDataAsync(String.Empty, success, failure, hash, list, include_deleted); } - public void GetMetaDataAsync(string path, string hash, Action success, Action failure) + public void GetMetaDataAsync(String path, Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); - - request.AddParameter("hash", hash); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); ExecuteAsync(ApiType.Base, request, success, failure); } diff --git a/DropNet/Client/Files.Sync.cs b/DropNet/Client/Files.Sync.cs index 6b38c04..30a3952 100644 --- a/DropNet/Client/Files.Sync.cs +++ b/DropNet/Client/Files.Sync.cs @@ -14,16 +14,16 @@ namespace DropNet { public partial class DropNetClient { - public MetaData GetMetaData() + public MetaData GetMetaData(String hash = null, Boolean list = false, Boolean include_deleted = false) { - return GetMetaData(string.Empty); + return GetMetaData(String.Empty, hash, list, include_deleted); } - public MetaData GetMetaData(string path) + public MetaData GetMetaData(String path, String hash = null, Boolean list = false, Boolean include_deleted = false) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); return Execute(ApiType.Base, request); } diff --git a/DropNet/Client/Files.Task.cs b/DropNet/Client/Files.Task.cs index f290c04..54525da 100644 --- a/DropNet/Client/Files.Task.cs +++ b/DropNet/Client/Files.Task.cs @@ -11,25 +11,16 @@ namespace DropNet { public partial class DropNetClient { - public Task GetMetaDataTask(string path) + public Task GetMetaDataTask(String hash, Boolean list = false, Boolean include_deleted = false) { - if (!string.IsNullOrEmpty(path) && !path.StartsWith("/")) - { - path = "/" + path; - } - - var request = _requestHelper.CreateMetadataRequest(path, Root); - - return ExecuteTask(ApiType.Base, request); + return GetMetaDataTask(String.Empty, hash, list, include_deleted); } - public Task GetMetaDataTask(string path, string hash) + public Task GetMetaDataTask(String path, String hash = null, Boolean list = false, Boolean include_deleted = false) { if (path != "" && !path.StartsWith("/")) path = "/" + path; - var request = _requestHelper.CreateMetadataRequest(path, Root); - - request.AddParameter("hash", hash); + var request = _requestHelper.CreateMetadataRequest(path, Root, hash, list, include_deleted); return ExecuteTask(ApiType.Base, request); } diff --git a/DropNet/Client/IDropNetClient.cs b/DropNet/Client/IDropNetClient.cs index 0c1626e..08241e6 100644 --- a/DropNet/Client/IDropNetClient.cs +++ b/DropNet/Client/IDropNetClient.cs @@ -51,23 +51,21 @@ public interface IDropNetClient string BuildAuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string redirectUri, string state = null); /// - /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. + /// Gets MetaData for the root folder. /// /// The path of the file or folder /// Success call back /// Failure call back - void GetMetaDataAsync(string path, Action success, Action failure); + void GetMetaDataAsync(Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. - /// Optional 'hash' param returns HTTP code 304 (Directory contents have not changed) if contents have not changed since the - /// hash was retrieved on a previous call. /// /// The path of the file or folder /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. /// Success callback /// Failure callback - void GetMetaDataAsync(string path, string hash, Action success, Action failure); + void GetMetaDataAsync(String path, Action success, Action failure, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets list of metadata for search string @@ -326,8 +324,8 @@ public interface IDropNetClient /// Failure callback void GetCopyRefAsync(string path, Action success, Action failure); - Task GetMetaDataTask(string path); - Task GetMetaDataTask(string path, string hash); + Task GetMetaDataTask(String hash = null, Boolean list = false, Boolean include_deleted = false); + Task GetMetaDataTask(String path, String hash = null, Boolean list = false, Boolean include_deleted = false); Task> SearchTask(string searchString); Task> SearchTask(string searchString, int fileLimit); Task> SearchTask(string searchString, string path); @@ -352,15 +350,21 @@ public interface IDropNetClient /// /// Gets MetaData for the root folder. /// + /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. + /// If true, the folder's metadata will include a contents field with a list of metadata entries for the contents of the folder. If false, the contents field will be omitted. + /// Only applicable when list is set. If this parameter is set to true, then contents will include the metadata of deleted children. Note that the target of the metadata call is always returned even when it has been deleted (with is_deleted set to true) regardless of this flag. /// - MetaData GetMetaData(); + MetaData GetMetaData(String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size. /// /// The path of the file or folder + /// hash - Optional. Listing return values include a hash representing the state of the directory's contents. If you provide this argument to the metadata call, you give the service an opportunity to respond with a "304 Not Modified" status code instead of a full (potentially very large) directory listing. This argument is ignored if the specified path is associated with a file or if list=false. + /// If true, the folder's metadata will include a contents field with a list of metadata entries for the contents of the folder. If false, the contents field will be omitted. + /// Only applicable when list is set. If this parameter is set to true, then contents will include the metadata of deleted children. Note that the target of the metadata call is always returned even when it has been deleted (with is_deleted set to true) regardless of this flag. /// - MetaData GetMetaData(string path); + MetaData GetMetaData(String path, String hash = null, Boolean list = false, Boolean include_deleted = false); /// /// Gets List of MetaData for a File versions. Each metadata item contains info about file in certain version on Dropbox. diff --git a/DropNet/Helpers/RequestHelper.cs b/DropNet/Helpers/RequestHelper.cs index 5ca911f..17b03e2 100644 --- a/DropNet/Helpers/RequestHelper.cs +++ b/DropNet/Helpers/RequestHelper.cs @@ -18,7 +18,7 @@ public RequestHelper(string version) _version = version; } - public RestRequest CreateMetadataRequest(string path, string root) + public RestRequest CreateMetadataRequest(String path, String root, String hash, Boolean list, Boolean include_deleted) { var request = new RestRequest(Method.GET); request.Resource = "{version}/metadata/{root}{path}"; @@ -26,6 +26,13 @@ public RestRequest CreateMetadataRequest(string path, string root) request.AddParameter("path", path, ParameterType.UrlSegment); request.AddParameter("root", root, ParameterType.UrlSegment); + if (list) + { + request.AddParameter("hash", hash); + request.AddParameter("list", list.ToString().ToLower()); + request.AddParameter("include_deleted", include_deleted.ToString().ToLower()); + } + return request; }