platform/lib/src/rate_limiting_window.dart

36 lines
1.2 KiB
Dart
Raw Normal View History

2019-08-14 18:52:21 +00:00
/// A representation of the abstract "rate-limiting window" in which
/// a [user] is accessing some API or endpoint.
class RateLimitingWindow<User> {
/// The user who is accessing the endpoint.
final User user;
/// The time at which the user's current window began.
final DateTime start;
2019-08-14 19:17:20 +00:00
/// The number of points the user has already consumed within
2019-08-14 18:52:21 +00:00
/// the current window.
2019-08-14 19:17:20 +00:00
final int pointsConsumed;
2019-08-14 18:52:21 +00:00
2019-08-14 19:14:47 +00:00
/// The maximum amount of points allowed within a single window.
2019-08-14 19:38:09 +00:00
///
/// This field is typically only set by the [RateLimiter] middleware,
/// and is therefore optional in the constructor.
2019-08-14 19:14:47 +00:00
final int pointLimit;
/// The amount of points the user can consume before hitting the
/// rate limit for the current window.
2019-08-14 19:38:09 +00:00
///
/// This field is typically only set by the [RateLimiter] middleware,
/// and is therefore optional in the constructor.
2019-08-14 19:14:47 +00:00
final int remainingPoints;
/// The time at which the window will reset.
2019-08-14 19:38:09 +00:00
///
/// This field is typically only set by the [RateLimiter] middleware,
/// and is therefore optional in the constructor.
2019-08-14 19:14:47 +00:00
final DateTime resetsAt;
2019-08-14 19:17:20 +00:00
RateLimitingWindow(this.user, this.start, this.pointsConsumed,
2019-08-14 19:14:47 +00:00
{this.pointLimit, this.remainingPoints, this.resetsAt});
2019-08-14 18:52:21 +00:00
}