/// <summary> /// Builds up the oauth parameters and updated the request Uri /// </summary> /// <param name="request"></param> /// <returns></returns> public HttpRequest Authenticate(HttpRequest request) { request.AddParameter("oauth_version", "1.0"); request.AddParameter("oauth_nonce", GenerateNonce()); request.AddParameter("oauth_timestamp", GenerateTimeStamp()); request.AddParameter("oauth_signature_method", SignatureMethod); request.AddParameter("oauth_consumer_key", ApiKey); if (!string.IsNullOrEmpty(UserToken)) { request.AddParameter("oauth_token", UserToken); } request.Parameters.Sort(new QueryParameterComparer()); request.AddParameter("oauth_signature", GenerateSignature(request)); //Now build the real Url var data = EncodeParameters(request); var url = string.Format("{0}?{1}", request.RequestUri, data); request.RequestUri = new Uri(url); //Does it need to do this? return request; }
/// <summary> /// Gets the deltas for a user's folders and files. /// </summary> /// <param name="cursor">The value returned from the prior call to GetDelta or an empty string</param> /// <returns></returns> public async Task<DeltaPage> GetDelta(string cursor) { var requestUrl = MakeRequestString("1/delta", ApiType.Base); var request = new HttpRequest(HttpMethod.Post, requestUrl); request.AddParameter("cursor", cursor); _oauthHandler.Authenticate(request); var response = await _httpClient.SendAsync(request); //TODO - Error Handling string responseBody = await response.Content.ReadAsStringAsync(); var deltaResponse = JsonConvert.DeserializeObject<DeltaPageInternal>(responseBody); var deltaPage = new DeltaPage { Cursor = deltaResponse.Cursor, Has_More = deltaResponse.Has_More, Reset = deltaResponse.Reset, Entries = new List<DeltaEntry>() }; foreach (var stringList in deltaResponse.Entries) { deltaPage.Entries.Add(StringListToDeltaEntry(stringList)); } return deltaPage; }
/// <summary> /// Created a new folder with the given path /// </summary> /// <param name="path"></param> /// <returns></returns> public async Task<MetaData> CreateFolder(string path) { var requestUrl = MakeRequestString("1/fileops/create_folder", ApiType.Base); var request = new HttpRequest(HttpMethod.Get, requestUrl); request.AddParameter("path", path); request.AddParameter("root", Root); var response = await SendAsync<MetaData>(request); return response; }
/// <summary> /// Gets the thumbnail of an image given its path /// </summary> /// <param name="path"></param> /// <param name="size"></param> /// <returns></returns> public async Task<byte[]> GetThumbnail(string path, ThumbnailSize size) { var requestUrl = MakeRequestString(string.Format("1/thumbnails/{0}/{1}", Root, path.CleanPath()), ApiType.Content); var request = new HttpRequest(HttpMethod.Get, requestUrl); request.AddParameter("size", ThumbnailSizeString(size)); _oauthHandler.Authenticate(request); var response = await _httpClient.SendAsync(request); //TODO - Error Handling return await response.Content.ReadAsByteArrayAsync(); }
/// <summary> /// Moves a file or folder on Dropbox /// </summary> /// <param name="fromPath"></param> /// <param name="toPath"></param> /// <returns></returns> public async Task<MetaData> Move(string fromPath, string toPath) { var requestUrl = MakeRequestString("1/fileops/move", ApiType.Base); var request = new HttpRequest(HttpMethod.Get, requestUrl); request.AddParameter("from_path", fromPath); request.AddParameter("to_path", toPath); request.AddParameter("root", Root); var response = await SendAsync<MetaData>(request); return response; }