limiter-ruby 0.2.6 → 0.2.7

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: 0ba0ddf343988f20e25bf09cd9e8d79d07df1012733709dca66742098f9f31a1
4
- data.tar.gz: 35418ed42f3e2d435f872e964f5738343d2b2b25c9cccf270c7060161bddca0a
3
+ metadata.gz: adbf765b7ef3aa5873ed8a1ad83b70b23dc1169b447d389f6757f88f83dbc031
4
+ data.tar.gz: 7d36b0b18a42fba6d217c131a2d8c52441fd42927071330a9a4af94ab504db5a
5
5
  SHA512:
6
- metadata.gz: 1b54697bbfecb6e03df15fb14e6e4ed35de4a4c56c69f2d1197e47e1d31616b00a8f4f305e1d6af81c90fdfb39e6181d25a8c05e2b12bc920459060202a0054d
7
- data.tar.gz: 223a007534acba31fd0ae706d5ba8d17be190b898e1963b2a436dc130f0c86a5191b8ca5f3d0f97ebd78e1c9074495ca5bc2f4b4d1cfe94b60f8804cccfe20d3
6
+ metadata.gz: 98feb4fc57be513ba79d1f37050dada93f4e877d31f358acdc8ea42a3e607fc6c04a5cbb1a7fed2b50e34f4b75ce07b0372b3c40fa80b02bfc2e5febecc9d42f
7
+ data.tar.gz: 79d8b18d6a7c6e4648caa3973e59cbe292ecf4ba3f493d5391e8b271e80a60e2d5a04f510bb7bc203ca9f20d8bc681e531b21657a64a8685d29fe20663ebc3ec
data/README.md CHANGED
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  ## Simple Rate Limit Example
35
35
 
36
- Assuming this is a Ruby on Rails app within ActiveJob
36
+ Sample API controller that checks the rate limit for the current user and increments the request count
37
37
 
38
38
  ```ruby
39
39
  class ApiController < ApplicationController
@@ -62,28 +62,28 @@ end
62
62
 
63
63
  ## Points Rate Limit Example
64
64
 
65
- ```ruby
66
- class ApiController < ApplicationController
67
- before_action :rate_limit
68
-
69
- def index
70
- # continue the action
71
-
72
- limiter.used(100) # mark 100 points used
73
- end
65
+ Sample ActiveJob that checks the rate limit for the shop and updates the request count
74
66
 
75
- private
76
- def rate_limit
77
- rate_limit = limiter.check(current_user.id)
67
+ ```ruby
68
+ class DataSyncJob < ApplicationJob
69
+ queue_as :default
78
70
 
71
+ def perform
72
+ rate_limit = limiter.check(shop.id)
79
73
  if rate_limit.exhausted?
80
- render json: { error: "Rate limit exceeded" }, status: :too_many_requests
74
+ self.class.set(wait: rate_limit.resets_in).perform_later
75
+ return
81
76
  end
77
+
78
+ # continue the action
79
+ response = ... # query_cost = 100
80
+
81
+ limiter.used(response.query_cost) # mark 100 points used
82
82
  end
83
83
 
84
84
  # Allow 1000 points per minute
85
85
  def limiter
86
- Limiter::Points.new(namespace: "shopify", limit: 1000, interval: 1.minute)
86
+ Limiter::Points.new(namespace: "shopify", limit: 1000, interval: 20.seconds)
87
87
  end
88
88
  end
89
89
  ```
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "http"
4
+
3
5
  module Limiter
4
6
  class Client
5
7
 
@@ -47,7 +49,7 @@ module Limiter
47
49
  end
48
50
 
49
51
  def request(params = {})
50
- HTTP
52
+ ::HTTP
51
53
  .auth("Bearer #{Limiter.configuration.api_token}")
52
54
  .headers("User-Agent" => "Limiter-Ruby/#{Limiter::VERSION}")
53
55
  .get(BASE_URL + limiter_path, params: params)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Limiter
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limiter-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bilal Budhani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-14 00:00:00.000000000 Z
11
+ date: 2024-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http