From b6420fcc495933cacef196202ce9bcbc867118a0 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 20 May 2026 11:31:02 +0200 Subject: [PATCH] Refactor GetAsync methods to return deserialized data Updated GetAsync methods in ProfileApi, RecActionApi, and ResultApi to return deserialized objects of type instead of raw HttpResponseMessage, improving usability. Added conditional compilation (#if NETFRAMEWORK) to handle nullable return types (T?) for non-NET Framework targets, ensuring compatibility across .NET versions. Replaced direct Http.GetAsync calls with using blocks for proper disposal of HTTP responses. Introduced response handling and deserialization via ReCClientHelpers to streamline processing and logging. Updated XML documentation to reflect the new behavior and removed redundant parameters. --- src/ReC.Client/Api/ProfileApi.cs | 18 +++++++++++------- src/ReC.Client/Api/RecActionApi.cs | 18 +++++++++++------- src/ReC.Client/Api/ResultApi.cs | 22 +++++++++------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/ReC.Client/Api/ProfileApi.cs b/src/ReC.Client/Api/ProfileApi.cs index b0a62be..4347095 100644 --- a/src/ReC.Client/Api/ProfileApi.cs +++ b/src/ReC.Client/Api/ProfileApi.cs @@ -25,16 +25,20 @@ namespace ReC.Client.Api } /// - /// Retrieves profiles, optionally filtered by identifier. + /// Retrieves profiles and deserializes the JSON response into . /// - /// Optional profile identifier filter. When , all profiles are returned. - /// Whether to include related actions. Defaults to to match the API default. - /// A token to cancel the operation. - /// The HTTP response message. - public Task GetAsync(long? id = null, bool includeActions = true, CancellationToken cancel = default) +#if NETFRAMEWORK + public async Task GetAsync(long? id = null, bool includeActions = true, CancellationToken cancel = default) +#else + public async Task GetAsync(long? id = null, bool includeActions = true, CancellationToken cancel = default) +#endif { var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions)); - return Http.GetAsync($"{ResourcePath}{query}", cancel); + using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false)) + { + var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false); + return ReCClientHelpers.Deserialize(body); + } } } } diff --git a/src/ReC.Client/Api/RecActionApi.cs b/src/ReC.Client/Api/RecActionApi.cs index f038a90..9429d3f 100644 --- a/src/ReC.Client/Api/RecActionApi.cs +++ b/src/ReC.Client/Api/RecActionApi.cs @@ -58,16 +58,20 @@ namespace ReC.Client.Api } /// - /// Retrieves Rec actions. + /// Retrieves Rec actions and deserializes the JSON response into . /// - /// Optional profile filter. - /// Optional invoked filter. - /// A token to cancel the operation. - /// The HTTP response message. - public Task GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default) +#if NETFRAMEWORK + public async Task GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default) +#else + public async Task GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default) +#endif { var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked)); - return Http.GetAsync($"{ResourcePath}{query}", cancel); + using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false)) + { + var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false); + return ReCClientHelpers.Deserialize(body); + } } } } diff --git a/src/ReC.Client/Api/ResultApi.cs b/src/ReC.Client/Api/ResultApi.cs index 1a818c3..6a6d21e 100644 --- a/src/ReC.Client/Api/ResultApi.cs +++ b/src/ReC.Client/Api/ResultApi.cs @@ -25,21 +25,12 @@ namespace ReC.Client.Api } /// - /// Retrieves results with optional filters. + /// Retrieves results with optional filters and deserializes the JSON response into . /// - /// Optional result identifier. - /// Optional action identifier. - /// Optional profile identifier. - /// Optional batch identifier. - /// Whether to include the related action. Defaults to to match the API default. - /// Whether to include the related profile. Defaults to to match the API default. - /// When , restricts results to those belonging to the most recent batch matching the other filters. - /// A token to cancel the operation. - /// The HTTP response message. #if NETFRAMEWORK - public Task GetAsync(long? id = null, long? actionId = null, long? profileId = null, string batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default) + public async Task GetAsync(long? id = null, long? actionId = null, long? profileId = null, string batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default) #else - public Task GetAsync(long? id = null, long? actionId = null, long? profileId = null, string? batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default) + public async Task GetAsync(long? id = null, long? actionId = null, long? profileId = null, string? batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default) #endif { var query = ReCClientHelpers.BuildQuery( @@ -50,7 +41,12 @@ namespace ReC.Client.Api ("IncludeAction", includeAction), ("IncludeProfile", includeProfile), ("LastBatch", lastBatch)); - return Http.GetAsync($"{ResourcePath}{query}", cancel); + + using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false)) + { + var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false); + return ReCClientHelpers.Deserialize(body); + } } } }