Add ReCClientOptions for configurable client behavior
Introduced a new `ReCClientOptions` property to `BaseCrudApi` and its derived classes to enhance flexibility and control over client behavior. Updated constructors to accept an optional `ReCClientOptions` parameter, with default options applied when omitted. Modified `CreateAsync`, `UpdateAsync`, and other methods in `BaseCrudApi` to utilize the `Options.LogSuccessfulRequests` property for more granular logging control. Updated derived API classes (`CommonApi`, `EndpointAuthApi`, `EndpointParamsApi`, `EndpointsApi`, `ProfileApi`, `RecActionApi`, and `ResultApi`) to pass the `options` parameter to the base constructor. Ensured compatibility with both `NETFRAMEWORK` and other frameworks by using nullable annotations where applicable. These changes improve the extensibility and maintainability of the API client.
This commit is contained in:
@@ -30,21 +30,28 @@ namespace ReC.Client.Api
|
|||||||
protected readonly ILogger? Logger;
|
protected readonly ILogger? Logger;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The options controlling client behavior. Never <see langword="null"/>.
|
||||||
|
/// </summary>
|
||||||
|
protected readonly ReCClientOptions Options;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
|
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
|
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger logger = null)
|
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger logger = null, ReCClientOptions options = null)
|
||||||
#else
|
#else
|
||||||
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger? logger = null)
|
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger? logger = null, ReCClientOptions? options = null)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
Http = http ?? throw new ArgumentNullException(nameof(http));
|
Http = http ?? throw new ArgumentNullException(nameof(http));
|
||||||
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
|
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
|
Options = options ?? new ReCClientOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,7 +66,7 @@ namespace ReC.Client.Api
|
|||||||
using (var content = ReCClientHelpers.ToJsonContent(payload))
|
using (var content = ReCClientHelpers.ToJsonContent(payload))
|
||||||
using (var resp = await Http.PostAsync(ResourcePath, content, cancel))
|
using (var resp = await Http.PostAsync(ResourcePath, content, cancel))
|
||||||
{
|
{
|
||||||
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
|
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +83,7 @@ namespace ReC.Client.Api
|
|||||||
using (var content = ReCClientHelpers.ToJsonContent(payload))
|
using (var content = ReCClientHelpers.ToJsonContent(payload))
|
||||||
using (var resp = await Http.PutAsync($"{ResourcePath}/{id}", content, cancel))
|
using (var resp = await Http.PutAsync($"{ResourcePath}/{id}", content, cancel))
|
||||||
{
|
{
|
||||||
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
|
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +102,7 @@ namespace ReC.Client.Api
|
|||||||
})
|
})
|
||||||
using (var resp = await Http.SendAsync(request, cancel))
|
using (var resp = await Http.SendAsync(request, cancel))
|
||||||
{
|
{
|
||||||
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancel).ConfigureAwait(false);
|
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public CommonApi(HttpClient http, ILogger logger = null) : base(http, "api/Common", logger)
|
public CommonApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Common", logger, options)
|
||||||
#else
|
#else
|
||||||
public CommonApi(HttpClient http, ILogger? logger = null) : base(http, "api/Common", logger)
|
public CommonApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Common", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public EndpointAuthApi(HttpClient http, ILogger logger = null) : base(http, "api/EndpointAuth", logger)
|
public EndpointAuthApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointAuth", logger, options)
|
||||||
#else
|
#else
|
||||||
public EndpointAuthApi(HttpClient http, ILogger? logger = null) : base(http, "api/EndpointAuth", logger)
|
public EndpointAuthApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointAuth", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public EndpointParamsApi(HttpClient http, ILogger logger = null) : base(http, "api/EndpointParams", logger)
|
public EndpointParamsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointParams", logger, options)
|
||||||
#else
|
#else
|
||||||
public EndpointParamsApi(HttpClient http, ILogger? logger = null) : base(http, "api/EndpointParams", logger)
|
public EndpointParamsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointParams", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public EndpointsApi(HttpClient http, ILogger logger = null) : base(http, "api/Endpoints", logger)
|
public EndpointsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Endpoints", logger, options)
|
||||||
#else
|
#else
|
||||||
public EndpointsApi(HttpClient http, ILogger? logger = null) : base(http, "api/Endpoints", logger)
|
public EndpointsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Endpoints", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public ProfileApi(HttpClient http, ILogger logger = null) : base(http, "api/Profile", logger)
|
public ProfileApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Profile", logger, options)
|
||||||
#else
|
#else
|
||||||
public ProfileApi(HttpClient http, ILogger? logger = null) : base(http, "api/Profile", logger)
|
public ProfileApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Profile", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public RecActionApi(HttpClient http, ILogger logger = null) : base(http, "api/RecAction", logger)
|
public RecActionApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/RecAction", logger, options)
|
||||||
#else
|
#else
|
||||||
public RecActionApi(HttpClient http, ILogger? logger = null) : base(http, "api/RecAction", logger)
|
public RecActionApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/RecAction", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,7 @@ namespace ReC.Client.Api
|
|||||||
using (content)
|
using (content)
|
||||||
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
|
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
|
||||||
{
|
{
|
||||||
await ReCClientHelpers.HandleResponseAsync(resp, Logger, cancellationToken).ConfigureAwait(false);
|
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ namespace ReC.Client.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="http">The HTTP client used for requests.</param>
|
/// <param name="http">The HTTP client used for requests.</param>
|
||||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||||
|
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public ResultApi(HttpClient http, ILogger logger = null) : base(http, "api/Result", logger)
|
public ResultApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Result", logger, options)
|
||||||
#else
|
#else
|
||||||
public ResultApi(HttpClient http, ILogger? logger = null) : base(http, "api/Result", logger)
|
public ResultApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Result", logger, options)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user