paul_walker 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +41 -0
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/paul_walker.rb +14 -2
- data/lib/paul_walker/rate_limit.rb +34 -0
- data/lib/paul_walker/store.rb +15 -0
- data/lib/paul_walker/version.rb +1 -1
- data/paul_walker.gemspec +18 -23
- metadata +50 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e68b78d1cd83deb5f5dd82e946812022c14fcca737ca996ddc67169ea7884a0e
|
4
|
+
data.tar.gz: f472cddb0576d5f92aee366c0363d94b3026e04ea7eadd0ba86c5f1d1d0ab92e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 996d8239727ffe11ecaeb99cccc3be179238b605cb8cb0ae51c3979088ec05a1a425bfa1c555116dc6a80c16834701199e61acee3a07d44e52c19b54cbd30267
|
7
|
+
data.tar.gz: d7eebab7f6fac303043c767d486559fa2b78e2e7dbd876234e5f49469d71f039c5e56cf3e4501d5fe6c6e6b32a0d07bca1f1ffbb269cffa841877f23992446c2
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in paul_walker.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paul_walker (0.1.0)
|
5
|
+
redis (>= 4.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
byebug (10.0.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
mock_redis (0.19.0)
|
13
|
+
rake (10.5.0)
|
14
|
+
redis (4.0.2)
|
15
|
+
rspec (3.8.0)
|
16
|
+
rspec-core (~> 3.8.0)
|
17
|
+
rspec-expectations (~> 3.8.0)
|
18
|
+
rspec-mocks (~> 3.8.0)
|
19
|
+
rspec-core (3.8.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-expectations (3.8.2)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-mocks (3.8.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-support (3.8.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.16)
|
34
|
+
byebug
|
35
|
+
mock_redis
|
36
|
+
paul_walker!
|
37
|
+
rake (~> 10.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.16.1
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'paul_walker'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "paul_walker"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/paul_walker.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'paul_walker/version'
|
2
|
+
require 'paul_walker/rate_limit'
|
3
|
+
require 'paul_walker/store'
|
2
4
|
|
3
5
|
module PaulWalker
|
4
|
-
|
6
|
+
class << self
|
7
|
+
attr_accessor :redis
|
8
|
+
attr_writer :redis_url
|
9
|
+
def configure
|
10
|
+
yield self if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def redis_url
|
14
|
+
@redis_url || ENV['REDIS_URL']
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'json/ext'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module PaulWalker
|
5
|
+
class RateLimit
|
6
|
+
def self.add(namespace, key, current, max)
|
7
|
+
store.set(composite_key(namespace, key),
|
8
|
+
{
|
9
|
+
current: current,
|
10
|
+
max: max,
|
11
|
+
timestamp: Time.now.utc
|
12
|
+
}.to_json)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get(namespace, key)
|
16
|
+
value = store.get(composite_key(namespace, key))
|
17
|
+
return nil if value.nil?
|
18
|
+
value = JSON.parse(value)
|
19
|
+
time = Time.parse(value['timestamp'])
|
20
|
+
adjusted_current = Time.now.utc.to_i - time.to_i + value['current']
|
21
|
+
value['current'] = adjusted_current <= value['current'] ? adjusted_current : value['max']
|
22
|
+
value
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.composite_key(namespace, key)
|
26
|
+
"#{namespace}:#{key}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.store
|
30
|
+
store = Store.new
|
31
|
+
store.provider
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# For now, we'll just force redis but keep everything abstract
|
2
|
+
require 'redis'
|
3
|
+
module PaulWalker
|
4
|
+
class Store
|
5
|
+
attr_accessor :redis
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@redis ||= PaulWalker.redis || Redis.new(url: PaulWalker.redis_url)
|
9
|
+
end
|
10
|
+
|
11
|
+
def provider
|
12
|
+
@redis
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/paul_walker/version.rb
CHANGED
data/paul_walker.gemspec
CHANGED
@@ -1,36 +1,31 @@
|
|
1
1
|
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'paul_walker/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'paul_walker'
|
8
8
|
spec.version = PaulWalker::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['jshaffer']
|
10
|
+
spec.email = ['jshaffer@instructure.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
"public gem pushes."
|
24
|
-
end
|
12
|
+
spec.summary = 'Rate limit management using redis'
|
13
|
+
spec.description = 'Rate limit management using redis'
|
14
|
+
spec.homepage = 'https://github.com/jayshaffer/paul_walker'
|
15
|
+
spec.license = 'MIT'
|
25
16
|
|
26
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
18
|
f.match(%r{^(test|spec|features)/})
|
28
19
|
end
|
29
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
30
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'redis', '>= 4.0'
|
32
25
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'byebug'
|
28
|
+
spec.add_development_dependency 'mock_redis'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paul_walker
|
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
|
- jshaffer
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,34 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mock_redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rake
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +94,7 @@ dependencies:
|
|
52
94
|
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '3.0'
|
55
|
-
description:
|
97
|
+
description: Rate limit management using redis
|
56
98
|
email:
|
57
99
|
- jshaffer@instructure.com
|
58
100
|
executables: []
|
@@ -63,19 +105,21 @@ files:
|
|
63
105
|
- ".rspec"
|
64
106
|
- ".travis.yml"
|
65
107
|
- Gemfile
|
108
|
+
- Gemfile.lock
|
66
109
|
- LICENSE.txt
|
67
110
|
- README.md
|
68
111
|
- Rakefile
|
69
112
|
- bin/console
|
70
113
|
- bin/setup
|
71
114
|
- lib/paul_walker.rb
|
115
|
+
- lib/paul_walker/rate_limit.rb
|
116
|
+
- lib/paul_walker/store.rb
|
72
117
|
- lib/paul_walker/version.rb
|
73
118
|
- paul_walker.gemspec
|
74
|
-
homepage: https://
|
119
|
+
homepage: https://github.com/jayshaffer/paul_walker
|
75
120
|
licenses:
|
76
121
|
- MIT
|
77
|
-
metadata:
|
78
|
-
allowed_push_host: https://rubygems.org
|
122
|
+
metadata: {}
|
79
123
|
post_install_message:
|
80
124
|
rdoc_options: []
|
81
125
|
require_paths:
|
@@ -95,5 +139,5 @@ rubyforge_project:
|
|
95
139
|
rubygems_version: 2.7.3
|
96
140
|
signing_key:
|
97
141
|
specification_version: 4
|
98
|
-
summary:
|
142
|
+
summary: Rate limit management using redis
|
99
143
|
test_files: []
|