Skip to content

Commit

Permalink
Make ApiRateLimits properties nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Aug 19, 2024
1 parent 5863063 commit 8e4477c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="docs/static/img/nordigen-api-client-logo.png" width="30%">
<img src="https://raw.githubusercontent.com/RobinTTY/NordigenApiClient/main/docs/static/img/nordigen-api-client-logo.png" width="30%">
</p>

# NordigenApiClient
Expand Down
36 changes: 18 additions & 18 deletions docs/docs/api-reference/responses/api-rate-limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ The `ApiRateLimits` class represents the rate limits of the GoCardless API.

### `RequestLimit` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the maximum number of allowed requests within the defined time window.
Indicates the maximum number of allowed requests within the defined time window. Usually populated in every response.

### `RemainingRequests` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the number of remaining requests you can make in the current time window.
Indicates the number of remaining requests you can make in the current time window. Usually populated in every response.

### `RemainingSecondsInTimeWindow` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the time remaining in the current time window (in seconds).
Indicates the time remaining in the current time window (in seconds). Usually populated in every response.

### `RequestLimitAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the maximum number of allowed requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) within the defined time window.
Indicates the maximum number of allowed requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) within the defined time window. Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

### `RemainingRequestsAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the number of remaining requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) you can make in the current time window.
Indicates the number of remaining requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) you can make in the current time window. Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

### `RemainingSecondsInTimeWindowAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)

Indicates the time remaining in the current time window (in seconds) for requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).
Indicates the time remaining in the current time window (in seconds) for requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint). Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

## Constructor

Expand All @@ -39,26 +39,26 @@ public ApiRateLimits(int requestLimit, int remainingRequests, int remainingTimeI

### Parameters

#### `requestLimit` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `requestLimit` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the maximum number of allowed requests within the defined time window.
Indicates the maximum number of allowed requests within the defined time window. Usually populated in every response.

#### `remainingRequests` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `remainingRequests` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the number of remaining requests you can make in the current time window.
Indicates the number of remaining requests you can make in the current time window. Usually populated in every response.

#### `remainingSecondsInTimeWindow` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `remainingSecondsInTimeWindow` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the time remaining in the current time window (in seconds).
Indicates the time remaining in the current time window (in seconds). Usually populated in every response.

#### `requestLimitAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `requestLimitAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the maximum number of allowed requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) within the defined time window.
Indicates the maximum number of allowed requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) within the defined time window. Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

#### `remainingRequestsAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `remainingRequestsAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the number of remaining requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) you can make in the current time window.
Indicates the number of remaining requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint) you can make in the current time window. Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

#### `remainingSecondsInTimeWindowAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)
#### `remainingSecondsInTimeWindowAccountsEndpoint` - [int](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-int32)?

Indicates the time remaining in the current time window (in seconds) for requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).
Indicates the time remaining in the current time window (in seconds) for requests to the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint). Only populated in responses from the [AccountsEndpoint](/docs/api-reference/endpoints/accounts-endpoint).

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 28 additions & 23 deletions src/RobinTTY.NordigenApiClient/Models/Responses/ApiRateLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,34 @@ public class ApiRateLimits
{
/// <summary>
/// Indicates the maximum number of allowed requests within the defined time window.
/// Usually populated in every response.
/// </summary>
public int RequestLimit { get; set; }
public int? RequestLimit { get; set; }
/// <summary>
/// Indicates the number of remaining requests you can make in the current time window.
/// Usually populated in every response.
/// </summary>
public int RemainingRequests { get; set; }
public int? RemainingRequests { get; set; }
/// <summary>
/// Indicates the time remaining in the current time window (in seconds).
/// Usually populated in every response.
/// </summary>
public int RemainingSecondsInTimeWindow { get; set; }
public int? RemainingSecondsInTimeWindow { get; set; }
/// <summary>
/// Indicates the maximum number of allowed requests to the <see cref="AccountsEndpoint"/>
/// within the defined time window.
/// within the defined time window. Only populated in responses from the <see cref="AccountsEndpoint"/>.
/// </summary>
public int RequestLimitAccountsEndpoint { get; set; }
public int? RequestLimitAccountsEndpoint { get; set; }
/// <summary>
/// Indicates the number of remaining requests to the <see cref="AccountsEndpoint"/>
/// you can make in the current time window.
/// you can make in the current time window. Only populated in responses from the <see cref="AccountsEndpoint"/>.
/// </summary>
public int RemainingRequestsAccountsEndpoint { get; set; }
public int? RemainingRequestsAccountsEndpoint { get; set; }
/// <summary>
/// Indicates the time remaining in the current time window (in seconds) for requests
/// to the <see cref="AccountsEndpoint"/>.
/// to the <see cref="AccountsEndpoint"/>. Only populated in responses from the <see cref="AccountsEndpoint"/>.
/// </summary>
public int RemainingSecondsInTimeWindowAccountsEndpoint { get; set; }
public int? RemainingSecondsInTimeWindowAccountsEndpoint { get; set; }

/// <summary>
/// Creates a new instance of <see cref="ApiRateLimits" />.
Expand All @@ -48,8 +51,8 @@ public class ApiRateLimits
/// you can make in the current time window.</param>
/// <param name="remainingSecondsInTimeWindowAccountsEndpoint">Indicates the time remaining in the current time window (in seconds) for requests
/// to the <see cref="AccountsEndpoint"/>.</param>
public ApiRateLimits(int requestLimit, int remainingRequests, int remainingSecondsInTimeWindow, int requestLimitAccountsEndpoint,
int remainingRequestsAccountsEndpoint, int remainingSecondsInTimeWindowAccountsEndpoint)
public ApiRateLimits(int? requestLimit, int? remainingRequests, int? remainingSecondsInTimeWindow, int? requestLimitAccountsEndpoint,
int? remainingRequestsAccountsEndpoint, int? remainingSecondsInTimeWindowAccountsEndpoint)
{
RequestLimit = requestLimit;
RemainingRequests = remainingRequests;
Expand All @@ -65,18 +68,20 @@ public ApiRateLimits(int requestLimit, int remainingRequests, int remainingSecon
/// <param name="headers">The headers of the HTTP response containing the rate limit information.</param>
public ApiRateLimits(HttpHeaders headers)
{
headers.TryGetValues("HTTP_X_RATELIMIT_LIMIT", out var requestLimitInTimeWindow);
headers.TryGetValues("HTTP_X_RATELIMIT_REMAINING", out var remainingRequestsInTimeWindow);
headers.TryGetValues("HTTP_X_RATELIMIT_RESET", out var remainingTimeInTimeWindow);
headers.TryGetValues("HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_LIMIT", out var maxAccountRequestsInTimeWindow);
headers.TryGetValues("HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_REMAINING", out var remainingAccountRequestsInTimeWindow);
headers.TryGetValues("HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_RESET", out var remainingTimeInAccountTimeWindow);
RequestLimit = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_LIMIT");
RemainingRequests = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_REMAINING");
RemainingSecondsInTimeWindow = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_RESET");
RequestLimitAccountsEndpoint = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_LIMIT");
RemainingRequestsAccountsEndpoint = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_REMAINING");
RemainingSecondsInTimeWindowAccountsEndpoint = TryParseApiLimit(headers, "HTTP_X_RATELIMIT_ACCOUNT_SUCCESS_RESET");
}

RequestLimit = requestLimitInTimeWindow != null ? int.Parse(requestLimitInTimeWindow.First()) : 0;
RemainingRequests = remainingRequestsInTimeWindow != null ? int.Parse(remainingRequestsInTimeWindow.First()) : 0;
RemainingSecondsInTimeWindow = remainingTimeInTimeWindow != null ? int.Parse(remainingTimeInTimeWindow.First()) : 0;
RequestLimitAccountsEndpoint = maxAccountRequestsInTimeWindow != null ? int.Parse(maxAccountRequestsInTimeWindow.First()) : 0;
RemainingRequestsAccountsEndpoint = remainingAccountRequestsInTimeWindow != null ? int.Parse(remainingAccountRequestsInTimeWindow.First()) : 0;
RemainingSecondsInTimeWindowAccountsEndpoint = remainingTimeInAccountTimeWindow != null ? int.Parse(remainingTimeInAccountTimeWindow.First()) : 0;
private static int? TryParseApiLimit(HttpHeaders headers, string headerName)
{
headers.TryGetValues(headerName, out var values);
var firstHeaderValue = values?.FirstOrDefault();
var parseSuccess = int.TryParse(firstHeaderValue, out var limitValue);

return parseSuccess ? limitValue : null;
}
}

0 comments on commit 8e4477c

Please sign in to comment.