ReC/src/ReC.Client/ReCClient.cs
Developer 02 b190e4f5e9 Update InvokeRecActionAsync to return success status
The method `InvokeRecActionAsync` in the `ReC.Client` namespace was updated to return a `bool` instead of `Task`. This change allows the method to indicate whether the HTTP request was successful.

- Updated the return type from `Task` to `Task<bool>`.
- Modified the `<returns>` XML documentation to reflect the new behavior.
- Replaced `resp.EnsureSuccessStatusCode()` with `resp.IsSuccessStatusCode` to return the success status directly.
2025-12-05 23:36:45 +01:00

34 lines
1.0 KiB
C#

using System.Text.Json;
#if NETFRAMEWORK
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
#endif
namespace ReC.Client
{
public class ReCClient
{
private readonly HttpClient _http;
public static readonly string ClientName = Guid.NewGuid().ToString();
public ReCClient(IHttpClientFactory httpClientFactory)
{
_http = httpClientFactory.CreateClient(ClientName);
}
/// <summary>
/// POST api/RecAction/invoke/{profileId}
/// </summary>
/// <param name="profileId"></param>
/// <param name="cancellationToken"></param>
/// <returns>True if the request was successful, false otherwise</returns>
public async Task<bool> InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default)
{
var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken);
return resp.IsSuccessStatusCode;
}
}
}