huge work for nextcloud api
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Model.Apps.FilesRetention;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.APIs.Apps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps
|
||||
{
|
||||
public class FilesRetentionClient : ClientBase
|
||||
{
|
||||
public FilesRetentionClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<bool> CreateRetentionRule(RetentionRule rule)
|
||||
{
|
||||
var entry = rule.ToOcsData();
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().CreateRetentionRule(entry);
|
||||
}
|
||||
|
||||
public Task<bool> DeleteRetentionRule(int ruleID)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().DeleteRetentionRule(ruleID);
|
||||
}
|
||||
|
||||
public async Task<RetentionRule[]?> GetRetentionRules()
|
||||
{
|
||||
var api = Client.Ocs.GetApi<OcsApiFilesRetention>();
|
||||
var response = await api.GetRetentionRules();
|
||||
|
||||
if (response?.Data is not null)
|
||||
{
|
||||
var rules = new List<RetentionRule>();
|
||||
|
||||
foreach (var entry in response.Data)
|
||||
rules.Add(new RetentionRule(entry));
|
||||
|
||||
return rules.ToArray();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client
|
||||
{
|
||||
public abstract class ClientBase
|
||||
{
|
||||
public NextcloudClient Client { get; init; }
|
||||
|
||||
public ClientBase(NextcloudClient client)
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Model.Cloud;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client
|
||||
{
|
||||
public class CloudClient : ClientBase
|
||||
{
|
||||
public CloudClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<UserInfo?> GetUserInfo()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Client.CurrentLogin?.LoginName))
|
||||
return GetUserInfo(Client.CurrentLogin.LoginName);
|
||||
else
|
||||
return Task.FromResult<UserInfo?>(null);
|
||||
}
|
||||
|
||||
public async Task<UserInfo?> GetUserInfo(string username)
|
||||
{
|
||||
var result = await Client.Ocs.Cloud.GetUserMeta(username);
|
||||
|
||||
if (result?.Data != null)
|
||||
return new UserInfo(result.Data);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user