diff --git a/src/ReC.Client/Api/ResultApi.cs b/src/ReC.Client/Api/ResultApi.cs new file mode 100644 index 0000000..4ad84f0 --- /dev/null +++ b/src/ReC.Client/Api/ResultApi.cs @@ -0,0 +1,74 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to output result endpoints. + /// + public class ResultApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public ResultApi(HttpClient http) + { + _http = http; + } + + /// + /// Retrieves results with optional filters. + /// + /// Optional result identifier. + /// Optional action identifier. + /// Optional profile identifier. + /// A token to cancel the operation. + /// The HTTP response message. + public Task GetResultsAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default) + { + var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId)); + return _http.GetAsync($"api/OutRes{query}", cancel); + } + + /// + /// Creates a result. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateResultAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/OutRes", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates a result. + /// + /// The payload type. + /// The result identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateResultAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/OutRes/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes results. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteResultsAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/OutRes") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}