From 0fddf5669f0cca7b0aa8cbf8d35403e33697285d Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:33:36 +0100 Subject: [PATCH] Add RecActionApi client for RecAction endpoint operations Introduced RecActionApi in ReC.Client.Api to provide a typed API client for RecAction endpoints. Includes methods for invoking, retrieving, creating, updating, and deleting Rec actions, with support for cancellation tokens and helper-based serialization. All methods are documented with XML comments. --- src/ReC.Client/Api/RecActionApi.cs | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/ReC.Client/Api/RecActionApi.cs diff --git a/src/ReC.Client/Api/RecActionApi.cs b/src/ReC.Client/Api/RecActionApi.cs new file mode 100644 index 0000000..377fa7b --- /dev/null +++ b/src/ReC.Client/Api/RecActionApi.cs @@ -0,0 +1,85 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to RecAction endpoints. + /// + public class RecActionApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public RecActionApi(HttpClient http) + { + _http = http; + } + + /// + /// Invokes a ReC action for the specified profile. + /// + /// The profile identifier. + /// A token to cancel the operation. + /// if the request succeeds; otherwise, . + public async Task InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default) + { + var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken); + return resp.IsSuccessStatusCode; + } + + /// + /// Retrieves Rec actions. + /// + /// Optional profile filter. + /// Optional invoked filter. + /// A token to cancel the operation. + /// The HTTP response message. + public Task GetRecActionsAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default) + { + var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked)); + return _http.GetAsync($"api/RecAction{query}", cancel); + } + + /// + /// Creates a Rec action. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateRecActionAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/RecAction", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates a Rec action. + /// + /// The payload type. + /// The action identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateRecActionAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/RecAction/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes Rec actions. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteRecActionsAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/RecAction") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}