# Nexaas::Throttle [![Build Status](https://travis-ci.org/myfreecomm/nexaas-throttle.svg?branch=master)](https://travis-ci.org/myfreecomm/nexaas-throttle) [![Test Coverage](https://codeclimate.com/github/myfreecomm/nexaas-throttle/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/nexaas-throttle/coverage) [![Code Climate](https://codeclimate.com/github/myfreecomm/nexaas-throttle/badges/gpa.svg)](https://codeclimate.com/github/myfreecomm/nexaas-throttle) A configurable Rails engine that provides a common way of reducing API abuse, throttling consumers' requests and blocking undesired pentesters and robots. ## Installation Add this line to your application's Gemfile: ```ruby gem 'nexaas-throttle' ``` And then execute: $ bundle Or install it yourself as: $ gem install nexaas-throttle ## Usage In a Rails initializer file such as `config/initializers/nexaas_throttle.rb`, put something like this: ```ruby require "nexaas/throttle" Nexaas::Throttle.configure do |config| config.throttle = true config.track = true config.period = 1.minute config.limit = 2 config.request_identifier = MyRequestIdentifier config.redis_options = { host: "localhost", port: 6379, db: 0, namespace: "nexaas:throttle" } config.ignored_user_agents = [/[Gg]oogle/, /Amazon/] end ``` ### Configuration
Option | Description | Default |
---|---|---|
throttle |
Whether or not requests are throttled. | true |
track |
Whether or not requests are tracked. | true |
period |
The size of the throttle window. | 1 minute |
limit |
How many requests a consumer can do during a window until he starts being throttled. | 60 requests |
request_identifier |
The class that will handle request identification. See Request Identification for more details. | nil |
redis_options |
Redis hash configuration where requests counters are persisted. |
{ host: "localhost", port: 6379, db: 0, namespace: "nexaas:throttle" } |
ignored_user_agents |
Ignores how many User-Agent the application wants, in case of other applications from the same organization. | nil |