Introduced the EndpointAuthApi class in ReC.Client.Api to handle endpoint authentication API interactions. This class provides async methods for creating, updating, and deleting endpoint authentication configurations using HttpClient, with support for cancellation tokens and JSON payload serialization. XML documentation is included for clarity.
61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ReC.Client.Api
|
|
{
|
|
/// <summary>
|
|
/// Provides access to endpoint authentication endpoints.
|
|
/// </summary>
|
|
public class EndpointAuthApi
|
|
{
|
|
private readonly HttpClient _http;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="EndpointAuthApi"/> class.
|
|
/// </summary>
|
|
/// <param name="http">The HTTP client used for requests.</param>
|
|
public EndpointAuthApi(HttpClient http)
|
|
{
|
|
_http = http;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates endpoint authentication configuration.
|
|
/// </summary>
|
|
/// <typeparam name="T">The payload type.</typeparam>
|
|
/// <param name="procedure">The payload to send.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>The HTTP response message.</returns>
|
|
public Task<HttpResponseMessage> CreateEndpointAuthAsync<T>(T procedure, CancellationToken cancel = default)
|
|
=> _http.PostAsync("api/EndpointAuth", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
|
|
/// <summary>
|
|
/// Updates endpoint authentication configuration.
|
|
/// </summary>
|
|
/// <typeparam name="T">The payload type.</typeparam>
|
|
/// <param name="id">The authentication identifier.</param>
|
|
/// <param name="procedure">The payload to send.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>The HTTP response message.</returns>
|
|
public Task<HttpResponseMessage> UpdateEndpointAuthAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
|
=> _http.PutAsync($"api/EndpointAuth/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
|
|
|
/// <summary>
|
|
/// Deletes endpoint authentications.
|
|
/// </summary>
|
|
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
|
/// <param name="procedure">The payload to send.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>The HTTP response message.</returns>
|
|
public Task<HttpResponseMessage> DeleteEndpointAuthAsync<T>(T procedure, CancellationToken cancel = default)
|
|
{
|
|
var request = new HttpRequestMessage(HttpMethod.Delete, "api/EndpointAuth")
|
|
{
|
|
Content = ReCClientHelpers.ToJsonContent(procedure)
|
|
};
|
|
return _http.SendAsync(request, cancel);
|
|
}
|
|
}
|
|
}
|