Class: Aikido::Zen::RuntimeSettings::RateLimitSettings

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_requestsInteger (readonly)

Returns:

  • (Integer)


35
36
37
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 35

def max_requests
  @max_requests
end

#periodInteger (readonly)

Returns the fixed window to bucket requests in, in seconds.

Returns:

  • (Integer)

    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

.disabledAikido::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.

Parameters:

  • data (Hash)

    the deserialized JSON data.

Options Hash (data):

  • "enabled" (Boolean)
  • "maxRequests" (Integer)
  • "windowSizeInMS" (Integer)

Returns:

  • (Aikido::Zen::RateLimitSettings)


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

Returns:

  • (Boolean)


43
44
45
# File 'lib/aikido/zen/runtime_settings/rate_limit_settings.rb', line 43

def enabled?
  @enabled
end