Class: DHC::Throttle
- Inherits:
-
Interceptor
- Object
- Interceptor
- DHC::Throttle
- Defined in:
- lib/dhc/interceptors/throttle.rb
Defined Under Namespace
Classes: OutOfQuota
Constant Summary collapse
- CACHE_KEY =
'DHC/throttle/tracker/v1'
Instance Attribute Summary
Attributes inherited from Interceptor
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Interceptor
#after_request, #all_interceptor_classes, #before_init, #before_response, dup, #initialize, #response
Constructor Details
This class inherits a constructor from DHC::Interceptor
Class Method Details
.tracker(provider) ⇒ Object
13 14 15 |
# File 'lib/dhc/interceptors/throttle.rb', line 13 def tracker(provider) (Rails.cache.read(CACHE_KEY) || {})[provider] || {} end |
Instance Method Details
#after_response ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/dhc/interceptors/throttle.rb', line 27 def after_response return unless track? self.class.tracker = { provider: .dig(:provider), limit: limit, remaining: remaining, expires: expires } end |
#before_request ⇒ Object
22 23 24 25 |
# File 'lib/dhc/interceptors/throttle.rb', line 22 def before_request return unless break! if break? end |