Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarasti committed Nov 21, 2020
1 parent 603af60 commit a436f94
Show file tree
Hide file tree
Showing 16 changed files with 3,902 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/docs/
/lib/
/bin/
/.shards/
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

# rate_limiter

This shard provides a Crystal implementation of the [token bucket](https://en.wikipedia.org/wiki/Token_bucket) algorithm for rate limiting.
This shard provides a Crystal implementation of the [token bucket](https://en.wikipedia.org/wiki/Token_bucket) algorithm for rate limiting. You can check out the API documentation [here](https://lbarasti.com/rate_limiter/).

## Installation

1. Add the dependency to your `shard.yml`:
1 - Add the dependency to your `shard.yml`:

```yaml
dependencies:
rate_limiter:
github: lbarasti/rate_limiter
```
```yaml
dependencies:
rate_limiter:
github: lbarasti/rate_limiter
```
2. Run `shards install`
2 - Run `shards install`

## Usage

Expand Down Expand Up @@ -68,6 +68,9 @@ RateLimiter.new(rate: 0.5, max_burst: 10)
```
This will generate 1 token every 2 seconds and store up to 10 unused tokens for later use. See Wikipedia's [Burst size](https://en.wikipedia.org/wiki/Token_bucket#Burst_size) for more details.

## Under the hood
![](./media/diagram_1.png)

## Why do I need a rate limiter?
* We're calling an API that throttles us when we
call it too frequently, and we'd rather avoid that.
Expand Down
291 changes: 291 additions & 0 deletions docs/RateLimiter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="generator" content="Crystal Docs 0.34.0">
<meta name="crystal_docs.project_version" content="main-dev">
<meta name="crystal_docs.project_name" content="rate_limiter">


<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/doc.js"></script>

<svg class="hidden">
<symbol id="octicon-link" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
</symbol>
</svg>

<meta id="repository-name" content="rate_limiter">
<title>RateLimiter - rate_limiter main-dev</title>
<script type="text/javascript">
CrystalDocs.base_path = "";
</script>
</head>
<body>

<div class="sidebar">
<div class="sidebar-header">
<div class="search-box">
<input type="search" class="search-input" placeholder="Search..." spellcheck="false" aria-label="Search">
</div>

<div class="project-summary">
<h1 class="project-name">
<a href="index.html">
rate_limiter
</a>
</h1>

<span class="project-version">
main-dev
</span>
</div>
</div>

<div class="search-results" class="hidden">
<ul class="search-list"></ul>
</div>

<div class="types-list">
<ul>

<li class="parent open current" data-id="rate_limiter/RateLimiter" data-name="ratelimiter">
<a href="RateLimiter.html">RateLimiter</a>

<ul>

<li class=" " data-id="rate_limiter/RateLimiter/Limiter" data-name="ratelimiter::limiter">
<a href="RateLimiter/Limiter.html">Limiter</a>

</li>

<li class=" " data-id="rate_limiter/RateLimiter/LimiterLike" data-name="ratelimiter::limiterlike">
<a href="RateLimiter/LimiterLike.html">LimiterLike</a>

</li>

<li class=" " data-id="rate_limiter/RateLimiter/MultiLimiter" data-name="ratelimiter::multilimiter">
<a href="RateLimiter/MultiLimiter.html">MultiLimiter</a>

</li>

<li class=" " data-id="rate_limiter/RateLimiter/Timeout" data-name="ratelimiter::timeout">
<a href="RateLimiter/Timeout.html">Timeout</a>

</li>

<li class=" " data-id="rate_limiter/RateLimiter/Token" data-name="ratelimiter::token">
<a href="RateLimiter/Token.html">Token</a>

</li>

</ul>


</li>

</ul>

</div>
</div>


<div class="main-content">
<h1 class="type-name">

<span class="kind">module</span> RateLimiter

</h1>





<h2>
<a id="overview" class="anchor" href="#overview">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Overview
</h2>

<p>Rate limiting functionality.</p>














<h2>
<a id="defined-in" class="anchor" href="#defined-in">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Defined in:
</h2>





<h2>
<a id="constant-summary" class="anchor" href="#constant-summary">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Constant Summary
</h2>

<dl>

<dt class="entry-const" id="VERSION">
<strong>VERSION</strong> = <code><span class="s">&quot;1.0.0&quot;</span></code>
</dt>


</dl>



<h2>
<a id="constructors" class="anchor" href="#constructors">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Constructors
</h2>
<ul class="list-summary">

<li class="entry-summary">
<a href="#new(rate:Float64,max_burst:Int32=1)-class-method" class="signature"><strong>.new</strong>(rate : Float64, max_burst : Int32 = <span class="n">1</span>)</a>

<div class="summary"><p>Creates a new <code><a href="RateLimiter/Limiter.html">Limiter</a></code>.</p></div>

</li>

<li class="entry-summary">
<a href="#new(interval:Time::Span,max_burst:Int32=1)-class-method" class="signature"><strong>.new</strong>(interval : Time::Span, max_burst : Int32 = <span class="n">1</span>)</a>

<div class="summary"><p>Creates a new <code><a href="RateLimiter/Limiter.html">Limiter</a></code>.</p></div>

</li>

<li class="entry-summary">
<a href="#new(*limiters:Limiter)-class-method" class="signature"><strong>.new</strong>(*limiters : Limiter)</a>

<div class="summary"><p>Creates a <code><a href="RateLimiter/MultiLimiter.html">MultiLimiter</a></code>.</p></div>

</li>

</ul>









<div class="methods-inherited">

</div>


<h2>
<a id="constructor-detail" class="anchor" href="#constructor-detail">
<svg class="octicon-link" aria-hidden="true">
<use href="#octicon-link"/>
</svg>
</a>
Constructor Detail
</h2>

<div class="entry-detail" id="new(rate:Float64,max_burst:Int32=1)-class-method">
<div class="signature">

def self.<strong>new</strong>(rate : Float64, max_burst : Int32 = <span class="n">1</span>)

<a class="method-permalink" href="#new(rate:Float64,max_burst:Int32=1)-class-method">#</a>
</div>

<div class="doc">

<p>Creates a new <code><a href="RateLimiter/Limiter.html">Limiter</a></code>.
<code>rate</code>: the rate of tokens being produced in tokens/second.
<code>max_burst</code>: maximum number of tokens that can be stored in the bucket.</p>
</div>

<br/>
<div>

</div>
</div>

<div class="entry-detail" id="new(interval:Time::Span,max_burst:Int32=1)-class-method">
<div class="signature">

def self.<strong>new</strong>(interval : Time::Span, max_burst : Int32 = <span class="n">1</span>)

<a class="method-permalink" href="#new(interval:Time::Span,max_burst:Int32=1)-class-method">#</a>
</div>

<div class="doc">

<p>Creates a new <code><a href="RateLimiter/Limiter.html">Limiter</a></code>.
<code>interval</code>: the interval at which new tokens are generated.
<code>max_burst</code>: maximum number of tokens that can be stored in the bucket.</p>
</div>

<br/>
<div>

</div>
</div>

<div class="entry-detail" id="new(*limiters:Limiter)-class-method">
<div class="signature">

def self.<strong>new</strong>(*limiters : <a href="RateLimiter/Limiter.html">Limiter</a>)

<a class="method-permalink" href="#new(*limiters:Limiter)-class-method">#</a>
</div>

<div class="doc">

<p>Creates a <code><a href="RateLimiter/MultiLimiter.html">MultiLimiter</a></code>.
<code>limiters</code>: a set of rate limiters.</p>
</div>

<br/>
<div>

</div>
</div>









</div>

</body>
</html>
Loading

0 comments on commit a436f94

Please sign in to comment.