fixes for Nextcloud
This commit is contained in:
@@ -10,6 +10,8 @@ using System.Net;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.APIs;
|
||||
using System.Net.Sockets;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Data;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.OCS
|
||||
{
|
||||
@@ -51,30 +53,103 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.OCS
|
||||
return BaseUrl + path;
|
||||
}
|
||||
|
||||
public Task<TResponse?> MakeRequest<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
/// <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);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> MakeRequest(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
/// <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)
|
||||
{
|
||||
return MakeRequest(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
public async Task<TResponse?> MakeRequest<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
using var responseInit = await MakeRequest(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
using var responseInit = MakeRequest(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
|
||||
if (responseInit != null)
|
||||
{
|
||||
var bodyInit = await responseInit.Content.ReadAsStringAsync();
|
||||
var bodyInit = responseInit.Content.ReadAsStringAsync().Result;
|
||||
return JsonConvert.DeserializeObject<TResponse>(bodyInit);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> MakeRequest(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
/// <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;
|
||||
@@ -118,7 +193,7 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.OCS
|
||||
Content = httpContent
|
||||
};
|
||||
|
||||
return await client.SendAsync(request);
|
||||
return client.Send(request);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in New Issue
Block a user