more work on api & rename to Pilz.Net

This commit is contained in:
Pilzinsel64
2024-08-16 06:59:39 +02:00
parent f57aef5f4f
commit 2efb4f141c
91 changed files with 299 additions and 241 deletions

View File

@@ -0,0 +1,41 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention;
public class FilesRetentionClient : ClientBase
{
public FilesRetentionClient(NextcloudClient client) : base(client)
{
}
public bool CreateRetentionRule(RetentionRuleInfo rule)
{
var entry = rule.ToOcsData();
return Client.Ocs.GetApi<OcsApiFilesRetention>().CreateRetentionRule(entry);
}
public bool DeleteRetentionRule(int ruleID)
{
return Client.Ocs.GetApi<OcsApiFilesRetention>().DeleteRetentionRule(ruleID);
}
public RetentionRule[]? GetRetentionRules()
{
var api = Client.Ocs.GetApi<OcsApiFilesRetention>();
var response = 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;
}
}

View File

@@ -0,0 +1,30 @@
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public class RetentionRule : RetentionRuleInfo
{
/// <summary>
/// The ID for the retention rule.
/// </summary>
public int ID { get; init; }
/// <summary>
/// Defines if a background job has been generated
/// </summary>
public bool HasJob { get; init; }
public RetentionRule()
{
}
public RetentionRule(OcsResponseDataEntryRetention data)
{
ID = data.ID ?? -1;
TagID = data.TagID ?? -1;
TimeUnit = (RetentionTimeUnit)(data.TimeUnit ?? 0);
TimeAmount = data.TimeAmount ?? -1;
TimeAfter = (RetentionTimeAfter)(data.TimeAfter ?? 0);
HasJob = data.HasJob ?? false;
}
}

View File

@@ -0,0 +1,37 @@
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public class RetentionRuleInfo
{
/// <summary>
/// The ID for the tag that is used for this rule.
/// </summary>
public int TagID { get; init; }
/// <summary>
/// The unit used for the time.
/// </summary>
public RetentionTimeUnit TimeUnit { get; init; }
/// <summary>
/// Represents numer of days/weeks/months/years.
/// </summary>
public int TimeAmount { get; init; }
/// <summary>
/// The time used for the rule.
/// </summary>
public RetentionTimeAfter TimeAfter { get; init; }
public OcsDataRetentionRule ToOcsData()
{
return new OcsDataRetentionRule
{
TagID = TagID,
TimeUnit = (int)TimeUnit,
TimeAmount = TimeAmount,
TimeAfter = (int)TimeAfter
};
}
}

View File

@@ -0,0 +1,7 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeAfter
{
CreationDate,
LastAccess
}

View File

@@ -0,0 +1,9 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
public enum RetentionTimeUnit
{
Day,
Week,
Month,
Year
}

View File

@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsDataRetentionRule : OcsData
{
[JsonProperty("tagid")]
public int? TagID { get; set; }
[JsonProperty("timeunit")]
public int? TimeUnit { get; set; }
[JsonProperty("timeamount")]
public int? TimeAmount { get; set; }
[JsonProperty("timeafter")]
public int? TimeAfter { get; set; }
}

View File

@@ -0,0 +1,25 @@
using Newtonsoft.Json;
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsResponseDataEntryRetention : OcsResponseDataEntry
{
[JsonProperty("id")]
public int? ID { get; set; }
[JsonProperty("tagid")]
public int? TagID { get; set; }
[JsonProperty("timeunit")]
public int? TimeUnit { get; set; }
[JsonProperty("timeamount")]
public int? TimeAmount { get; set; }
[JsonProperty("timeafter")]
public int? TimeAfter { get; set; }
[JsonProperty("hasJob")]
public bool? HasJob { get; set; }
}

View File

@@ -0,0 +1,7 @@
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
{
}

View File

@@ -0,0 +1,32 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.FileRetention;
public class OcsApiFilesRetention : OcsApiBase
{
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULES = new("/ocs/v2.php/apps/files_retention/api/v1/retentions");
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULE = new("/ocs/v2.php/apps/files_retention/api/v1/retentions/{0}");
public OcsApiFilesRetention(OcsApi manager) : base(manager)
{
}
public bool CreateRetentionRule(OcsDataRetentionRule rule)
{
var response = Manager.MakeRequest(HttpMethod.Post, OCS_FILE_RETENTION_RULES, content: rule);
return response.IsSuccessStatusCode;
}
public bool DeleteRetentionRule(int ruleID)
{
var response = Manager.MakeRequest(HttpMethod.Delete, OCS_FILE_RETENTION_RULE.FillParameters(ruleID));
return response.IsSuccessStatusCode;
}
public OcsResponseRetention? GetRetentionRules()
{
return Manager.MakeRequestOcs<OcsResponseRetention>(HttpMethod.Get, OCS_FILE_RETENTION_RULES);
}
}

View File

@@ -0,0 +1,110 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Column
{
[JsonProperty("type")]
private string? type;
[JsonProperty("subtype")]
private string? subtype;
[JsonProperty("id")]
public long ColumnId { get; set; }
[JsonProperty("tableId")]
public long TableId { get; set; }
[JsonProperty("title")]
public string? Title { get; set; }
[JsonProperty("createdBy")]
public string? CreatedBy { get; set; }
[JsonProperty("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonProperty("lastEditBy")]
public string? LastEditBy { get; set; }
[JsonProperty("lastEditAt")]
public DateTime LastEditAt { get; set; }
[JsonProperty("mandatory")]
public bool Mandatory { get; set; }
[JsonProperty("description")]
public string? Description { get; set; }
[JsonProperty("numberDefault")]
public float? NumberDefault { get; set; }
[JsonProperty("numberMin")]
public float? NumberMin { get; set; }
[JsonProperty("numberMax")]
public float? NumberMax { get; set; }
[JsonProperty("numberDecimals")]
public float NumberDecimals { get; set; }
[JsonProperty("numberPrefix")]
public string? NumberPrefix { get; set; }
[JsonProperty("numberSuffix")]
public string? NumberSuffix { get; set; }
[JsonProperty("textDefault")]
public string? TextDefault { get; set; }
[JsonProperty("textAllowedPattern")]
public string? TextAllowedPattern { get; set; }
[JsonProperty("textMaxLength")]
public int? TextMaxLength { get; set; }
[JsonProperty("selectionOptions")]
public List<ColumnSelectionOption> SelectionOptions { get; } = new();
[JsonProperty("selectionDefault")]
public int? SelectionDefault { get; set; }
[JsonProperty("datetimeDefault")]
public DateTime? DatetimeDefault { get; set; }
[JsonIgnore]
public ColumnType Type
{
get => type switch
{
"text" => ColumnType.Text,
"selection" => ColumnType.Selection,
"datetime" => ColumnType.DateTime,
_ => ColumnType.Unknown,
};
set => type = value switch
{
ColumnType.Text => "text",
ColumnType.Selection => "selection",
ColumnType.DateTime => "datetime",
_ => "text"
};
}
[JsonIgnore]
public ColumnSubtype Subtype
{
get => subtype switch
{
"line" => ColumnSubtype.Line,
"" => ColumnSubtype.None,
_ => ColumnSubtype.Unknown,
};
set => subtype = value switch
{
ColumnSubtype.Line => "line",
_ => ""
};
}
}

View File

@@ -0,0 +1,12 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class ColumnSelectionOption
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("label")]
public string? Label { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnSubtype
{
None,
Unknown,
Line
}

View File

@@ -0,0 +1,9 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public enum ColumnType
{
Unknown,
Text,
Selection,
DateTime
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Columns : List<Column>
{
}

View File

@@ -0,0 +1,27 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Row
{
[JsonProperty("id")]
public long RowId { get; set; } = -1;
[JsonProperty("tableId")]
public long TableId { get; set; } = -1;
[JsonProperty("createdBy")]
public string? CreatedBy { get; set; }
[JsonProperty("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonProperty("lastEditBy")]
public string? LastEditBy { get; set; }
[JsonProperty("lastEditAt")]
public DateTime LastEditAt { get; set; }
[JsonProperty("data")]
public List<RowData> Data { get; set; } = new();
}

View File

@@ -0,0 +1,12 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowData
{
[JsonProperty("columnId")]
public long ColumnId { get; set; }
[JsonProperty("value")]
public object? Value { get; set; }
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowSimple : List<object>
{
}

View File

@@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowUpdate
{
[JsonProperty("data")]
public Dictionary<long, object?> Data { get; set; } = new();
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class Rows : List<Row>
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
public class RowsSimple : List<RowSimple>
{
}

View File

@@ -0,0 +1,80 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables;
public class OcsApiTables : OcsApiBase
{
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS = new("/apps/tables/api/1/tables/{0}/rows");
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_ROWS = new("/apps/tables/api/1/views/{0}/rows");
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS_SIMPLE = new("/apps/tables/api/1/tables/{0}/rows/simple");
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_COLUMNS = new("/apps/tables/api/1/tables/{0}/columns");
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_COLUMNS = new("/apps/tables/api/1/views/{0}/columns");
public static readonly OcsApiUrlPath OCS_TABLES_ROW = new("/apps/tables/api/1/rows/{0}");
public static readonly OcsApiUrlPath OCS_TABLES_COLUMN = new("/apps/tables/api/1/column/{0}");
public OcsApiTables(OcsApi manager) : base(manager)
{
}
public RowsSimple? GetRowsSimple(long tableId)
{
return Manager.MakeRequest<RowsSimple>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS_SIMPLE.FillParameters(tableId));
}
public Rows? GetRows(long tableId)
{
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS.FillParameters(tableId));
}
public Rows? GetViewRows(long viewId)
{
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_VIEW_ROWS.FillParameters(viewId));
}
public Row? GetRow(long rowId)
{
return Manager.MakeRequest<Row>(HttpMethod.Get, OCS_TABLES_ROW.FillParameters(rowId));
}
public Columns? GetColumns(long tableId)
{
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_TABLE_COLUMNS.FillParameters(tableId));
}
public Columns? GetViewColumns(long viewId)
{
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_VIEW_COLUMNS.FillParameters(viewId));
}
public Column? GetColumn(long columnId)
{
return Manager.MakeRequest<Column>(HttpMethod.Get, OCS_TABLES_COLUMN.FillParameters(columnId));
}
public Row? DeleteRow(long rowId)
{
return Manager.MakeRequest<Row>(HttpMethod.Delete, OCS_TABLES_ROW.FillParameters(rowId));
}
public Column? DeleteColumn(long columnId)
{
return Manager.MakeRequest<Column>(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId));
}
public Row? UpdateRow(long rowId, RowUpdate values)
{
return Manager.MakeRequest<Row>(HttpMethod.Put, OCS_TABLES_ROW.FillParameters(rowId), content: values);
}
public Row? CreateRow(long tableId, RowUpdate values)
{
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_TABLE_ROWS.FillParameters(tableId), content: values);
}
public Row? CreateViewRow(long viewId, RowUpdate values)
{
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_VIEW_ROWS.FillParameters(viewId), content: values);
}
}

View File

@@ -0,0 +1,77 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Apps.Tables;
public class TablesClient : ClientBase
{
public TablesClient(NextcloudClient client) : base(client)
{
}
public RowsSimple? GetRowsSimple(long tableId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetRowsSimple(tableId);
}
public Rows? GetRows(long tableId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetRows(tableId);
}
public Rows? GetViewRows(long viewId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetViewRows(viewId);
}
public Row? GetRow(long rowId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetRow(rowId);
}
public Columns? GetColumns(long tableId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetColumns(tableId);
}
public Columns? GetViewColumns(long viewId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetViewColumns(viewId);
}
public Column? GetColumn(long columnId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetColumn(columnId);
}
public bool DeleteRow(long rowId)
{
return DeleteRowAdv(rowId) is not null;
}
public Row? DeleteRowAdv(long rowId)
{
return Client.Ocs.GetApi<OcsApiTables>().DeleteRow(rowId);
}
public bool DeleteColumn(long columnId)
{
return DeleteColumnAdv(columnId) is not null;
}
public Column? DeleteColumnAdv(long columnId)
{
return Client.Ocs.GetApi<OcsApiTables>().DeleteColumn(columnId);
}
public Row? UpdateRow(long rowId, RowUpdate values)
{
return Client.Ocs.GetApi<OcsApiTables>().UpdateRow(rowId, values);
}
public Row? CreateRow(long tableId, RowUpdate values)
{
return Client.Ocs.GetApi<OcsApiTables>().CreateRow(tableId, values);
}
}

View File

@@ -0,0 +1,22 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client;
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
namespace Pilz.Networking.CloudProviders.Nextcloud.Client
{
public abstract class ClientBase
Nach:
namespace Pilz.Networking.CloudProviders.Nextcloud.Client;
public abstract class ClientBase
*/
public abstract class ClientBase
{
protected NextcloudClient Client { get; init; }
protected ClientBase(NextcloudClient client)
{
Client = client;
}
}

View File

@@ -0,0 +1,29 @@
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
public class CloudClient : ClientBase
{
public CloudClient(NextcloudClient client) : base(client)
{
}
public UserInfo? GetUserInfo()
{
if (!string.IsNullOrEmpty(Client.CurrentLogin?.LoginName))
return GetUserInfo(Client.CurrentLogin.LoginName);
else
return null;
}
public UserInfo? GetUserInfo(string username)
{
var result = Client.Ocs.Cloud.GetUserMeta(username);
if (result?.Data != null)
return new UserInfo(result.Data);
return null;
}
}

View File

@@ -0,0 +1,14 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserBackendCapabilities
{
/// <summary>
/// Defines if the display name can be changed.
/// </summary>
public bool SetDisplayName { get; set; }
/// <summary>
/// Defines if the password can be changed.
/// </summary>
public bool SetPassword { get; set; }
}

View File

@@ -0,0 +1,126 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserInfo
{
/// <summary>
/// Defines if the user is enabled.
/// </summary>
public bool Enabled { get; init; }
/// <summary>
/// The location of the user's storage directory.
/// </summary>
public string? StorageLocation { get; init; }
/// <summary>
/// The uniquie user id that infos are for.
/// </summary>
public string? ID { get; init; }
/// <summary>
/// The last time when the user has logged in to its account.
/// </summary>
public DateTime LastLogin { get; init; }
/// <summary>
/// The backend of the user. Common values are "Database" or "LDAP".
/// </summary>
public string? Backend { get; init; }
/// <summary>
/// The Email address of the user.
/// </summary>
public string? Email { get; init; }
/// <summary>
/// The displayname of the user.
/// </summary>
public string? Displayname { get; init; }
/// <summary>
/// The displayname of the user.
/// </summary>
public string? Displayname2 { get; init; }
/// <summary>
/// The phone number of the user.
/// </summary>
public string? Phone { get; init; }
/// <summary>
/// The address of the user.
/// </summary>
public string? Address { get; init; }
/// <summary>
/// The Website of the user.
/// </summary>
public string? Website { get; init; }
/// <summary>
/// The twitter profile name of the user.
/// </summary>
public string? Twitter { get; init; }
/// <summary>
/// Defines the groups the user is member of.
/// </summary>
public string[] Groups { get; init; }
/// <summary>
/// The configured language of the user.
/// </summary>
public string? Language { get; init; }
/// <summary>
/// The configured location of the user.
/// </summary>
public string? Locale { get; init; }
/// <summary>
/// Quota informations for the user.
/// </summary>
public UserQuota Quota { get; } = new();
/// <summary>
/// Backend capabilities of the user.
/// </summary>
public UserBackendCapabilities BackendCapabilities { get; } = new();
public UserInfo(OcsResponseDataUser responseData)
{
Enabled = Convert.ToBoolean(responseData.Enabled);
StorageLocation = responseData.StorageLocation;
ID = responseData.ID;
LastLogin = responseData.LastLogin.UnixTimeMillisecondsToDateTime();
Backend = responseData.Backend;
Email = responseData.Email;
Displayname = responseData.Displayname;
Displayname2 = responseData.Displayname2;
Phone = responseData.Phone;
Address = responseData.Address;
Website = responseData.Website;
Twitter = responseData.Twitter;
Groups = responseData.Groups ?? Array.Empty<string>();
Language = responseData.Language;
Locale = responseData.Locale;
if (responseData.Quota != null)
{
Quota.Free = responseData.Quota.Free ?? 0;
Quota.Used = responseData.Quota.Used ?? 0;
Quota.Total = responseData.Quota.Total ?? 0;
Quota.Relative = responseData.Quota.Relative ?? 0.0F;
Quota.Quota = responseData.Quota.Quota ?? 0;
}
if (responseData.BackendCapabilities != null)
{
BackendCapabilities.SetDisplayName = Convert.ToBoolean(responseData.BackendCapabilities.SetDisplayName);
BackendCapabilities.SetPassword = Convert.ToBoolean(responseData.BackendCapabilities.SetPassword);
}
}
}

View File

@@ -0,0 +1,29 @@
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
public class UserQuota
{
/// <summary>
/// Amount of free bytes left.
/// </summary>
public long Free { get; set; }
/// <summary>
/// Amount of already used bytes.
/// </summary>
public long Used { get; set; }
/// <summary>
/// Total amount of all bytes (free + used).
/// </summary>
public long Total { get; set; }
/// <summary>
/// Relative amount of used quota in percent.
/// </summary>
public float Relative { get; set; }
/// <summary>
/// Total amount of bytes available.
/// </summary>
public long Quota { get; set; }
}

View File

@@ -0,0 +1,85 @@
using Newtonsoft.Json;
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
public class OcsResponseDataUser : OcsResponseData
{
public class ResponseQuota
{
[JsonProperty("free")]
public long? Free { get; set; }
[JsonProperty("used")]
public long? Used { get; set; }
[JsonProperty("total")]
public long? Total { get; set; }
[JsonProperty("relative")]
public float? Relative { get; set; }
[JsonProperty("quota")]
public long? Quota { get; set; }
}
public class ResponseBackendCapabilities
{
[JsonProperty("setDisplayName")]
public bool? SetDisplayName { get; set; }
[JsonProperty("setPassword")]
public bool? SetPassword { get; set; }
}
[JsonProperty("enabled")]
public bool? Enabled { get; set; }
[JsonProperty("storageLocation")]
public string? StorageLocation { get; set; }
[JsonProperty("id")]
public string? ID { get; set; }
[JsonProperty("lastLogin")]
public long? LastLogin { get; set; }
[JsonProperty("backend")]
public string? Backend { get; set; }
[JsonProperty("quota")]
public ResponseQuota? Quota { get; set; }
[JsonProperty("email")]
public string? Email { get; set; }
[JsonProperty("displayname")]
public string? Displayname { get; set; }
[JsonProperty("display-name")]
public string? Displayname2 { get; set; }
[JsonProperty("phone")]
public string? Phone { get; set; }
[JsonProperty("address")]
public string? Address { get; set; }
[JsonProperty("website")]
public string? Website { get; set; }
[JsonProperty("twitter")]
public string? Twitter { get; set; }
[JsonProperty("groups")]
public string[]? Groups { get; set; }
[JsonProperty("language")]
public string? Language { get; set; }
[JsonProperty("locale")]
public string? Locale { get; set; }
[JsonProperty("backendCapabilities")]
public ResponseBackendCapabilities? BackendCapabilities { get; set; }
}

View File

@@ -0,0 +1,7 @@
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
{
}

View File

@@ -0,0 +1,19 @@
using Pilz.Net.CloudProviders.Nextcloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
public class OcsApiCloud : OcsApiBase
{
public readonly static OcsApiUrlPath OCS_CLOUD_USER_METADATA = new("/ocs/v1.php/cloud/users/{0}");
public OcsApiCloud(OcsApi manager) : base(manager)
{
}
public OcsResponseUser? GetUserMeta(string username)
{
return Manager.MakeRequestOcs<OcsResponseUser>(HttpMethod.Get, OCS_CLOUD_USER_METADATA.FillParameters(username));
}
}

View File

@@ -0,0 +1,26 @@
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
using System;
Nach:
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
using System;
*/
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.Core;
public class OcsApiCore : OcsApiBase
{
public static readonly OcsApiUrlPath OCS_CORE_APPPASSWORD = "/ocs/v2.php/core/apppassword";
public OcsApiCore(OcsApi manager) : base(manager)
{
}
public bool DeleteAppPassword()
{
using var msg = Manager.MakeRequest(HttpMethod.Delete, OCS_CORE_APPPASSWORD);
return msg != null && msg.IsSuccessStatusCode;
}
}

View File

@@ -0,0 +1,34 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
public class OcsResponseLoginFlowV2
{
public class PollData
{
/// <summary>
/// The login token that has been created for the login process.
/// It can be used to poll the login state.
/// </summary>
[JsonProperty("token")]
public string? Token { get; set; }
/// <summary>
///
/// </summary>
[JsonProperty("endpoint")]
public string? Endpoint { get; set; }
}
/// <summary>
///
/// </summary>
[JsonProperty("poll")]
public PollData? Poll { get; set; }
/// <summary>
/// The temporary login url that should be used for login.
/// </summary>
[JsonProperty("login")]
public string? LoginUrl { get; set; }
}

View File

@@ -0,0 +1,24 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
public class OcsResponseLoginFlowV2Credentials
{
/// <summary>
/// The server url the login credentials are for.
/// </summary>
[JsonProperty("server")]
public string? Server { get; set; }
/// <summary>
/// The login name (username or password) used for the login.
/// </summary>
[JsonProperty("loginName")]
public string? LoginName { get; set; }
/// <summary>
/// The app password that has been generated.
/// </summary>
[JsonProperty("appPassword")]
public string? AppPassword { get; set; }
}

View File

@@ -0,0 +1,30 @@
using Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
namespace Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2;
public class OcsApiLoginFlowV2 : OcsApiBase
{
private const string OCS_LOGIN_INIT = "/index.php/login/v2";
public OcsApiLoginFlowV2(OcsApi manager) : base(manager)
{
}
public OcsResponseLoginFlowV2? Init(string url)
{
return Manager.MakeRequest<OcsResponseLoginFlowV2>(HttpMethod.Post, url + OCS_LOGIN_INIT);
}
public OcsResponseLoginFlowV2Credentials? Poll(OcsResponseLoginFlowV2.PollData poll)
{
ArgumentNullException.ThrowIfNull(poll?.Endpoint);
ArgumentNullException.ThrowIfNull(poll?.Token);
return Manager.MakeRequest<OcsResponseLoginFlowV2Credentials?>(HttpMethod.Post, poll.Endpoint,
parameters: new Dictionary<string, string>
{
{ "token", poll.Token }
});
}
}