Class: StraightServer::Throttler

Inherits:
Object
  • Object
show all
Defined in:
lib/straight-server/throttler.rb

Instance Method Summary collapse

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,.

Parameters:

Returns:

  • (Boolean|Nil)

    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