Class: Rack::ApiKeyLimit::Hourly

Inherits:
Base
  • Object
show all
Defined in:
lib/rack_api_key_limit/hourly.rb

Instance Method Summary collapse

Methods inherited from Base

#allowed?, #cache, #call, #has_param?, #http_error, #http_status, #initialize, #not_rate_limited, #options, #param, #param_name, #rate_limit_exceeded, #rate_limit_headers, #remaining, #request_count, #request_limit

Constructor Details

This class inherits a constructor from Rack::ApiKeyLimit::Base

Instance Method Details

#get_key(request, counter) ⇒ Object



4
5
6
7
# File 'lib/rack_api_key_limit/hourly.rb', line 4

def get_key(request, counter)
  api_key = param(request)
  "#{param_name}-rate-limit:#{api_key}-#{Time.now.hour}"
end

#limit_secondsObject



9
10
11
# File 'lib/rack_api_key_limit/hourly.rb', line 9

def limit_seconds
  3600
end

#retry_afterObject



13
14
15
# File 'lib/rack_api_key_limit/hourly.rb', line 13

def retry_after
  retry_after_seconds(Time.now, limit_seconds)        
end

#retry_after_seconds(time_now, period_seconds) ⇒ Object



17
18
19
20
# File 'lib/rack_api_key_limit/hourly.rb', line 17

def retry_after_seconds(time_now, period_seconds)
  seconds_since_midnight = time_now.to_i % 86400
  (period_seconds - seconds_since_midnight % period_seconds)
end