faraday-rate_limiter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +10 -2
- data/faraday-rate_limiter.gemspec +4 -4
- data/lib/faraday/rate_limiter.rb +0 -1
- data/spec/integration/rate_limiter_spec.rb +14 -5
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f50d1628dbd510948d560f33a34c303318d2dc8
|
4
|
+
data.tar.gz: 9e150cd0e7ec8f19c28b72968c3fa98c8c89c629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba3c38e9adc1520266d57f6ffccd7de2c0fdf87ee7e02c412e9b6acdd21fce28a66e73d488c7d5d918fa09b6a94ab54353f66a33910c45e5706a5c77d65f030
|
7
|
+
data.tar.gz: 8847d9e3d1968fc6356a79118c85bb6fcfd5884920933895589851393c9a9b8c60c6bc1e32e0ac0372bf2fde1f7ba3a6ce8bd4783ca2bb723d81164e1d081e8e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/cameron-martin/faraday-rate_limiter.png?branch=master)](https://travis-ci.org/cameron-martin/faraday-rate_limiter)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/cameron-martin/faraday-rate_limiter.png)](https://codeclimate.com/github/cameron-martin/faraday-rate_limiter)
|
3
|
+
|
1
4
|
# Faraday::RateLimiter
|
2
5
|
|
3
|
-
|
6
|
+
Faraday middleware to limit the rate of requests
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -18,7 +21,12 @@ Or install it yourself as:
|
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
require 'faraday-rate_limiter'
|
25
|
+
|
26
|
+
Faraday.new do |conn|
|
27
|
+
conn.request :rate_limiter, interval: 5 # Defaults to 1 second
|
28
|
+
conn.adapter :net_http
|
29
|
+
end
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'faraday-rate_limiter'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.4'
|
8
8
|
spec.authors = ['Cameron Martin']
|
9
9
|
spec.email = ['cameronmartin123@gmail.com']
|
10
|
-
spec.description = %q{
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage = ''
|
10
|
+
spec.description = %q{Faraday middleware to limit rate of requests}
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = 'https://github.com/cameron-martin/faraday-rate_limiter'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
data/lib/faraday/rate_limiter.rb
CHANGED
@@ -8,26 +8,35 @@ describe Faraday::RateLimiter do
|
|
8
8
|
let(:interval) { 5 }
|
9
9
|
let(:conn) do
|
10
10
|
Faraday.new do |conn|
|
11
|
-
conn.request :rate_limiter, interval
|
11
|
+
conn.request :rate_limiter, :interval => interval
|
12
12
|
conn.adapter :test do |stub|
|
13
13
|
stub.get('/index') {[ 200, {}, '' ]}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'returns the first result without delay' do
|
19
19
|
t1 = Time.now
|
20
20
|
conn.get('/index')
|
21
21
|
t2 = Time.now
|
22
|
-
expect(
|
22
|
+
expect(t2 - t1).to be_within(0.1).of(0)
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'waits between requests' do
|
26
26
|
t1 = Time.now
|
27
27
|
conn.get('/index')
|
28
28
|
conn.get('/index')
|
29
29
|
t2 = Time.now
|
30
|
-
expect(
|
30
|
+
expect(t2 - t1).to be_within(0.1).of(interval)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'waits for correct time with long requests' do
|
34
|
+
t1 = Time.now
|
35
|
+
conn.get('/index')
|
36
|
+
sleep(5)
|
37
|
+
conn.get('/index')
|
38
|
+
t2 = Time.now
|
39
|
+
expect(t2 - t1).to be_within(0.1).of(interval)
|
31
40
|
end
|
32
41
|
|
33
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-rate_limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Faraday middleware to limit rate of requests
|
70
70
|
email:
|
71
71
|
- cameronmartin123@gmail.com
|
72
72
|
executables: []
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
|
+
- .travis.yml
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
@@ -82,7 +83,7 @@ files:
|
|
82
83
|
- lib/faraday-rate_limiter.rb
|
83
84
|
- lib/faraday/rate_limiter.rb
|
84
85
|
- spec/integration/rate_limiter_spec.rb
|
85
|
-
homepage:
|
86
|
+
homepage: https://github.com/cameron-martin/faraday-rate_limiter
|
86
87
|
licenses:
|
87
88
|
- MIT
|
88
89
|
metadata: {}
|
@@ -105,6 +106,6 @@ rubyforge_project:
|
|
105
106
|
rubygems_version: 2.2.1
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
|
-
summary:
|
109
|
+
summary: Faraday middleware to limit rate of requests
|
109
110
|
test_files:
|
110
111
|
- spec/integration/rate_limiter_spec.rb
|