From 55059202661e7c3aecd9241f3061edffdf4eb9b2 Mon Sep 17 00:00:00 2001 From: Matthew Jorgensen Date: Fri, 4 Oct 2024 12:06:33 -0500 Subject: [PATCH 1/2] Refactor LinkAceClient to allow for passing in an HttpClient --- src/LinkAce.NET/LinkAceClient.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LinkAce.NET/LinkAceClient.cs b/src/LinkAce.NET/LinkAceClient.cs index cbf222d..5ee7fd1 100644 --- a/src/LinkAce.NET/LinkAceClient.cs +++ b/src/LinkAce.NET/LinkAceClient.cs @@ -16,7 +16,7 @@ namespace LinkAce.NET; public class LinkAceClient { private static string? _apiUrl; - private static HttpClient _client = new(); + private static HttpClient _client; /// /// Initializes a new instance of the class with the specified URL and HTTP client. /// @@ -32,10 +32,12 @@ public LinkAceClient(string linkAceUrl, HttpClient httpClient) /// /// The base URL of the LinkAce.NET instance. /// The API token for authentication. - public LinkAceClient(string linkAceUrl, string apiToken) + /// The HTTP client to use for requests. + public LinkAceClient(string linkAceUrl, string apiToken, HttpClient? client = null) { _apiUrl = $"{linkAceUrl}/api/v1"; // Setup HttpClient + _client = client ?? new HttpClient(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json)); _client.DefaultRequestHeaders.UserAgent.Add(Meta.UserAgent); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiToken); From 33db1f43363d908c89e5f8d4b56047a0591b8271 Mon Sep 17 00:00:00 2001 From: Matthew Jorgensen Date: Fri, 4 Oct 2024 13:58:31 -0500 Subject: [PATCH 2/2] Mark constructor without ApiToken obsolete --- src/LinkAce.NET/LinkAceClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LinkAce.NET/LinkAceClient.cs b/src/LinkAce.NET/LinkAceClient.cs index 5ee7fd1..4a9473c 100644 --- a/src/LinkAce.NET/LinkAceClient.cs +++ b/src/LinkAce.NET/LinkAceClient.cs @@ -22,6 +22,7 @@ public class LinkAceClient /// /// The base URL of the LinkAce.NET instance. /// The HTTP client to use for requests. + [Obsolete("Use the constructor with the API token instead.")] public LinkAceClient(string linkAceUrl, HttpClient httpClient) { _apiUrl = $"{linkAceUrl}/api/v1";