platform/lib/src/rate_limiting_window.dart

27 lines
852 B
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.
final int pointLimit;
/// The amount of points the user can consume before hitting the
/// rate limit for the current window.
final int remainingPoints;
/// The time at which the window will reset.
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
}