faraday-rate_limiter 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29be4e16b6bbfc73da1e297934382ae2a1aa9c7f
4
- data.tar.gz: bfde830f34f2eaac789461ae4e2ce942c95d3b01
3
+ metadata.gz: 4f50d1628dbd510948d560f33a34c303318d2dc8
4
+ data.tar.gz: 9e150cd0e7ec8f19c28b72968c3fa98c8c89c629
5
5
  SHA512:
6
- metadata.gz: fc59cdd063d6a2cad6c85063da1fa4f7d13f1c735c0bcbe40be3d041a48de6ce20342ae7cf4b06a0ee57ad3b9e414ae6b5d2a0c8def72790abbc734e910c5efb
7
- data.tar.gz: 8d277892aee46d5e1d9482c05cd4bc77514b9fb342b9fa8b14cad4d00c6df36e51df6135d86fc821e613a9ccf4cf1af0f402aa2f373e9e2b863d02becd4af63c
6
+ metadata.gz: 3ba3c38e9adc1520266d57f6ffccd7de2c0fdf87ee7e02c412e9b6acdd21fce28a66e73d488c7d5d918fa09b6a94ab54353f66a33910c45e5706a5c77d65f030
7
+ data.tar.gz: 8847d9e3d1968fc6356a79118c85bb6fcfd5884920933895589851393c9a9b8c60c6bc1e32e0ac0372bf2fde1f7ba3a6ce8bd4783ca2bb723d81164e1d081e8e
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx
9
+ script: bundle exec rspec
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
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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.3'
7
+ spec.version = '0.0.4'
8
8
  spec.authors = ['Cameron Martin']
9
9
  spec.email = ['cameronmartin123@gmail.com']
10
- spec.description = %q{Limits the rate of faraday requests}
11
- spec.summary = %q{Limits the rate of faraday requests}
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($/)
@@ -8,7 +8,6 @@ module Faraday
8
8
 
9
9
  def call(env)
10
10
 
11
-
12
11
  if @last_request_time
13
12
  time_since_last_request = Time.now - @last_request_time
14
13
  if time_since_last_request < @interval
@@ -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: 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 'should return the first result without delay' do
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((t2 - t1).abs < interval).to be_true
22
+ expect(t2 - t1).to be_within(0.1).of(0)
23
23
  end
24
24
 
25
- it 'should wait between requests' do
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((t2 - t1).abs > interval).to be_true
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.3
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-02 00:00:00.000000000 Z
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: Limits the rate of faraday requests
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: Limits the rate of faraday requests
109
+ summary: Faraday middleware to limit rate of requests
109
110
  test_files:
110
111
  - spec/integration/rate_limiter_spec.rb