From 4b5446f357be1ccdafbcacbbce3c1cd525a37dc8 Mon Sep 17 00:00:00 2001 From: MichaelL79 <53481075+MichaelL79@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:31:11 +0100 Subject: [PATCH] Moved target version to connection info object --- src/FMData.Rest/FileMakerRestClient.cs | 18 +++++++----------- src/FMData/ConnectionInfo.cs | 4 ++++ tests/FMData.Rest.Tests/GeneralTests.cs | 22 +++++----------------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/FMData.Rest/FileMakerRestClient.cs b/src/FMData.Rest/FileMakerRestClient.cs index 33022f0..97a6f91 100644 --- a/src/FMData.Rest/FileMakerRestClient.cs +++ b/src/FMData.Rest/FileMakerRestClient.cs @@ -65,16 +65,15 @@ public class FileMakerRestClient : FileMakerApiClientBase, IFileMakerRestClient /// Version of the DataAPI endpoint to use. Default is v1. [Obsolete("Creates a new HttpClient for this instance, and is generally not good. Inject a managed client.")] public FileMakerRestClient(string fmsUri, string file, string user, string pass, RestTargetVersion targetVersion = RestTargetVersion.v1) - : this(new HttpClient(), new ConnectionInfo { FmsUri = fmsUri, Database = file, Username = user, Password = pass }, targetVersion) { } + : this(new HttpClient(), new ConnectionInfo { FmsUri = fmsUri, Database = file, Username = user, Password = pass, RestTargetVersion = targetVersion }) { } /// /// FM Data Constructor with HttpClient and ConnectionInfo. Useful for Dependency Injection situations. /// /// The HttpClient instance to use. /// The connection information for FMS. - /// Version of the DataAPI endpoint to use. Default is v1. - public FileMakerRestClient(HttpClient client, ConnectionInfo conn, RestTargetVersion targetVersion = RestTargetVersion.v1) - : this(client, new DefaultAuthTokenProvider(conn), targetVersion) + public FileMakerRestClient(HttpClient client, ConnectionInfo conn) + : this(client, new DefaultAuthTokenProvider(conn)) { } /// @@ -82,11 +81,9 @@ public FileMakerRestClient(HttpClient client, ConnectionInfo conn, RestTargetVer /// /// The HttpClient instance to use. /// Authentication provider - /// Version of the DataAPI endpoint to use. Default is v1. public FileMakerRestClient( HttpClient client, - IAuthTokenProvider authTokenProvider, - RestTargetVersion targetVersion = RestTargetVersion.v1) : this(client, authTokenProvider, false, targetVersion) + IAuthTokenProvider authTokenProvider) : this(client, authTokenProvider, false) { } /// @@ -95,19 +92,18 @@ public FileMakerRestClient( /// The HttpClient instance to use. /// Authentication provider /// When set to true, will use a new http client to load container data that has isolated cookies and can work with ASP.NET Core DI/HttpClientFactory. - /// Version of the DataAPI endpoint to use. Default is v1. public FileMakerRestClient( HttpClient client, IAuthTokenProvider authTokenProvider, - bool useNewClientForContainers, - RestTargetVersion targetVersion = RestTargetVersion.v1) + bool useNewClientForContainers) : base(client, authTokenProvider.ConnectionInfo) { _authTokenProvider = authTokenProvider; _useNewClientForContainers = useNewClientForContainers; - switch (targetVersion) + switch (_authTokenProvider.ConnectionInfo?.RestTargetVersion) { case RestTargetVersion.v1: + case null: _targetVersion = "v1"; break; case RestTargetVersion.v2: diff --git a/src/FMData/ConnectionInfo.cs b/src/FMData/ConnectionInfo.cs index 856c204..8f08e5e 100644 --- a/src/FMData/ConnectionInfo.cs +++ b/src/FMData/ConnectionInfo.cs @@ -21,6 +21,10 @@ public class ConnectionInfo /// Password to use when making the connection. /// public string Password { get; set; } + /// + /// Gets or sets the to use. + /// + public RestTargetVersion? RestTargetVersion { get; set; } #region FileMaker Cloud diff --git a/tests/FMData.Rest.Tests/GeneralTests.cs b/tests/FMData.Rest.Tests/GeneralTests.cs index 0392deb..01a3818 100644 --- a/tests/FMData.Rest.Tests/GeneralTests.cs +++ b/tests/FMData.Rest.Tests/GeneralTests.cs @@ -265,24 +265,12 @@ private IEnumerable CreateEndpointTestClients(RestTargetVer var file = "test-file"; var user = "unit"; var pass = "test"; - var connectionInfo = new ConnectionInfo { FmsUri = server, Database = file, Username = user, Password = pass }; + var connectionInfo = new ConnectionInfo { FmsUri = server, Database = file, Username = user, Password = pass, RestTargetVersion = targetVersion }; - if (targetVersion != null) - { - return new List(){ - new(server, file, user, pass, targetVersion.Value), - new(mockHttp.ToHttpClient(), connectionInfo, targetVersion.Value), - new(mockHttp.ToHttpClient(), new DefaultAuthTokenProvider(connectionInfo), targetVersion.Value) - }; - } - else - { - return new List(){ - new(server, file, user, pass), - new(mockHttp.ToHttpClient(), connectionInfo), - new(mockHttp.ToHttpClient(), new DefaultAuthTokenProvider(connectionInfo)) - }; - } + return [ + new(mockHttp.ToHttpClient(), connectionInfo), + new(mockHttp.ToHttpClient(), new DefaultAuthTokenProvider(connectionInfo)) + ]; } } }