Skip to content

Commit

Permalink
add missing guards; add runtime version
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-Roberto-Mancinelli committed Dec 23, 2024
1 parent 1376533 commit 59b31ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/TrueLayer/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace TrueLayer
internal class ApiClient : IApiClient
{
private static readonly string TlAgentHeader
= $"truelayer-dotnet/{ReflectionUtils.GetAssemblyVersion<ITrueLayerClient>()}";

= $"truelayer-dotnet/{ReflectionUtils.GetAssemblyVersion<ITrueLayerClient>()} ({System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription})";
private readonly HttpClient _httpClient;
private readonly IAuthTokenCache _authTokenCache;

Expand All @@ -46,7 +45,6 @@ public async Task<ApiResponse<TData>> GetAsync<TData>(
IDictionary<string, string>? customHeaders = null,
CancellationToken cancellationToken = default)
{

using var httpResponse = await SendRequestAsync(
httpMethod: HttpMethod.Get,
uri: uri,
Expand Down
15 changes: 12 additions & 3 deletions src/TrueLayer/Payments/PaymentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public async Task<ApiResponse<AuthorizationResponseUnion>> StartAuthorizationFlo
CancellationToken cancellationToken = default)
{
paymentId.NotNullOrWhiteSpace(nameof(paymentId));
paymentId.NotAUrl(nameof(paymentId));
idempotencyKey.NotNullOrWhiteSpace(nameof(idempotencyKey));
request.NotNull(nameof(request));

Expand All @@ -135,6 +136,7 @@ public async Task<ApiResponse<CreatePaymentRefundResponse>> CreatePaymentRefund(
string idempotencyKey, CreatePaymentRefundRequest request, CancellationToken cancellationToken = default)
{
paymentId.NotNullOrWhiteSpace(nameof(paymentId));
paymentId.NotAUrl(nameof(paymentId));
request.NotNull(nameof(request));

var authResponse = await _auth.GetAuthToken(
Expand All @@ -155,10 +157,12 @@ public async Task<ApiResponse<CreatePaymentRefundResponse>> CreatePaymentRefund(
);
}

public async Task<ApiResponse<ListPaymentRefundsResponse>> ListPaymentRefunds(string paymentId,
public async Task<ApiResponse<ListPaymentRefundsResponse>> ListPaymentRefunds(
string paymentId,
CancellationToken cancellationToken = default)
{
paymentId.NotNullOrWhiteSpace(nameof(paymentId));
paymentId.NotAUrl(nameof(paymentId));

var authResponse = await _auth.GetAuthToken(
new GetAuthTokenRequest(AuthorizationScope.Payments), cancellationToken);
Expand All @@ -175,11 +179,15 @@ public async Task<ApiResponse<ListPaymentRefundsResponse>> ListPaymentRefunds(st
);
}

public async Task<ApiResponse<RefundUnion>> GetPaymentRefund(string paymentId,
string refundId, CancellationToken cancellationToken = default)
public async Task<ApiResponse<RefundUnion>> GetPaymentRefund(
string paymentId,
string refundId,
CancellationToken cancellationToken = default)
{
paymentId.NotNullOrWhiteSpace(nameof(paymentId));
paymentId.NotAUrl(nameof(paymentId));
refundId.NotNullOrWhiteSpace(nameof(refundId));
refundId.NotAUrl(nameof(refundId));

var authResponse = await _auth.GetAuthToken(
new GetAuthTokenRequest(AuthorizationScope.Payments), cancellationToken);
Expand All @@ -199,6 +207,7 @@ public async Task<ApiResponse<RefundUnion>> GetPaymentRefund(string paymentId,
public async Task<ApiResponse> CancelPayment(string paymentId, string idempotencyKey, CancellationToken cancellationToken = default)
{
paymentId.NotNullOrWhiteSpace(nameof(paymentId));
paymentId.NotAUrl(nameof(paymentId));
idempotencyKey.NotNullOrWhiteSpace(nameof(idempotencyKey));

var authResponse = await _auth.GetAuthToken(
Expand Down
2 changes: 1 addition & 1 deletion test/TrueLayer.Tests/ApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public async Task Sets_TL_agent_header()
{
_httpMessageHandler
.Expect(HttpMethod.Get, "http://localhost/user-agent")
.WithHeaders(CustomHeaders.Agent, $"truelayer-dotnet/{ReflectionUtils.GetAssemblyVersion<ApiClient>()}")
.WithHeaders(CustomHeaders.Agent, $"truelayer-dotnet/{ReflectionUtils.GetAssemblyVersion<ApiClient>()} ({System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription})")
.Respond(HttpStatusCode.OK, MediaTypeNames.Application.Json, "{}");

var response = await _apiClient.GetAsync<TestResponse>(new Uri("http://localhost/user-agent"));
Expand Down

0 comments on commit 59b31ac

Please sign in to comment.