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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c41b64532e64bd3baad55a5b56899ed7efe2626b1b0fca4e1d2e76006c9c890
4
- data.tar.gz: eee51dfb85a9aab5d9602325563a1913f2d590b01fa9e19a13299006ef863124
3
+ metadata.gz: e68b78d1cd83deb5f5dd82e946812022c14fcca737ca996ddc67169ea7884a0e
4
+ data.tar.gz: f472cddb0576d5f92aee366c0363d94b3026e04ea7eadd0ba86c5f1d1d0ab92e
5
5
  SHA512:
6
- metadata.gz: 3d12f47ff06ddc08549e63439d8b288fc425c4fd55abf8b0be013dcda4256e3893275200184d36ef8b6b2e5abda77f90efd6950bbef16f12163c4429c4b928bf
7
- data.tar.gz: 4e9f0616af59535fe3540fb3a431178d8b5f9ba75d9180c9f9b7e85d391c7aaa70cb0ba6468065d79ac131fe9c129f98fe1c142edf3086cbf847625821f3cd5f
6
+ metadata.gz: 996d8239727ffe11ecaeb99cccc3be179238b605cb8cb0ae51c3979088ec05a1a425bfa1c555116dc6a80c16834701199e61acee3a07d44e52c19b54cbd30267
7
+ data.tar.gz: d7eebab7f6fac303043c767d486559fa2b78e2e7dbd876234e5f49469d71f039c5e56cf3e4501d5fe6c6e6b32a0d07bca1f1ffbb269cffa841877f23992446c2
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "paul_walker"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/lib/paul_walker.rb CHANGED
@@ -1,5 +1,17 @@
1
- require "paul_walker/version"
1
+ require 'paul_walker/version'
2
+ require 'paul_walker/rate_limit'
3
+ require 'paul_walker/store'
2
4
 
3
5
  module PaulWalker
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module PaulWalker
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/paul_walker.gemspec CHANGED
@@ -1,36 +1,31 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "paul_walker/version"
4
+ require 'paul_walker/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "paul_walker"
7
+ spec.name = 'paul_walker'
8
8
  spec.version = PaulWalker::VERSION
9
- spec.authors = ["jshaffer"]
10
- spec.email = ["jshaffer@instructure.com"]
9
+ spec.authors = ['jshaffer']
10
+ spec.email = ['jshaffer@instructure.com']
11
11
 
12
- spec.summary = %q{Global capture of rate limit}
13
- spec.description = %q{Caputer rate limit across API clients to handle rate limiting}
14
- spec.homepage = "https://gerrit.instructure.com/admin/projects/paul_walker"
15
- spec.license = "MIT"
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 = "exe"
20
+ spec.bindir = 'exe'
30
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'redis', '>= 4.0'
32
25
 
33
- spec.add_development_dependency "bundler", "~> 1.16"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
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.0
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: Caputer rate limit across API clients to handle rate limiting
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://gerrit.instructure.com/admin/projects/paul_walker
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: Global capture of rate limit
142
+ summary: Rate limit management using redis
99
143
  test_files: []