/// <summary> /// Gets all shares for the current user when <c>path</c> is not set, otherwise it gets shares for the specific file or folder /// </summary> /// <returns>array of shares or empty array if the operation failed.</returns> /// <param name="path">(optional) path to the share to be checked.</param> /// <param name="reshares">(optional) returns not only the shares from the current user but all shares from the given file.</param> /// <param name="subfiles">(optional) returns all shares within a folder, given that path defines a folder.</param> public List<Share> GetShares(string path, OcsBoolParam reshares = OcsBoolParam.None, OcsBoolParam subfiles = OcsBoolParam.None) { var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares") , Method.GET); request.AddHeader("OCS-APIREQUEST", "true"); if ((path != null) && (!path.Equals(""))) request.AddQueryParameter("path", path); if (reshares == OcsBoolParam.True) request.AddQueryParameter("reshares", "true"); else if (reshares == OcsBoolParam.False) request.AddQueryParameter("reshares", "false"); if (subfiles == OcsBoolParam.True) request.AddQueryParameter("subfiles", "true"); else if (subfiles == OcsBoolParam.False) request.AddQueryParameter("subfiles", "false"); var response = rest.Execute (request); CheckOcsStatus (response); return GetShareList (response.Content); }
/// <summary> /// Shares a remote file with link. /// </summary> /// <returns>instance of PublicShare with the share info.</returns> /// <param name="path">path to the remote file to share.</param> /// <param name="perms">(optional) permission of the shared object.</param> /// <param name="password">(optional) sets a password.</param> /// <param name="public_upload">(optional) allows users to upload files or folders.</param> public PublicShare ShareWithLink(string path, int perms = -1, string password = null, OcsBoolParam public_upload = OcsBoolParam.None) { var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares"), Method.POST); request.AddHeader("OCS-APIREQUEST", "true"); request.AddParameter ("shareType", Convert.ToInt32 (OcsShareType.Link)); request.AddParameter ("path", path); if (perms != Convert.ToInt32(OcsPermission.None)) request.AddParameter("permissions", Convert.ToInt32(perms) + ""); if (password != null) request.AddParameter ("password", password); if (public_upload == OcsBoolParam.True) request.AddParameter ("publicUpload", "true"); else if (public_upload == OcsBoolParam.False) request.AddParameter ("publicUpload", "false"); var response = rest.Execute (request); CheckOcsStatus (response); PublicShare share = new PublicShare (); share.ShareId = Convert.ToInt32(GetFromData(response.Content, "id")); share.Url = GetFromData(response.Content, "url"); share.Token = GetFromData(response.Content, "token"); share.TargetPath = path; share.Perms = (perms > -1) ? perms : Convert.ToInt32(OcsPermission.Read); return share; }
/// <summary> /// Shares a remote file with specified user. /// </summary> /// <returns>instance of UserShare with the share info.</returns> /// <param name="path">path to the remote file to share.</param> /// <param name="username">name of the user whom we want to share a file/folder.</param> /// <param name="perms">permissions of the shared object.</param> /// <param name="remoteUser">Remote user.</param> public UserShare ShareWithUser(string path, string username, int perms = -1, OcsBoolParam remoteUser = OcsBoolParam.None) { if ((perms == -1) || (perms > Convert.ToInt32 (OcsPermission.All)) || (username == null) || (username.Equals (""))) return null; var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares"), Method.POST); request.AddHeader("OCS-APIREQUEST", "true"); if (remoteUser == OcsBoolParam.True) request.AddParameter ("shareType", Convert.ToInt32 (OcsShareType.Remote)); else request.AddParameter ("shareType", Convert.ToInt32 (OcsShareType.User)); request.AddParameter ("path", path); if (perms != Convert.ToInt32(OcsPermission.None)) request.AddParameter("permissions", perms + ""); else request.AddParameter("permissions", Convert.ToInt32(OcsPermission.Read) + ""); request.AddParameter ("shareWith", username); var response = rest.Execute (request); CheckOcsStatus (response); var share = new UserShare(); share.ShareId = Convert.ToInt32(GetFromData(response.Content, "id")); share.TargetPath = path; share.Perms = perms; share.SharedWith = username; return share; }
/// <summary> /// Updates a given share. NOTE: Only one of the update parameters can be specified at once. /// </summary> /// <returns><c>true</c>, if share was updated, <c>false</c> otherwise.</returns> /// <param name="shareId">Share identifier.</param> /// <param name="perms">(optional) update permissions.</param> /// <param name="password">(optional) updated password for public link Share.</param> /// <param name="public_upload">(optional) If set to <c>true</c> enables public upload for public shares.</param> public bool UpdateShare(int shareId, int perms = -1, string password = null, OcsBoolParam public_upload = OcsBoolParam.None) { if ((perms == Convert.ToInt32(OcsPermission.None)) && (password == null) && (public_upload == OcsBoolParam.None)) return false; var request = new RestRequest(GetOcsPath(ocsServiceShare, "shares") + "/{id}", Method.PUT); request.AddUrlSegment("id", "" + shareId); request.AddHeader("OCS-APIREQUEST", "true"); if (perms != Convert.ToInt32(OcsPermission.None)) request.AddQueryParameter ("permissions", Convert.ToInt32(perms) + ""); if (password != null) request.AddQueryParameter ("password", password); if (public_upload == OcsBoolParam.True) request.AddQueryParameter ("publicUpload", "true"); else if (public_upload == OcsBoolParam.False) request.AddQueryParameter ("publicUpload", "false"); var response = rest.Execute<OCS>(request); if (response.Data != null) { if (response.Data.Meta.StatusCode == 100) return true; else throw new OCSResponseError (response.Data.Meta.Message, response.Data.Meta.StatusCode + ""); } return false; }