Skip to content

Commit

Permalink
Create an interface for NordigenClient
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Feb 21, 2024
1 parent 3b7be99 commit 788abef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 45 deletions.
60 changes: 60 additions & 0 deletions src/RobinTTY.NordigenApiClient/INordigenClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using RobinTTY.NordigenApiClient.Endpoints;
using RobinTTY.NordigenApiClient.Models.Jwt;

namespace RobinTTY.NordigenApiClient;

/// <summary>
/// Client used to access the Nordigen API endpoints.
/// </summary>
public interface INordigenClient
{
/// <summary>
/// A pair consisting of access/refresh token used to authenticate with the Nordigen API.
/// </summary>
JsonWebTokenPair? JsonWebTokenPair { get; set; }

/// <summary>
/// Provides support for the API operations of the tokens endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
TokenEndpoint TokenEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the institutions endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
InstitutionsEndpoint InstitutionsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the agreements endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
AgreementsEndpoint AgreementsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the requisitions endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
RequisitionsEndpoint RequisitionsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the accounts endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
AccountsEndpoint AccountsEndpoint { get; }

/// <summary>
/// Occurs whenever the <see cref="NordigenClient.JsonWebTokenPair" /> is updated.
/// </summary>
event EventHandler<TokenPairUpdatedEventArgs>? TokenPairUpdated;
}
53 changes: 11 additions & 42 deletions src/RobinTTY.NordigenApiClient/NordigenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,34 @@

namespace RobinTTY.NordigenApiClient;

/// <summary>
/// Client used to access the Nordigen API endpoints.
/// </summary>
public class NordigenClient
/// <inheritdoc />
public class NordigenClient : INordigenClient
{
private static readonly SemaphoreSlim TokenSemaphore = new(1, 1);
private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _serializerOptions;
internal readonly NordigenClientCredentials Credentials;

/// <summary>
/// A pair consisting of access/refresh token used to authenticate with the Nordigen API.
/// </summary>
/// <inheritdoc />
public JsonWebTokenPair? JsonWebTokenPair { get; set; }

/// <summary>
/// Provides support for the API operations of the tokens endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
/// <inheritdoc />
public TokenEndpoint TokenEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the institutions endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
/// <inheritdoc />
public InstitutionsEndpoint InstitutionsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the agreements endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
/// <inheritdoc />
public AgreementsEndpoint AgreementsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the requisitions endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
/// <inheritdoc />
public RequisitionsEndpoint RequisitionsEndpoint { get; }

/// <summary>
/// Provides support for the API operations of the accounts endpoint.
/// <para>
/// Reference: <a href="https://developer.gocardless.com/bank-account-data/endpoints">GoCardless Documentation</a>
/// </para>
/// </summary>
/// <inheritdoc />
public AccountsEndpoint AccountsEndpoint { get; }

/// <inheritdoc />
public event EventHandler<TokenPairUpdatedEventArgs>? TokenPairUpdated;

/// <summary>
/// Creates a new instance of <see cref="NordigenClient" />.
Expand Down Expand Up @@ -91,11 +65,6 @@ public NordigenClient(HttpClient httpClient, NordigenClientCredentials credentia
AccountsEndpoint = new AccountsEndpoint(this);
}

/// <summary>
/// Occurs whenever the <see cref="JsonWebTokenPair" /> is updated.
/// </summary>
public event EventHandler<TokenPairUpdatedEventArgs>? TokenPairUpdated;

internal async Task<NordigenApiResponse<TResponse, TError>> MakeRequest<TResponse, TError>(
string uri,
HttpMethod method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageTags>Nordigen; API; client</PackageTags>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/release-notes.txt"))</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>6.1.3</Version>
<Version>6.2.0</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/RobinTTY.NordigenApiClient/release-notes.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 788abef

Please sign in to comment.