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 }
});
}
}

View File

@@ -0,0 +1,41 @@
using Pilz.Net.CloudProviders.Nextcloud.OCS;
using System.Text;
namespace Pilz.Net.CloudProviders.Nextcloud;
public static class Extensions
{
public static string ToBasicAuth(this OcsApiAuthCredentials? credentials)
{
if (credentials != null)
{
var creds = $"{credentials?.LoginName}:{credentials?.AppPassword}";
var bytes = Encoding.UTF8.GetBytes(creds);
return "Basic " + Convert.ToBase64String(bytes);
}
return string.Empty;
}
public static OcsApiAuthCredentials? ToOcsApiAuthCredentials(this NextcloudLogin? login)
{
if (!string.IsNullOrEmpty(login?.LoginName) && !string.IsNullOrEmpty(login?.AppPassword))
return new OcsApiAuthCredentials(login.LoginName, login.AppPassword);
return null;
}
public static OcsApiUrlPath FillParameters(this OcsApiUrlPath path, params object?[] @params)
{
return (OcsApiUrlPath)string.Format(path, @params);
}
public static DateTime UnixTimeMillisecondsToDateTime(this long? value)
{
return DateTimeOffset.FromUnixTimeMilliseconds(value ?? 0).DateTime;
}
public static long ToUnixTimeMilliseconds(this DateTime value)
{
return new DateTimeOffset(value).ToUnixTimeMilliseconds();
}
}

View File

@@ -0,0 +1,162 @@
using Pilz.Net.CloudProviders.Nextcloud.Client;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud;
using Pilz.Net.CloudProviders.Nextcloud.Client.Cloud.Model;
using Pilz.Net.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
using Pilz.Net.CloudProviders.Nextcloud.OCS;
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
Nach:
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
*/
using System.Diagnostics;
namespace Pilz.Net.CloudProviders.Nextcloud;
public class NextcloudClient : IDisposable
{
private readonly List<ClientBase> clients = new();
private NextcloudLogin? currentLogin;
public OcsApi Ocs { get; init; } = new();
public NextcloudLogin? CurrentLogin
{
get => currentLogin;
private set
{
currentLogin = value;
Ocs.BaseUrl = value?.Server ?? string.Empty;
}
}
public CloudClient Cloud => GetClient<CloudClient>();
public NextcloudClient()
{
Ocs.GetOcsApiAuthCredentails += Ocs_GetOcsApiAuthCredentails;
}
private void Ocs_GetOcsApiAuthCredentails(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs)
{
if (sender == Ocs)
eventArgs.Credentials = CurrentLogin.ToOcsApiAuthCredentials();
}
public TClient GetClient<TClient>() where TClient : ClientBase
{
var instance = TryGetClient<TClient>();
return instance is null ? throw new NullReferenceException() : instance;
}
public TClient? TryGetClient<TClient>() where TClient : ClientBase
{
TClient? instance = (TClient?)clients.FirstOrDefault(n => n is TClient);
instance ??= (TClient?)Activator.CreateInstance(typeof(TClient), new object[] { this });
if (instance is not null)
clients.Add(instance);
return instance;
}
public UserInfo? Login(NextcloudLogin login)
{
return Login(login, true);
}
public UserInfo? Login(NextcloudLogin login, bool checkUser)
{
// Ensure we are logged out
Logout(false);
// Temporary set user login
CurrentLogin = login;
if (checkUser)
{
// Try get user info & check if user is enabled
var userInfo = Cloud.GetUserInfo();
var isValid = userInfo != null /*&& userInfo.Enabled*/; // Enabled is false for some (new) users but they still are able to login??
// If invalid, reset login credentials
if (!isValid)
CurrentLogin = null;
return userInfo;
}
return null;
}
public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken)
{
// Ensure we are logged out
Logout(false);
// Init the login process
var initResponse = Ocs.LoginFlowV2.Init(baseUrl);
if (!string.IsNullOrEmpty(initResponse?.LoginUrl) && initResponse.Poll != null)
{
// Open the browser
Process.Start(new ProcessStartInfo
{
FileName = initResponse.LoginUrl,
UseShellExecute = true
});
// Poll for credentails in intervals
OcsResponseLoginFlowV2Credentials? pollResponse = null;
while (!cancellationToken.IsCancellationRequested && pollResponse is null)
{
// Wait 5 seconds
Thread.Sleep(5000);
// Poll the credentials
if (!cancellationToken.IsCancellationRequested)
pollResponse = Ocs.LoginFlowV2.Poll(initResponse.Poll);
}
// Check login credentials
if (pollResponse is not null)
CurrentLogin = new(pollResponse);
}
return CurrentLogin;
}
public void Logout()
{
Logout(false);
}
public void Logout(bool logoutOnServer)
{
if (CurrentLogin != null)
{
// Delete currently used app password
if (logoutOnServer)
Ocs.Core.DeleteAppPassword();
// Reset current login infos
CurrentLogin = null;
}
}
public void Dispose()
{
Ocs.Dispose();
GC.SuppressFinalize(this);
}
}

View File

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

View File

@@ -0,0 +1,8 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public delegate void GetOcsApiAuthCredentailsEventHandler(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs);
public class GetOcsApiAuthCredentailsEventArgs : EventArgs
{
public OcsApiAuthCredentials? Credentials { get; set; }
}

View File

@@ -0,0 +1,228 @@
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http.Headers;
using Newtonsoft.Json;
Nach:
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Core;
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2;
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
using System;
using System.Json;
*/
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
Vor:
using
Nach:
using
*/
using Pilz.Net.CloudProviders.Nextcloud;
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsApi : IDisposable
{
public const string CONTENT_TYPE_JSON = "application/json";
public event GetOcsApiAuthCredentailsEventHandler? GetOcsApiAuthCredentails;
private readonly HttpClient client = new();
private readonly List<OcsApiBase> apis = new();
public string BaseUrl { get; set; } = string.Empty;
public OcsApiLoginFlowV2 LoginFlowV2 => GetApi<OcsApiLoginFlowV2>();
public OcsApiCore Core => GetApi<OcsApiCore>();
public OcsApiCloud Cloud => GetApi<OcsApiCloud>();
public TApi GetApi<TApi>() where TApi : OcsApiBase
{
var instance = TryGetApi<TApi>();
return instance is null ? throw new NullReferenceException() : instance;
}
public TApi? TryGetApi<TApi>() where TApi : OcsApiBase
{
TApi? instance = (TApi?)apis.FirstOrDefault(n => n is TApi);
instance ??= (TApi?)Activator.CreateInstance(typeof(TApi), new object[] { this });
if (instance is not null)
apis.Add(instance);
return instance;
}
public string BuildFullUrl(OcsApiUrlPath path)
{
return BaseUrl + path;
}
/// <summary>
/// Makes an request with the given arguments and deserialize it to the given type.
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
{
return MakeRequestOcs<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
}
/// <summary>
/// Makes an request with the given arguments and deserialize it to the given type.
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
{
var response = MakeRequest<OcsApiResponse<TResponse>?>(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
if (response != null)
return response.Ocs;
return default;
}
/// <summary>
/// Makes an request with the given arguments and deserialize it to the given type.
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns the deserialized content of type given type.</returns>
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
{
return MakeRequest<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
}
/// <summary>
/// Makes an request with the given arguments and deserialize it to the given type.
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns the deserialized content of type given type.</returns>
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
{
using var responseInit = MakeRequest(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
if (responseInit != null)
{
try
{
var bodyInit = responseInit.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<TResponse>(bodyInit);
}
catch (FormatException) { }
catch (JsonSerializationException) { }
}
return default;
}
/// <summary>
/// Makes an request with the given arguments.
/// </summary>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns a HttpResponseMessage as result.</returns>
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
{
return MakeRequest(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
}
/// <summary>
/// Makes an request with the given arguments.
/// </summary>
/// <param name="httpMethod"></param>
/// <param name="url"></param>
/// <param name="useAuthentication"></param>
/// <param name="parameters"></param>
/// <param name="content"></param>
/// <returns>Returns a HttpResponseMessage as result.</returns>
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
{
OcsApiAuthCredentials? authentication;
string @params;
HttpContent? httpContent;
// Get authentication
if (useAuthentication)
{
var args = new GetOcsApiAuthCredentailsEventArgs();
GetOcsApiAuthCredentails?.Invoke(this, args);
authentication = args.Credentials;
}
else
authentication = null;
// Parse params
if (parameters != null)
@params = "?" + string.Join("&", parameters.Select(p => $"{p.Key}={p.Value}"));
else
@params = string.Empty;
// Create content
if (content is HttpContent contentHttp)
httpContent = contentHttp;
else if (content is OcsData || content is not null)
{
var stringContent = JsonConvert.SerializeObject(content);
httpContent = new StringContent(stringContent, null, CONTENT_TYPE_JSON);
}
else
httpContent = null;
// Send request
var request = new HttpRequestMessage
{
Method = httpMethod ?? HttpMethod.Post,
RequestUri = new Uri(url + @params),
Headers =
{
{ "Accept", CONTENT_TYPE_JSON },
{ "OCS-APIREQUEST", "true" },
//{ "Authorization", authentication.ToBasicAuth() }
},
Content = httpContent
};
// Add authorization
if (authentication != null)
request.Headers.Add("Authorization", authentication.ToBasicAuth());
return client.Send(request);
}
public void Dispose()
{
client.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,13 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public struct OcsApiAuthCredentials
{
public string LoginName { get; set; }
public string AppPassword { get; set; }
public OcsApiAuthCredentials(string loginName, string appPassword)
{
LoginName = loginName;
AppPassword = appPassword;
}
}

View File

@@ -0,0 +1,11 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public abstract class OcsApiBase
{
protected OcsApi Manager { get; init; }
protected OcsApiBase(OcsApi manager)
{
Manager = manager;
}
}

View File

@@ -0,0 +1,10 @@
using Newtonsoft.Json;
using Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsApiResponse<TOcsResponse> where TOcsResponse : IOcsResponse
{
[JsonProperty("ocs")]
public TOcsResponse? Ocs { get; set; }
}

View File

@@ -0,0 +1,24 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public readonly struct OcsApiUrlPath
{
private readonly string path;
public OcsApiUrlPath()
{
path = string.Empty;
}
public OcsApiUrlPath(string path)
{
this.path = path;
}
public static implicit operator string(OcsApiUrlPath o) => o.path;
public static implicit operator OcsApiUrlPath(string o) => new(o);
public override readonly string ToString()
{
return path;
}
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS;
public class OcsData
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponse
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponseData
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public interface IOcsResponseMeta
{
}

View File

@@ -0,0 +1,20 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponse<TMeta, TData> : IOcsResponse where TMeta : IOcsResponseMeta where TData : IOcsResponseData
{
[JsonProperty("meta")]
public TMeta? Meta { get; set; }
[JsonProperty("data")]
public TData? Data { get; set; }
}
public class OcsResponse<TData> : OcsResponse<OcsResponseMeta, TData> where TData : IOcsResponseData
{
}
public class OcsResponse : OcsResponse<OcsResponseMeta, OcsResponseData>
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseData : IOcsResponseData
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseDataArray<TEntry> : List<TEntry>, IOcsResponseData where TEntry : OcsResponseDataEntry
{
}

View File

@@ -0,0 +1,5 @@
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseDataEntry
{
}

View File

@@ -0,0 +1,15 @@
using Newtonsoft.Json;
namespace Pilz.Net.CloudProviders.Nextcloud.OCS.Responses;
public class OcsResponseMeta : IOcsResponseMeta
{
[JsonProperty("status")]
public string? Status { get; set; }
[JsonProperty("statuscode")]
public int? StatusCode { get; set; }
[JsonProperty("message")]
public string? Message { get; set; }
}

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Version>2.1.2</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<None Update="README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,28 @@
# Nextcloud Client Api
This library is for interactive with Nextcloud instances.
**Beware:** This library is NOT complete. I usually expand it by the functions I need. So, feel free to extend it with your APIs and your functions and submit a Pull Request with the changes.
## How to use
This is a simple shot how the library is intended to be used.
*There are two ways to login. One is the LoginFlowV2.*
```cs
using NextcloudClient ncClient = new();
var userInfo = ncClient.Login(creds);
if (userInfo != null)
{
var tableId = 16L;
var tablesClient = ncClient.GetClient<TablesClient>();
var rows = tablesClient.GetRows(tableId);
if (rows != null)
{
foreach (var row in rows)
Console.WriteLine(row.RowId);
}
}
```