Class: TocDoc::Middleware::RateLimiter Private
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- TocDoc::Middleware::RateLimiter
- Defined in:
- lib/toc_doc/http/middleware/rate_limiter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Faraday middleware that enforces a client-side rate limit via a RateLimiter::TokenBucket.
Placed between the retry middleware and the JSON middleware so each retry attempt is individually rate-limited.
Instance Method Summary collapse
-
#call(env) ⇒ Faraday::Response
private
Acquires a token before forwarding the request downstream.
-
#initialize(app, bucket:) ⇒ RateLimiter
constructor
private
A new instance of RateLimiter.
Constructor Details
#initialize(app, bucket:) ⇒ RateLimiter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RateLimiter.
19 20 21 22 |
# File 'lib/toc_doc/http/middleware/rate_limiter.rb', line 19 def initialize(app, bucket:) super(app) @bucket = bucket end |
Instance Method Details
#call(env) ⇒ Faraday::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Acquires a token before forwarding the request downstream.
28 29 30 31 |
# File 'lib/toc_doc/http/middleware/rate_limiter.rb', line 28 def call(env) @bucket.acquire @app.call(env) end |