Class: StraightServer::Throttler
- Inherits:
-
Object
- Object
- StraightServer::Throttler
- Defined in:
- lib/straight-server/throttler.rb
Instance Method Summary collapse
-
#deny?(ip) ⇒ Boolean|Nil
True if request should be rejected, false if request should be served,.
-
#initialize(gateway_id) ⇒ Throttler
constructor
A new instance of Throttler.
Constructor Details
#initialize(gateway_id) ⇒ Throttler
Returns a new instance of Throttler.
4 5 6 7 8 9 10 |
# File 'lib/straight-server/throttler.rb', line 4 def initialize(gateway_id) @id = "gateway_#{gateway_id}" @redis = StraightServer.redis_connection @limit = Config[:'throttle.requests_limit'].to_i @period = Config[:'throttle.period'].to_i # in seconds @ip_ban_duration = Config[:'throttle.ip_ban_duration'].to_i # in seconds end |
Instance Method Details
#deny?(ip) ⇒ Boolean|Nil
Returns true if request should be rejected, false if request should be served,.
15 16 17 |
# File 'lib/straight-server/throttler.rb', line 15 def deny?(ip) banned?(ip) || throttled?(ip) end |