Skip to content

Commit

Permalink
Moved target version to connection info object
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelL79 committed Dec 6, 2024
1 parent c86f604 commit 4b5446f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
18 changes: 7 additions & 11 deletions src/FMData.Rest/FileMakerRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,25 @@ public class FileMakerRestClient : FileMakerApiClientBase, IFileMakerRestClient
/// <param name="targetVersion">Version of the DataAPI endpoint to use. Default is v1.</param>
[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 }) { }

/// <summary>
/// FM Data Constructor with HttpClient and ConnectionInfo. Useful for Dependency Injection situations.
/// </summary>
/// <param name="client">The HttpClient instance to use.</param>
/// <param name="conn">The connection information for FMS.</param>
/// <param name="targetVersion">Version of the DataAPI endpoint to use. Default is v1.</param>
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))
{ }

/// <summary>
/// FM Data Constructor with HttpClient, ConnectionInfo and an authentication provider. Useful for Dependency Injection situations.
/// </summary>
/// <param name="client">The HttpClient instance to use.</param>
/// <param name="authTokenProvider">Authentication provider</param>
/// <param name="targetVersion">Version of the DataAPI endpoint to use. Default is v1.</param>
public FileMakerRestClient(
HttpClient client,
IAuthTokenProvider authTokenProvider,
RestTargetVersion targetVersion = RestTargetVersion.v1) : this(client, authTokenProvider, false, targetVersion)
IAuthTokenProvider authTokenProvider) : this(client, authTokenProvider, false)
{ }

/// <summary>
Expand All @@ -95,19 +92,18 @@ public FileMakerRestClient(
/// <param name="client">The HttpClient instance to use.</param>
/// <param name="authTokenProvider">Authentication provider</param>
/// <param name="useNewClientForContainers">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.</param>
/// <param name="targetVersion">Version of the DataAPI endpoint to use. Default is v1.</param>
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:
Expand Down
4 changes: 4 additions & 0 deletions src/FMData/ConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class ConnectionInfo
/// Password to use when making the connection.
/// </summary>
public string Password { get; set; }
/// <summary>
/// Gets or sets the <see cref="RestTargetVersion"/> to use.
/// </summary>
public RestTargetVersion? RestTargetVersion { get; set; }

#region FileMaker Cloud

Expand Down
22 changes: 5 additions & 17 deletions tests/FMData.Rest.Tests/GeneralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,12 @@ private IEnumerable<FileMakerRestClient> 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<FileMakerRestClient>(){
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<FileMakerRestClient>(){
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))
];
}
}
}

0 comments on commit 4b5446f

Please sign in to comment.