jduff-api-throttling 0.1.0 → 0.1.1
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.
- data/VERSION.yml +1 -1
- data/lib/handlers/handlers.rb +2 -2
- data/lib/handlers/hash_handler.rb +13 -0
- data/test/test_api_throttling_hash.rb +23 -0
- metadata +4 -1
data/VERSION.yml
CHANGED
data/lib/handlers/handlers.rb
CHANGED
@@ -33,11 +33,11 @@ module Handlers
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
%w(redis_handler memcache_handler).each do |handler|
|
36
|
+
%w(redis_handler memcache_handler hash_handler).each do |handler|
|
37
37
|
require File.expand_path(File.dirname(__FILE__) + "/#{handler}")
|
38
38
|
end
|
39
39
|
|
40
|
-
HANDLERS = [RedisHandler, MemCacheHandler]
|
40
|
+
HANDLERS = [RedisHandler, MemCacheHandler, HashHandler]
|
41
41
|
|
42
42
|
def self.cache_handler_for(info)
|
43
43
|
HANDLERS.detect{|handler| handler.handles?(info)}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class TestApiThrottlingHash < Test::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
include BasicTests
|
6
|
+
HASH = Hash.new
|
7
|
+
|
8
|
+
def app
|
9
|
+
app = Rack::Builder.new {
|
10
|
+
use ApiThrottling, :requests_per_hour => 3, :cache => HASH, :read_method=>"get", :write_method=>"add"
|
11
|
+
run lambda {|env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '12'}, ["Hello World!"] ] }
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
HASH.replace({})
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_cache_handler_should_be_memcache
|
20
|
+
assert_equal "Handlers::HashHandler", app.to_app.instance_variable_get(:@handler).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jduff-api-throttling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luc Castera
|
@@ -31,9 +31,11 @@ files:
|
|
31
31
|
- VERSION.yml
|
32
32
|
- lib/api_throttling.rb
|
33
33
|
- lib/handlers/handlers.rb
|
34
|
+
- lib/handlers/hash_handler.rb
|
34
35
|
- lib/handlers/memcache_handler.rb
|
35
36
|
- lib/handlers/redis_handler.rb
|
36
37
|
- test/test_api_throttling.rb
|
38
|
+
- test/test_api_throttling_hash.rb
|
37
39
|
- test/test_api_throttling_memcache.rb
|
38
40
|
- test/test_handlers.rb
|
39
41
|
- test/test_helper.rb
|
@@ -65,6 +67,7 @@ specification_version: 2
|
|
65
67
|
summary: Rack Middleware to impose a rate limit on a web service (aka API Throttling)
|
66
68
|
test_files:
|
67
69
|
- test/test_api_throttling.rb
|
70
|
+
- test/test_api_throttling_hash.rb
|
68
71
|
- test/test_api_throttling_memcache.rb
|
69
72
|
- test/test_handlers.rb
|
70
73
|
- test/test_helper.rb
|