This commit is contained in:
Toks
2014-06-01 13:39:19 -04:00
parent b13d89e982
commit e1f09e01b0
2 changed files with 21 additions and 3 deletions

View File

@@ -4,6 +4,12 @@ module ApiLimiter
MEMCACHE.fetch(key, 1.hour, :raw => true) {0}
MEMCACHE.incr(key).to_i > CurrentUser.user.api_hourly_limit
end
def remaining_hourly_limit(ip_addr)
key = "#{ip_addr}:#{Time.now.hour}"
requests = MEMCACHE.fetch(key, 1.hour, :raw => true) {0}.to_i
CurrentUser.user.api_hourly_limit - requests
end
module_function :throttled?
module_function :throttled?, :remaining_hourly_limit
end