rails_limiter 0.3.1 → 0.3.3

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
  SHA1:
3
- metadata.gz: 30e3304ed81c11936c5be83968972744273aa69f
4
- data.tar.gz: 51ac3c264349469dc075b4f959e56631c598f696
3
+ metadata.gz: e9cf139bea369504bef86ddebb06326e974e0674
4
+ data.tar.gz: e7601947fffb4e78cf111cdd5998a5763831e108
5
5
  SHA512:
6
- metadata.gz: e4078b59377f967b4351fbedf7c681e9b71606987bf85ab570e93979f1773be821e8f85f710a1b46b8ffcb6740b74206081a079590481842ae7eb874bd2920e6
7
- data.tar.gz: 1cbc22c9622293baa68f74a7eaa817331ee8df43aab4575d9827859a774772369febc71312126257879d09451cd683f946b5aef9cb0a295ed25621690614f03b
6
+ metadata.gz: ccfb5bab3bf040b46f4640093482a75b210fc201bfd8aec08955b479f0360e8ce8e25c4b5c1ac4333b907de3c7968a5aa30f213aef0725c95f2d30784d0998a7
7
+ data.tar.gz: 5f39f197c60a320ff1ec4e9358985b1c88ee869b8beab9f9d8f4e313d2882e0e48898d3ba25c44e925d65d095a120e2940f099b19d8f2d99f32b068b3de0121e
@@ -3,10 +3,9 @@ require 'active_support/core_ext/object/blank'
3
3
  module RailsLimiter::RailsLimiter
4
4
  def limit(key, max, expire_in, url)
5
5
  valid, ttl = process_limit(key, max, expire_in)
6
-
6
+
7
7
  unless valid
8
- flash[:error] = "You exceeded your requests limit of #{max}. Try again in #{ttl} seconds"
9
- redirect_to url
8
+ render :status => 429, :json => {:message => "You exceeded your requests limit of #{max}. Try again in #{ttl} seconds"}
10
9
  return
11
10
  end
12
11
  end
@@ -15,17 +14,17 @@ module RailsLimiter::RailsLimiter
15
14
  def get_connexion
16
15
  @connexion ||= RailsLimiter::Init.configuration.connexion
17
16
  end
18
-
17
+
19
18
  def process_limit(key, max, expire_in = 1.day.seconds.to_i)
20
19
  get_connexion
21
-
20
+
22
21
  val = @connexion.get(key)
23
-
22
+
24
23
  if val.blank?
25
24
  # si connexion ne possède pas de valeur pour la clé, on la créée
26
25
  @connexion.set(key, 1)
27
26
  @connexion.expire(key, expire_in)
28
-
27
+
29
28
  [true, 0]
30
29
  elsif val.to_i < max
31
30
  # si connexion possède la clé, on incrémente
@@ -36,4 +35,4 @@ module RailsLimiter::RailsLimiter
36
35
  [false, @connexion.ttl(key)]
37
36
  end
38
37
  end
39
- end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsLimiter
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_limiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Séveno
8
+ - Jean-Philippe Lecaille
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2017-12-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
@@ -41,6 +42,7 @@ dependencies:
41
42
  description: To limit the requests number of a user on an action's controller
42
43
  email:
43
44
  - jseveno@gmail.com
45
+ - jplecaille@gmail.com
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
@@ -86,7 +88,6 @@ files:
86
88
  - test/dummy/config/locales/en.yml
87
89
  - test/dummy/config/routes.rb
88
90
  - test/dummy/db/test.sqlite3
89
- - test/dummy/log/test.log
90
91
  - test/dummy/public/404.html
91
92
  - test/dummy/public/422.html
92
93
  - test/dummy/public/500.html
@@ -94,16 +95,6 @@ files:
94
95
  - test/dummy/script/rails
95
96
  - test/dummy/test/functional/test_controller_test.rb
96
97
  - test/dummy/test/unit/helpers/test_helper_test.rb
97
- - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
98
- - test/dummy/tmp/cache/assets/test/sprockets/293460f7bea2aea456231b769212f36f
99
- - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
100
- - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
101
- - test/dummy/tmp/cache/assets/test/sprockets/5daa64d9601a1dd14726112003d08364
102
- - test/dummy/tmp/cache/assets/test/sprockets/b45890d98668c132fee5cae4b15320d9
103
- - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
104
- - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
105
- - test/dummy/tmp/cache/assets/test/sprockets/daa0e3c217673cb0ebb89d97438a1b80
106
- - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
107
98
  - test/rails_limiter_test.rb
108
99
  - test/test_helper.rb
109
100
  homepage: https://github.com/idolweb/rails_limiter
@@ -126,59 +117,48 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
117
  version: '0'
127
118
  requirements: []
128
119
  rubyforge_project:
129
- rubygems_version: 2.2.0.rc.1
120
+ rubygems_version: 2.6.14
130
121
  signing_key:
131
122
  specification_version: 4
132
123
  summary: To limit the requests number of a user on an action's controller
133
124
  test_files:
134
- - test/dummy/app/assets/javascripts/application.js
135
- - test/dummy/app/assets/javascripts/test.js
136
- - test/dummy/app/assets/stylesheets/application.css
137
- - test/dummy/app/assets/stylesheets/test.css
138
125
  - test/dummy/app/controllers/application_controller.rb
139
126
  - test/dummy/app/controllers/test_controller.rb
140
- - test/dummy/app/helpers/application_helper.rb
141
- - test/dummy/app/helpers/test_helper.rb
142
- - test/dummy/app/views/layouts/application.html.erb
143
127
  - test/dummy/app/views/test/index.html.erb
144
128
  - test/dummy/app/views/test/redirect.html.erb
145
- - test/dummy/config/application.rb
146
- - test/dummy/config/boot.rb
147
- - test/dummy/config/database.yml
148
- - test/dummy/config/environment.rb
149
- - test/dummy/config/environments/development.rb
129
+ - test/dummy/app/views/layouts/application.html.erb
130
+ - test/dummy/app/assets/javascripts/test.js
131
+ - test/dummy/app/assets/javascripts/application.js
132
+ - test/dummy/app/assets/stylesheets/application.css
133
+ - test/dummy/app/assets/stylesheets/test.css
134
+ - test/dummy/app/helpers/test_helper.rb
135
+ - test/dummy/app/helpers/application_helper.rb
136
+ - test/dummy/test/unit/helpers/test_helper_test.rb
137
+ - test/dummy/test/functional/test_controller_test.rb
138
+ - test/dummy/config/routes.rb
139
+ - test/dummy/config/locales/en.yml
150
140
  - test/dummy/config/environments/production.rb
141
+ - test/dummy/config/environments/development.rb
151
142
  - test/dummy/config/environments/test.rb
143
+ - test/dummy/config/environment.rb
144
+ - test/dummy/config/application.rb
145
+ - test/dummy/config/database.yml
146
+ - test/dummy/config/boot.rb
152
147
  - test/dummy/config/initializers/backtrace_silencers.rb
153
- - test/dummy/config/initializers/inflections.rb
154
148
  - test/dummy/config/initializers/mime_types.rb
155
- - test/dummy/config/initializers/rails_limiter.rb
156
- - test/dummy/config/initializers/secret_token.rb
157
149
  - test/dummy/config/initializers/session_store.rb
158
150
  - test/dummy/config/initializers/wrap_parameters.rb
159
- - test/dummy/config/locales/en.yml
160
- - test/dummy/config/routes.rb
151
+ - test/dummy/config/initializers/rails_limiter.rb
152
+ - test/dummy/config/initializers/secret_token.rb
153
+ - test/dummy/config/initializers/inflections.rb
161
154
  - test/dummy/config.ru
162
- - test/dummy/db/test.sqlite3
163
- - test/dummy/log/test.log
164
- - test/dummy/public/404.html
155
+ - test/dummy/script/rails
156
+ - test/dummy/Rakefile
157
+ - test/dummy/public/favicon.ico
165
158
  - test/dummy/public/422.html
166
159
  - test/dummy/public/500.html
167
- - test/dummy/public/favicon.ico
168
- - test/dummy/Rakefile
160
+ - test/dummy/public/404.html
161
+ - test/dummy/db/test.sqlite3
169
162
  - test/dummy/README.rdoc
170
- - test/dummy/script/rails
171
- - test/dummy/test/functional/test_controller_test.rb
172
- - test/dummy/test/unit/helpers/test_helper_test.rb
173
- - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
174
- - test/dummy/tmp/cache/assets/test/sprockets/293460f7bea2aea456231b769212f36f
175
- - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
176
- - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
177
- - test/dummy/tmp/cache/assets/test/sprockets/5daa64d9601a1dd14726112003d08364
178
- - test/dummy/tmp/cache/assets/test/sprockets/b45890d98668c132fee5cae4b15320d9
179
- - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
180
- - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
181
- - test/dummy/tmp/cache/assets/test/sprockets/daa0e3c217673cb0ebb89d97438a1b80
182
- - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
183
- - test/rails_limiter_test.rb
184
163
  - test/test_helper.rb
164
+ - test/rails_limiter_test.rb
@@ -1,60 +0,0 @@
1
-  (0.1ms) begin transaction
2
- -----------------------------------------------------------------
3
- TestControllerTest: test_can_access_to_index_until_max_is_reached
4
- -----------------------------------------------------------------
5
- Processing by TestController#index as HTML
6
- Rendered test/index.html.erb within layouts/application (0.5ms)
7
- Completed 200 OK in 26ms (Views: 25.4ms | ActiveRecord: 0.0ms)
8
- Processing by TestController#index as HTML
9
- Rendered test/index.html.erb within layouts/application (0.1ms)
10
- Completed 200 OK in 1ms (Views: 0.8ms | ActiveRecord: 0.0ms)
11
- Processing by TestController#index as HTML
12
- Redirected to http://test.host/test/redirect
13
- Filter chain halted as #<Proc:0x007f92e3b13d48@/Users/jplecaille/Documents/Developpement/rails_limiter/test/dummy/app/controllers/test_controller.rb:2> rendered or redirected
14
- Completed 302 Found in 1ms (Views: 0.8ms | ActiveRecord: 0.0ms)
15
-  (0.1ms) rollback transaction
16
-  (0.1ms) begin transaction
17
- ----------------------------
18
- RailsLimiterTest: test_truth
19
- ----------------------------
20
-  (0.0ms) rollback transaction
21
-  (0.2ms) begin transaction
22
- -----------------------------------------------------------------
23
- TestControllerTest: test_can_access_to_index_until_max_is_reached
24
- -----------------------------------------------------------------
25
- Processing by TestController#index as HTML
26
- Rendered test/index.html.erb within layouts/application (0.6ms)
27
- Completed 200 OK in 19ms (Views: 18.5ms | ActiveRecord: 0.0ms)
28
- Processing by TestController#index as HTML
29
- Rendered test/index.html.erb within layouts/application (0.0ms)
30
- Completed 200 OK in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)
31
- Processing by TestController#index as HTML
32
- Redirected to http://test.host/test/redirect
33
- Filter chain halted as #<Proc:0x007fbc014bb7b0@/Users/jplecaille/Documents/Developpement/rails_limiter/test/dummy/app/controllers/test_controller.rb:2> rendered or redirected
34
- Completed 302 Found in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)
35
-  (0.1ms) rollback transaction
36
-  (0.1ms) begin transaction
37
- ----------------------------
38
- RailsLimiterTest: test_truth
39
- ----------------------------
40
-  (0.0ms) rollback transaction
41
-  (0.2ms) begin transaction
42
- -----------------------------------------------------------------
43
- TestControllerTest: test_can_access_to_index_until_max_is_reached
44
- -----------------------------------------------------------------
45
- Processing by TestController#index as HTML
46
- Rendered test/index.html.erb within layouts/application (0.6ms)
47
- Completed 200 OK in 14ms (Views: 13.4ms | ActiveRecord: 0.0ms)
48
- Processing by TestController#index as HTML
49
- Rendered test/index.html.erb within layouts/application (0.0ms)
50
- Completed 200 OK in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)
51
- Processing by TestController#index as HTML
52
- Redirected to http://test.host/test/redirect
53
- Filter chain halted as #<Proc:0x007f7fe5a07b40@/Users/jplecaille/Documents/Developpement/rails_limiter/test/dummy/app/controllers/test_controller.rb:2> rendered or redirected
54
- Completed 302 Found in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)
55
-  (0.1ms) rollback transaction
56
-  (0.0ms) begin transaction
57
- ----------------------------
58
- RailsLimiterTest: test_truth
59
- ----------------------------
60
-  (0.0ms) rollback transaction