Class: Aikido::Zen::RuntimeSettings::RateLimitSettings
- Inherits:
-
Object
- Object
- Aikido::Zen::RuntimeSettings::RateLimitSettings
- Defined in:
- lib/aikido/zen/runtime_settings/rate_limit_settings.rb
Overview
Simple data object that holds the configuration for rate limiting a given endpoint.
Instance Attribute Summary collapse
- #max_requests ⇒ Integer readonly
-
#period ⇒ Integer
readonly
The fixed window to bucket requests in, in seconds.
Class Method Summary collapse
-
.disabled ⇒ Aikido::Zen::RuntimeSettings::RateLimitSettings
Initializes a disabled object that we can use as a default value for endpoints that have not configured rate limiting.
-
.from_json(data) ⇒ Aikido::Zen::RateLimitSettings
Initialize the settings from an API response.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(enabled: false, max_requests: 1000, period: 60) ⇒ RateLimitSettings
constructor
A new instance of RateLimitSettings.
Constructor Details
#initialize(enabled: false, max_requests: 1000, period: 60) ⇒ RateLimitSettings
Returns a new instance of RateLimitSettings.
37 38 39 40 41 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 37 def initialize(enabled: false, max_requests: 1000, period: 60) @enabled = enabled @period = period @max_requests = max_requests end |
Instance Attribute Details
#max_requests ⇒ Integer (readonly)
35 36 37 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 35 def max_requests @max_requests end |
#period ⇒ Integer (readonly)
Returns the fixed window to bucket requests in, in seconds.
32 33 34 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 32 def period @period end |
Class Method Details
.disabled ⇒ Aikido::Zen::RuntimeSettings::RateLimitSettings
Initializes a disabled object that we can use as a default value for endpoints that have not configured rate limiting.
27 28 29 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 27 def self.disabled new(enabled: false) end |
.from_json(data) ⇒ Aikido::Zen::RateLimitSettings
Initialize the settings from an API response.
15 16 17 18 19 20 21 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 15 def self.from_json(data) new( enabled: !!data["enabled"], max_requests: Integer(data["maxRequests"]), period: Integer(data["windowSizeInMS"]) / 1000 ) end |
Instance Method Details
#enabled? ⇒ Boolean
43 44 45 |
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 43 def enabled? @enabled end |