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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 261204130ba99059bdd1935e0bb8e68d96bea16ace2e8005aa984fa2c883a97a
4
- data.tar.gz: 8ac3bc402ee242f8e63cb65a4754e8601635ec2e8405b2ed9d9a7fc3fa822774
3
+ metadata.gz: 95cbfb0b951d027b39acd6a8a4a00acaac5fd57ba799c4e90ae9d81160a80955
4
+ data.tar.gz: a32b6eb90650b7dcd98af36b97ce663fe424f13e252a51d9feff291f1665c8fe
5
5
  SHA512:
6
- metadata.gz: 3273c9917ab3074d84cf8f91b5eb51d945fdde2c60388c9f07eb3e9500b731ba8cf89ea9f4918cd16b108d75982589b6a6099c14fae78598fa5fd9bc7f627d06
7
- data.tar.gz: 83103089327eece2e66612d5fd1287e9eb21da3fa25b2fde8945bdb74afe02acc90c02a34ccc076796a6afea2c550dbf7fc7bf4533f11d17c7f69a602b704b28
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
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "logger"
3
4
 
4
5
  module Limiter
@@ -28,7 +29,7 @@ module Limiter
28
29
  end
29
30
 
30
31
  def log(error)
31
- @logger ||= Logger.new(STDOUT)
32
+ @logger ||= Limiter.logger
32
33
  @logger.error(error)
33
34
  end
34
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.12"
4
+ VERSION = "0.1.15"
5
5
  end
data/lib/limiter.rb CHANGED
@@ -1,11 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "limiter/client"
4
- require "limiter/points"
5
- require "limiter/rate_limit_response"
6
- require "limiter/error_handler"
7
- require "limiter/version"
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
@@ -1 +1,3 @@
1
- require "limiter"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "limiter"
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.12
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bilal Budhani