public IRestApiType GetFiles() { try { RestApiHelper client = new RestApiHelper() { EndPoint = _GETUri, Method = RestApiHelper.HttpVerb.GET, GrantedToken = this.GrantedToken, Parameters = "?list=true" }; var json = client.SendRequest(); var obj = JsonHelper.ParseJson<DropboxRestApiType.File>(json); // Convert DropboxRest File.Contents type to RestApi.Files type (IRestApiType) Files files = new Files(); foreach (var f in obj.Contents) { files.files.Add( new RestApi.File() { id = f.Revision, filename = f.Path.Replace("/", ""), path = f.Path, size = f.Size } ); } return files; } catch (Exception ex) { throw new Exception("Fail to get all documents, error: " + ExceptionHelper.ExtractAll(ex)); } }
public ExactRestApiTypes.Documents GetDocuments() { try { RestApiHelper client = new RestApiHelper() { EndPoint = _GETUri, Method = RestApiHelper.HttpVerb.GET, GrantedToken = GrantedToken, Parameters = "?$select=ID,Subject,DocumentDate,Type,AccountName,Category,CategoryDescription" }; var json = client.SendRequest(); var obj = JsonHelper.ParseJson<ExactRestApiTypes.Root>(json); return obj.Documents; } catch (Exception ex) { throw new Exception("Fail to get all documents, error: " + ExceptionHelper.ExtractAll(ex)); } }
public ExactRestApiTypes.Document PostDocument(ExactRestApiTypes.Document doc) { try { string jsonPost = "{Subject : '" + doc.Subject + "',Type : 55,Category : '3b6d3833-b31b-423d-bc3c-39c62b8f2b12'}"; RestApiHelper client = new RestApiHelper() { EndPoint = _POSTUri, Method = RestApiHelper.HttpVerb.POST, GrantedToken = GrantedToken, Parameters = "", PostData = jsonPost }; var json = client.SendRequest(); var obj = JsonHelper.ParseJson<ExactRestApiTypes.Root_SingleDocument>(json); return obj.Document; } catch (Exception ex) { throw new Exception("Fail to post the document, error: " + ExceptionHelper.ExtractAll(ex)); } }
public string PostDocumentAttachment(string id, string filename, byte[] source) { try { string base64String = Convert.ToBase64String(source, 0, source.Length); string jsonPost = "{Attachment : " + base64String + ",Document : '" + id + "',FileName : '" + filename + "'}"; RestApiHelper client = new RestApiHelper() { EndPoint = _UploadUri, Method = RestApiHelper.HttpVerb.POST, GrantedToken = GrantedToken, Parameters = "", PostData = jsonPost }; var json = client.SendRequest(); return json; } catch (Exception ex) { throw new Exception("Fail to upload the attachment, error: " + ExceptionHelper.ExtractAll(ex)); } }
public byte[] DownloadFile(string path) { try { RestApiHelper client = new RestApiHelper() { EndPoint = _DownloadFileUri + path, Method = RestApiHelper.HttpVerb.GET, GrantedToken = this.GrantedToken }; path = path.Replace("/", "\\"); var filebytes = client.DownloadFile(); return filebytes; } catch (Exception ex) { throw new Exception("Fail to download the file, error: " + ExceptionHelper.ExtractAll(ex)); } }