more work on api & rename to Pilz.Net
This commit is contained in:
41
Pilz.Net.CloudProviders.Nextcloud/Extensions.cs
Normal file
41
Pilz.Net.CloudProviders.Nextcloud/Extensions.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user