{"id":23249520,"url":"https://github.com/wizardone/raterr","last_synced_at":"2026-03-10T13:04:27.178Z","repository":{"id":56890993,"uuid":"105235310","full_name":"wizardone/raterr","owner":"wizardone","description":"Rate limiting for Ruby applications","archived":false,"fork":false,"pushed_at":"2021-12-14T02:51:23.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-04T18:53:48.454Z","etag":null,"topics":["cache","hash","limiter","period","rails-cache","rate","rate-limiter","ruby","visitor"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wizardone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-29T05:57:04.000Z","updated_at":"2023-03-09T04:20:02.000Z","dependencies_parsed_at":"2022-08-20T16:00:58.796Z","dependency_job_id":null,"html_url":"https://github.com/wizardone/raterr","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/wizardone/raterr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fraterr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fraterr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fraterr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fraterr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wizardone","download_url":"https://codeload.github.com/wizardone/raterr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wizardone%2Fraterr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30334412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T12:41:07.687Z","status":"ssl_error","status_checked_at":"2026-03-10T12:41:06.728Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","hash","limiter","period","rails-cache","rate","rate-limiter","ruby","visitor"],"created_at":"2024-12-19T08:19:48.010Z","updated_at":"2026-03-10T13:04:27.157Z","avatar_url":"https://github.com/wizardone.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raterr\n[![Build Status](https://travis-ci.org/wizardone/raterr.svg?branch=master)](https://travis-ci.org/wizardone/raterr)\n[![codecov](https://codecov.io/gh/wizardone/raterr/branch/master/graph/badge.svg)](https://codecov.io/gh/wizardone/raterr)\n\n`Raterr` allows you to enforce rate limiting restrictions based on ip\naddress.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'raterr'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install raterr\n\n## Usage\nFor Ruby based application you need to tell `Raterr` what store to use.\nCurrently it supports a simple hash, or `Redis`\nIt is best to load the store in an initializer of any other kind of file\nthat is loaded initially.\n```ruby\n# Use either\nRaterr.store = Hash.new\n# Or\nRaterr.store = Redis.new\n```\nTo enforce rate limiting use:\n```ruby\nRaterr.enforce(request, period: :minute, max: 200, code: 429)\n```\n`request` might be any data type that has an `ip` method. For Rails\napplications that would be the request method.\n\nThe result of `Raterr.enforce` is always a pseudo status. In case the\nrate limit has not been reached you will get a pseudo `200` status + the\nnumber of attempts made. This allows you to do additional checks (say a\nwarning if you are about to reach the threshhold). If\nit has been reached you will get whatever status you configured, or the\ndefault one, which is 429 + a text message.\n\nAn example usage in a Rails application would be:\n```ruby\nclass MyController \u003c Base::ApplicationController\n  before_action :rate_limit, only: :index\n\n  def index\n    # Do something cool\n  end\n\n  private\n\n  def rate_limit\n    result = Raterr.enforce(request, period: :minute, max: 10)\n    if result[:status] == 429\n      # Do whatever you want to do when the rate limit is reached\n      render plain: result[:text], status: result[:status] and return\n    else\n      puts \"Number of attempts: #{result[:attempts]}\"\n    end\n  end\nend\n```\nIf you want to add limiting to the whole app you would put it in an\napplication controller and so on...\n\nYou can configure the period error code and the max attempts. The allowed periods\nare: `:minute, :hour, :day`.\nThe default error code is `429`.\nThe default max attempts is `100`.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/wizardone/raterr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fraterr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwizardone%2Fraterr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwizardone%2Fraterr/lists"}