Open
Description
I plan to implement a behavior that prevents getting into the rate limit. I think it can be added to the gem as an opt-in
something like this
Monobank::Methods::Base
will wrap its calls intoMonoBank.rate_limiter.call
passing the token and the endpoint- the developer supplies the rate limiter which can track the token/endpoint combination the way it wants (redis/memory/etc)
example
class MyRateLimiter
def initialize(redis:)
@redis = redis
end
def call(token:, endpoint:)
if @redis.exists?("#{token}:#{endpoint}")
raise StandardError.new # or whatever else the developer wants
end
begin
yield # back to the calling method
ensure
@redis.set("#{token}:#{endpoint}", '', ex: 60)
end
end
end
Monobank.configure(rate_limiter: MyRateLimiter.new(redis: $redis)
Metadata
Metadata
Assignees
Labels
No labels