limiter-ruby 0.1.13 → 0.1.15

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: 87a959ee34d3f771f97ce012ab718b8313057c407f6441f4beed90a021a097c5
4
- data.tar.gz: 0271c7731bafb69956cc8f36636d7eab28e67def6c55c69565d911e9f757bb14
3
+ metadata.gz: 95cbfb0b951d027b39acd6a8a4a00acaac5fd57ba799c4e90ae9d81160a80955
4
+ data.tar.gz: a32b6eb90650b7dcd98af36b97ce663fe424f13e252a51d9feff291f1665c8fe
5
5
  SHA512:
6
- metadata.gz: 214133e80b860d1e87d1005f09cf3e728da406ddee8d34100274f2064729997271dfb481bf227f163910146f4700b96decc1e7b9837d71e7f769417c98b9010a
7
- data.tar.gz: 00c72e252a8d733af4fcde4bdec7c3aa978450c53c26fc5548d992834550b54146aecc5e7ef165e42a50465ab7026c6ac36c73b4ad82ffa9604cc174d84ddbe7
6
+ metadata.gz: 761359a7844639c497dac6136693d82704eb118ba5d915a6227f4b52a70d0932fa93f09a4d2216543fdbcf69c7ee42c96edd7674adc56bff65442e0751317e56
7
+ data.tar.gz: 2390594ac176924ed4ea9bae0412ebeccb54af4d6019c3ee1523b45926e3da352c3cd9ed7749d28ebf0f6bb1f638fe2cb7890f3f7580d694bd471eb557a132b6
@@ -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
 
@@ -29,7 +29,7 @@ module Limiter
29
29
  end
30
30
 
31
31
  def log(error)
32
- @logger ||= Logger.new(STDOUT)
32
+ @logger ||= Limiter.logger
33
33
  @logger.error(error)
34
34
  end
35
35
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Limiter
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.15"
5
5
  end
data/lib/limiter.rb CHANGED
@@ -8,4 +8,12 @@ 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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limiter-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bilal Budhani