Skip to content

are you interested in adding a ratelimit behavior? #15

Open
@dreyks

Description

@dreyks

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 into MonoBank.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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions