From 788abef8a94e0dc475e9dda5e94928b7ec1c0727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Wed, 21 Feb 2024 10:57:21 +0100 Subject: [PATCH] Create an interface for NordigenClient --- .../INordigenClient.cs | 60 +++++++++++++++++++ .../NordigenClient.cs | 53 ++++------------ .../RobinTTY.NordigenApiClient.csproj | 2 +- .../release-notes.txt | 3 +- 4 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 src/RobinTTY.NordigenApiClient/INordigenClient.cs diff --git a/src/RobinTTY.NordigenApiClient/INordigenClient.cs b/src/RobinTTY.NordigenApiClient/INordigenClient.cs new file mode 100644 index 0000000..122e7c7 --- /dev/null +++ b/src/RobinTTY.NordigenApiClient/INordigenClient.cs @@ -0,0 +1,60 @@ +using RobinTTY.NordigenApiClient.Endpoints; +using RobinTTY.NordigenApiClient.Models.Jwt; + +namespace RobinTTY.NordigenApiClient; + +/// +/// Client used to access the Nordigen API endpoints. +/// +public interface INordigenClient +{ + /// + /// A pair consisting of access/refresh token used to authenticate with the Nordigen API. + /// + JsonWebTokenPair? JsonWebTokenPair { get; set; } + + /// + /// Provides support for the API operations of the tokens endpoint. + /// + /// Reference: GoCardless Documentation + /// + /// + TokenEndpoint TokenEndpoint { get; } + + /// + /// Provides support for the API operations of the institutions endpoint. + /// + /// Reference: GoCardless Documentation + /// + /// + InstitutionsEndpoint InstitutionsEndpoint { get; } + + /// + /// Provides support for the API operations of the agreements endpoint. + /// + /// Reference: GoCardless Documentation + /// + /// + AgreementsEndpoint AgreementsEndpoint { get; } + + /// + /// Provides support for the API operations of the requisitions endpoint. + /// + /// Reference: GoCardless Documentation + /// + /// + RequisitionsEndpoint RequisitionsEndpoint { get; } + + /// + /// Provides support for the API operations of the accounts endpoint. + /// + /// Reference: GoCardless Documentation + /// + /// + AccountsEndpoint AccountsEndpoint { get; } + + /// + /// Occurs whenever the is updated. + /// + event EventHandler? TokenPairUpdated; +} \ No newline at end of file diff --git a/src/RobinTTY.NordigenApiClient/NordigenClient.cs b/src/RobinTTY.NordigenApiClient/NordigenClient.cs index 76ec602..3a46754 100644 --- a/src/RobinTTY.NordigenApiClient/NordigenClient.cs +++ b/src/RobinTTY.NordigenApiClient/NordigenClient.cs @@ -8,60 +8,34 @@ namespace RobinTTY.NordigenApiClient; -/// -/// Client used to access the Nordigen API endpoints. -/// -public class NordigenClient +/// +public class NordigenClient : INordigenClient { private static readonly SemaphoreSlim TokenSemaphore = new(1, 1); private readonly HttpClient _httpClient; private readonly JsonSerializerOptions _serializerOptions; internal readonly NordigenClientCredentials Credentials; - /// - /// A pair consisting of access/refresh token used to authenticate with the Nordigen API. - /// + /// public JsonWebTokenPair? JsonWebTokenPair { get; set; } - /// - /// Provides support for the API operations of the tokens endpoint. - /// - /// Reference: GoCardless Documentation - /// - /// + /// public TokenEndpoint TokenEndpoint { get; } - /// - /// Provides support for the API operations of the institutions endpoint. - /// - /// Reference: GoCardless Documentation - /// - /// + /// public InstitutionsEndpoint InstitutionsEndpoint { get; } - /// - /// Provides support for the API operations of the agreements endpoint. - /// - /// Reference: GoCardless Documentation - /// - /// + /// public AgreementsEndpoint AgreementsEndpoint { get; } - /// - /// Provides support for the API operations of the requisitions endpoint. - /// - /// Reference: GoCardless Documentation - /// - /// + /// public RequisitionsEndpoint RequisitionsEndpoint { get; } - /// - /// Provides support for the API operations of the accounts endpoint. - /// - /// Reference: GoCardless Documentation - /// - /// + /// public AccountsEndpoint AccountsEndpoint { get; } + + /// + public event EventHandler? TokenPairUpdated; /// /// Creates a new instance of . @@ -91,11 +65,6 @@ public NordigenClient(HttpClient httpClient, NordigenClientCredentials credentia AccountsEndpoint = new AccountsEndpoint(this); } - /// - /// Occurs whenever the is updated. - /// - public event EventHandler? TokenPairUpdated; - internal async Task> MakeRequest( string uri, HttpMethod method, diff --git a/src/RobinTTY.NordigenApiClient/RobinTTY.NordigenApiClient.csproj b/src/RobinTTY.NordigenApiClient/RobinTTY.NordigenApiClient.csproj index 81ad625..200d8ee 100644 --- a/src/RobinTTY.NordigenApiClient/RobinTTY.NordigenApiClient.csproj +++ b/src/RobinTTY.NordigenApiClient/RobinTTY.NordigenApiClient.csproj @@ -16,7 +16,7 @@ Nordigen; API; client $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/release-notes.txt")) MIT - 6.1.3 + 6.2.0 true snupkg diff --git a/src/RobinTTY.NordigenApiClient/release-notes.txt b/src/RobinTTY.NordigenApiClient/release-notes.txt index 96f18db..4cfbd2a 100644 --- a/src/RobinTTY.NordigenApiClient/release-notes.txt +++ b/src/RobinTTY.NordigenApiClient/release-notes.txt @@ -1,2 +1 @@ -- Fixed CurrencyExchange deserialization caused by inconsistent API behavior -- Allow mocking of NordigenApiResponse +- Add an interface for NordigenClient to allow easier DI and mocking