Refactor GetAsync methods to return deserialized data
Updated GetAsync methods in ProfileApi, RecActionApi, and ResultApi to return deserialized objects of type <T> 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.
This commit is contained in:
@@ -58,16 +58,20 @@ namespace ReC.Client.Api
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves Rec actions.
|
||||
/// Retrieves Rec actions and deserializes the JSON response into <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <param name="profileId">Optional profile filter.</param>
|
||||
/// <param name="invoked">Optional invoked filter.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
|
||||
#if NETFRAMEWORK
|
||||
public async Task<T> GetAsync<T>(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
|
||||
#else
|
||||
public async Task<T?> GetAsync<T>(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<T>(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user