limiter-ruby 0.1.12 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/limiter/client.rb +2 -0
- data/lib/limiter/error_handler.rb +2 -1
- data/lib/limiter/rate_limit_response.rb +4 -0
- data/lib/limiter/version.rb +1 -1
- data/lib/limiter.rb +13 -5
- data/lib/limiter_ruby.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95cbfb0b951d027b39acd6a8a4a00acaac5fd57ba799c4e90ae9d81160a80955
|
4
|
+
data.tar.gz: a32b6eb90650b7dcd98af36b97ce663fe424f13e252a51d9feff291f1665c8fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761359a7844639c497dac6136693d82704eb118ba5d915a6227f4b52a70d0932fa93f09a4d2216543fdbcf69c7ee42c96edd7674adc56bff65442e0751317e56
|
7
|
+
data.tar.gz: 2390594ac176924ed4ea9bae0412ebeccb54af4d6019c3ee1523b45926e3da352c3cd9ed7749d28ebf0f6bb1f638fe2cb7890f3f7580d694bd471eb557a132b6
|
data/lib/limiter/client.rb
CHANGED
@@ -12,12 +12,14 @@ module Limiter
|
|
12
12
|
@limit = limit
|
13
13
|
@interval = interval.to_i
|
14
14
|
@token = token || ENV["LIMITER_TOKEN"]
|
15
|
+
@logger = Limiter.logger
|
15
16
|
|
16
17
|
ErrorHandler.error("token is not set") if @token.nil?
|
17
18
|
end
|
18
19
|
|
19
20
|
def check(identifier)
|
20
21
|
@identifier = identifier
|
22
|
+
@logger.info("Limiter performing request: #{namespace}/#{limit}/#{interval}/#{identifier}")
|
21
23
|
RateLimitResponse.new(request)
|
22
24
|
end
|
23
25
|
|
@@ -7,13 +7,17 @@ module Limiter
|
|
7
7
|
|
8
8
|
def initialize(response)
|
9
9
|
@response = response
|
10
|
+
@logger = Limiter.logger
|
10
11
|
end
|
11
12
|
|
12
13
|
def exhausted?
|
14
|
+
@logger.info("Limiter response: #{@response.status}")
|
13
15
|
signed_request? && @response.status == 429
|
14
16
|
end
|
17
|
+
alias_method :exceeded?, :exhausted?
|
15
18
|
|
16
19
|
def allowed?
|
20
|
+
@logger.info("Limiter response: #{@response.status}")
|
17
21
|
signed_request? && @response.status == 200
|
18
22
|
end
|
19
23
|
|
data/lib/limiter/version.rb
CHANGED
data/lib/limiter.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require_relative "limiter/client"
|
4
|
+
require_relative "limiter/points"
|
5
|
+
require_relative "limiter/rate_limit_response"
|
6
|
+
require_relative "limiter/error_handler"
|
7
|
+
require_relative "limiter/version"
|
8
8
|
|
9
9
|
module Limiter
|
10
10
|
class Error < StandardError; end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_writer :logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.logger
|
17
|
+
@logger ||= Logger.new(STDOUT)
|
18
|
+
end
|
11
19
|
end
|
data/lib/limiter_ruby.rb
CHANGED