Introduce BaseCrudApi to encapsulate common CRUD logic for API resource classes. Refactor CommonApi, EndpointAuthApi, EndpointParamsApi, EndpointsApi, ProfileApi, RecActionApi, and ResultApi to inherit from BaseCrudApi, removing duplicated CRUD methods and constructors. This centralizes CRUD operations, reduces code duplication, and improves maintainability.
46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ReC.Client.Api
|
|
{
|
|
/// <summary>
|
|
/// Provides access to RecAction endpoints.
|
|
/// </summary>
|
|
public class RecActionApi : BaseCrudApi
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="RecActionApi"/> class.
|
|
/// </summary>
|
|
/// <param name="http">The HTTP client used for requests.</param>
|
|
public RecActionApi(HttpClient http) : base(http, "api/RecAction")
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invokes a ReC action for the specified profile.
|
|
/// </summary>
|
|
/// <param name="profileId">The profile identifier.</param>
|
|
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
|
/// <returns><see langword="true"/> if the request succeeds; otherwise, <see langword="false"/>.</returns>
|
|
public async Task<bool> InvokeAsync(int profileId, CancellationToken cancellationToken = default)
|
|
{
|
|
var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content: null, cancellationToken);
|
|
return resp.IsSuccessStatusCode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves Rec actions.
|
|
/// </summary>
|
|
/// <param name="profileId">Optional profile filter.</param>
|
|
/// <param name="invoked">Optional invoked filter.</param>
|
|
/// <param name="cancel">A token to cancel the operation.</param>
|
|
/// <returns>The HTTP response message.</returns>
|
|
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
|
|
{
|
|
var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked));
|
|
return Http.GetAsync($"{ResourcePath}{query}", cancel);
|
|
}
|
|
}
|
|
}
|