Class: Nexaas::Throttle::Configuration
- Inherits:
-
Object
- Object
- Nexaas::Throttle::Configuration
- Defined in:
- lib/nexaas/throttle/configuration.rb
Instance Attribute Summary collapse
-
#ignored_user_agents ⇒ Array
Ignores how many User-Agent the application wants, in case of other applications from the same organization.
-
#limit ⇒ Integer
How many requests a consumer can do during a window until he starts being throttled.
-
#period ⇒ Integer
The size of the throttle window.
-
#redis_options ⇒ Hash
Redis hash configuration with the following default values: - host => localhost - port => 6379 - db => 0 - namespace => nexaas:throttle.
-
#request_identifier ⇒ Class
The class that will handle request identification.
-
#throttle ⇒ Boolean
(also: #throttleable?)
Whether or not requests are throttled.
-
#track ⇒ Boolean
(also: #trackable?)
Whether or not requests are tracked.
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 56 |
# File 'lib/nexaas/throttle/configuration.rb', line 48 def initialize @throttle = true @track = true @period = 1.minute @limit = 60 @request_identifier = nil @redis_options = @ignored_user_agents = nil end |
Instance Attribute Details
#ignored_user_agents ⇒ Array
Ignores how many User-Agent the application wants, in case of other applications from the same organization. Example: [/[Gg]oogle/, /Amazon/]
43 44 45 |
# File 'lib/nexaas/throttle/configuration.rb', line 43 def ignored_user_agents @ignored_user_agents end |
#limit ⇒ Integer
How many requests a consumer can do during a window until he starts being throttled. Example: 60
20 21 22 |
# File 'lib/nexaas/throttle/configuration.rb', line 20 def limit @limit end |
#period ⇒ Integer
The size of the throttle window. Example: 1.minute, 1.hour, 60(s)
15 16 17 |
# File 'lib/nexaas/throttle/configuration.rb', line 15 def period @period end |
#redis_options ⇒ Hash
Redis hash configuration with the following default values:
- host => localhost
- port => 6379
- db => 0
- namespace => nexaas:throttle
38 39 40 |
# File 'lib/nexaas/throttle/configuration.rb', line 38 def @redis_options end |
#request_identifier ⇒ Class
The class that will handle request identification. Each application handle with different domains on identifying a request, so they have to provide information on who is the requester based on their domain. This class MUST have the following interface: MyRequestIdentifier#initialize(request) MyRequestIdentifier#token Where MyRequestIdentifier#token must be a UNIQUE identifier from the requester.
30 31 32 |
# File 'lib/nexaas/throttle/configuration.rb', line 30 def request_identifier @request_identifier end |
#throttle ⇒ Boolean Also known as: throttleable?
Whether or not requests are throttled.
6 7 8 |
# File 'lib/nexaas/throttle/configuration.rb', line 6 def throttle @throttle end |
#track ⇒ Boolean Also known as: trackable?
Whether or not requests are tracked.
10 11 12 |
# File 'lib/nexaas/throttle/configuration.rb', line 10 def track @track end |
Instance Method Details
#check! ⇒ Object
58 59 60 61 62 |
# File 'lib/nexaas/throttle/configuration.rb', line 58 def check! .each do |option| raise ArgumentError, "You must provide a `#{option}` configuration." if send(option).blank? end end |