Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Unified MetaData methods, added optional parameters 'hash', 'list' an…
Browse files Browse the repository at this point in the history
…d 'include_deleted'.
  • Loading branch information
partyz0ne committed Mar 3, 2015
1 parent 7479ac0 commit ba2623f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
17 changes: 4 additions & 13 deletions DropNet/Client/Files.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ namespace DropNet
{
public partial class DropNetClient
{
public void GetMetaDataAsync(string path, Action<MetaData> success, Action<DropboxException> failure)
public void GetMetaDataAsync(Action<MetaData> success, Action<DropboxException> 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<MetaData> success, Action<DropboxException> failure)
public void GetMetaDataAsync(String path, Action<MetaData> success, Action<DropboxException> 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);
}
Expand Down
8 changes: 4 additions & 4 deletions DropNet/Client/Files.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetaData>(ApiType.Base, request);
}
Expand Down
17 changes: 4 additions & 13 deletions DropNet/Client/Files.Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,16 @@ namespace DropNet
{
public partial class DropNetClient
{
public Task<MetaData> GetMetaDataTask(string path)
public Task<MetaData> GetMetaDataTask(String hash, Boolean list, Boolean include_deleted)
{
if (!string.IsNullOrEmpty(path) && !path.StartsWith("/"))
{
path = "/" + path;
}

var request = _requestHelper.CreateMetadataRequest(path, Root);

return ExecuteTask<MetaData>(ApiType.Base, request);
return GetMetaDataTask(String.Empty, hash, list, include_deleted);
}

public Task<MetaData> GetMetaDataTask(string path, string hash)
public Task<MetaData> 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<MetaData>(ApiType.Base, request);
}
Expand Down
22 changes: 13 additions & 9 deletions DropNet/Client/IDropNetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,21 @@ public interface IDropNetClient
string BuildAuthorizeUrl(OAuth2AuthorizationFlow oAuth2AuthorizationFlow, string redirectUri, string state = null);

/// <summary>
/// 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.
/// </summary>
/// <param name="path">The path of the file or folder</param>
/// <param name="success">Success call back</param>
/// <param name="failure">Failure call back </param>
void GetMetaDataAsync(string path, Action<MetaData> success, Action<DropboxException> failure);
void GetMetaDataAsync(Action<MetaData> success, Action<DropboxException> failure, String hash = null, Boolean list = false, Boolean include_deleted = false);

/// <summary>
/// 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.
/// </summary>
/// <param name="path">The path of the file or folder</param>
/// <param name="hash">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.</param>
/// <param name="success">Success callback </param>
/// <param name="failure">Failure callback </param>
void GetMetaDataAsync(string path, string hash, Action<MetaData> success, Action<DropboxException> failure);
void GetMetaDataAsync(String path, Action<MetaData> success, Action<DropboxException> failure, String hash = null, Boolean list = false, Boolean include_deleted = false);

/// <summary>
/// Gets list of metadata for search string
Expand Down Expand Up @@ -326,8 +324,8 @@ public interface IDropNetClient
/// <param name="failure">Failure callback </param>
void GetCopyRefAsync(string path, Action<CopyRefResponse> success, Action<DropboxException> failure);

Task<MetaData> GetMetaDataTask(string path);
Task<MetaData> GetMetaDataTask(string path, string hash);
Task<MetaData> GetMetaDataTask(String hash = null, Boolean list = false, Boolean include_deleted = false);
Task<MetaData> GetMetaDataTask(String path, String hash = null, Boolean list = false, Boolean include_deleted = false);
Task<List<MetaData>> SearchTask(string searchString);
Task<List<MetaData>> SearchTask(string searchString, int fileLimit);
Task<List<MetaData>> SearchTask(string searchString, string path);
Expand All @@ -352,15 +350,21 @@ public interface IDropNetClient
/// <summary>
/// Gets MetaData for the root folder.
/// </summary>
/// <param name="hash">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.</param>
/// <param name="list">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.</param>
/// <param name="include_deleted">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.</param>
/// <returns></returns>
MetaData GetMetaData();
MetaData GetMetaData(String hash = null, Boolean list = false, Boolean include_deleted = false);

/// <summary>
/// Gets MetaData for a File or Folder. For a folder this includes its contents. For a file, this includes details such as file size.
/// </summary>
/// <param name="path">The path of the file or folder</param>
/// <param name="hash">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.</param>
/// <param name="list">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.</param>
/// <param name="include_deleted">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.</param>
/// <returns></returns>
MetaData GetMetaData(string path);
MetaData GetMetaData(String path, String hash = null, Boolean list = false, Boolean include_deleted = false);

/// <summary>
/// Gets List of MetaData for a File versions. Each metadata item contains info about file in certain version on Dropbox.
Expand Down
9 changes: 8 additions & 1 deletion DropNet/Helpers/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ 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}";
request.AddParameter("version", _version, ParameterType.UrlSegment);
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;
}

Expand Down

0 comments on commit ba2623f

Please sign in to comment.