rate_limit_mock_server 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 2b9fb178144b8150f25d9b8c9bcbe5007157ff1fbd6017ba14f1ea757b3b9d59
4
- data.tar.gz: e8519a29959d189058bffd6befdd8e3f85bf20f8f4b9089bc2582c7491e6f63a
3
+ metadata.gz: 21be3ae474578dff1b2becba7daaf8467cdc862bd6bc9c3b0f7e05431f0a1edf
4
+ data.tar.gz: ec5b32fdab8d805aada27badd8d42d783765e873f20fa955ddc6faa6aa67dcf9
5
5
  SHA512:
6
- metadata.gz: 0c1e2fac0497c9068e8e141040963d4761c58867d99de765a6c2a72b5aa259da195fc522a2d971f35946caf73c14763334378c1edc48b1a2f4c1d9ad5614771b
7
- data.tar.gz: dd7ddd4668028866c2a8a5c6c3fe47d14d430179a97c5b15aefb000182207a8c7c30ee9eba4d863ff134dc2da03d7f4590b4e7508509a89aa5761e2ef26644a8
6
+ metadata.gz: 0c760fc11117abec0e5e8953d1baf6d319a4dc07dce41626322a534a3d6ad83cd8191e217adc00294e101436c4a7c03e3ec32ae5bcdeff605f52eb0aeabbc6e7
7
+ data.tar.gz: b6c90674ed7fb5977728a70d5bc6713e8e0543452761b4cdb9868a44ad51734cfcdf7eef1b70cdbfcef84abfd26d255d3d0a6bca9da61257242742cac4441684
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # RateLimitMockServer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rate_limit_mock_server`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A mock server for testing rate limits.
6
4
 
7
5
  ## Installation
8
6
 
@@ -21,12 +19,26 @@ Or install it yourself as:
21
19
  $ gem install rate_limit_mock_server
22
20
 
23
21
  ## Usage
22
+ Run the server in a shell:
23
+ ```sh
24
+ # On default port: 4567
25
+ $ rate_limit_mock_server
26
+
27
+ # Or specify the port with
28
+ $ rate_limit_mock_server --port= 3000
29
+ # Or
30
+ $ rate_limit_mock_server -p 3000
31
+ ```
32
+
24
33
  To start the server from code, do this:
25
34
  ```ruby
26
35
  require 'rate_limit_mock_server`
27
36
 
28
- # Start the server on port 4567 and block the current thread
37
+ # Start the server on the default port 4567 and block the current thread
29
38
  RateLimitMockServer.start
39
+
40
+ # Or start the server on the specified port and block the current thread
41
+ RateLimitMockServer.start(port: 1337)
30
42
  ```
31
43
 
32
44
  Note, If you don't want the server to block the current thread, you can instead spawn a new thread for the server.
@@ -34,7 +46,7 @@ Note, If you don't want the server to block the current thread, you can instead
34
46
  require 'rate_limit_mock_server`
35
47
 
36
48
  thread = Thread.new do
37
- # Start the server on port 4567 and block the current thread
49
+ # Start the server on port 4567
38
50
  RateLimitMockServer.start
39
51
  end
40
52
 
@@ -49,7 +61,17 @@ Note, If you don't want the server to block the current thread, you can instead
49
61
  thread.join
50
62
  ```
51
63
 
52
- The server can be stopped by either `RateLimitMockServer.quit!` or by sending a GET to `http://localhost:4567/quit`.
64
+ The server responds to the following routes:
65
+ - `GET /limit_test` - Returns a "429 Too Many Requests" response (only for showing how such a response look).
66
+ - `PUT /quit` - Stops the server.
67
+ - `GET /:rate_limit` - Rate limited resources where `:rate_limit` is an integer that specifies the rate limit.
68
+
69
+ The "main" route (`GET /:rate_limit`) can be used to test different rate limits simultaneously. E.g. requests to
70
+ `GET /5` will be limited at 5 rps, while requests to `GET /20` will be limited at 20 rps.
71
+
72
+ Note: `:rate_limit` must be an integer greater than or equal to `1`. I.e it's not possible to user rate limits lower than 1 rps.
73
+
74
+ The server can be stopped by either `RateLimitMockServer.quit!` or by sending a PUT request to `http://localhost:4567/quit`.
53
75
 
54
76
  ## Development
55
77
 
@@ -1,8 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- $: << File.expand_path('../lib/', __dir__)
5
-
4
+ $LOAD_PATH << File.expand_path('../lib/', __dir__)
5
+
6
6
  require 'rate_limit_mock_server'
7
-
8
- RateLimitMockServer.start
7
+
8
+ port = nil
9
+ pattern = /\A-(?:-port(?:=(\d)*)?|p)\Z/
10
+ index = ARGV.index do |arg|
11
+ next unless m = pattern.match(arg)
12
+
13
+ port = m[1] if m.size > 1
14
+ true
15
+ end
16
+
17
+ port ||= ARGV[index + 1] if index
18
+ port &&= port.to_i
19
+ port = nil if port&.zero?
20
+
21
+ RateLimitMockServer.start(port: port)
@@ -18,7 +18,7 @@ module RateLimitMockServer
18
18
  [429, "Current rate for #{request.path_info}: #{error.rate} (allowed #{error.limit})\n"]
19
19
  end
20
20
 
21
- get '/quit' do
21
+ put '/quit' do
22
22
  self.class.quit!
23
23
  end
24
24
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RateLimitMockServer
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -4,10 +4,11 @@ require 'rate_limit_mock_server/version'
4
4
  require 'rate_limit_mock_server/server'
5
5
 
6
6
  module RateLimitMockServer
7
- def self.start
7
+ def self.start(port: nil)
8
+ Server.set :port, port if port
8
9
  Server.run!
9
10
  end
10
-
11
+
11
12
  def self.quit!
12
13
  Server.quit!
13
14
  end
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- *��쐿�=#|��k��2��m v%�  �(O�Yl:�[�8� ��N,�z|9n��2Rsy�j!�Μ���\߿N37�Fc�ZܓF��ywP��tO| ����&QZt��M�m1��ku��z,i�T�y�%e$`��n���4�"��i���‘N]���ݷ�#/��vU
1
+ NM��z )���j�Vzt������lۛ��q�ҷ��Qm����u7�Z(A9-�}��8�#b�y�E��< �����~rE׺]��)6z� Dkah2� �
2
+ ��]L�7N�d�������k���c�8fڑ�{v_��p� �/��틥â��.Y�@U��l�E��i`ň+K�M~{*���R��ܳm\\�Zt!-�(��=�m�z��}�*���H�U��Խ�yU��P2�����hFZ�[ͧ
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rate_limit_mock_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  hDgtXQiNH/WrZi6kriR8NgvZIZobYz4qKW9nAuVEa3qqegirIKi6BtcHr1pWrWt1
32
32
  FDc=
33
33
  -----END CERTIFICATE-----
34
- date: 2022-04-06 00:00:00.000000000 Z
34
+ date: 2022-04-07 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
metadata.gz.sig CHANGED
Binary file