Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

limiter-ruby

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limiter-ruby

  • 0.1.15
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Limiter

Limiter.dev enables building rate limits for your application with ease. It provides a simple interface to define rate limits and track usage.

Usage

Generate API Token

Before using the gem you must register at https://limiter.dev and generate an token to interact with the api. Thereafter, add the token to app's environment variable

LIMITER_TOKEN: [GENERATED TOKEN]

Install the gem

In the Gemfile add the following

gem "limiter-ruby"

Simple Rate Limit Example

Assuming this is a Ruby on Rails app within ActiveJob

class ApiController < ApplicationController
  before_action :rate_limit

  def index
    # Good to continue
  end

  private
  def rate_limit
    rate_limit = limiter.check(user.id)

    if rate_limit.exhausted?
      render json: { error: "Rate limit exceeded" }, status: :too_many_requests
    end
  end

  def limiter
    Limiter::Client.new(token: ENV["LIMITER_TOKEN"], namespace: "openai", limit: 60, interval: 1.minute)
  end
end

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc