introduce a very simple Nextcloud API
This commit is contained in:
37
Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs
Normal file
37
Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Model;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user