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 +4 -4
- data/README.md +15 -15
- data/lib/limiter/client.rb +3 -1
- data/lib/limiter/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: adbf765b7ef3aa5873ed8a1ad83b70b23dc1169b447d389f6757f88f83dbc031
         | 
| 4 | 
            +
              data.tar.gz: 7d36b0b18a42fba6d217c131a2d8c52441fd42927071330a9a4af94ab504db5a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 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 | 
            -
                   | 
| 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:  | 
| 86 | 
            +
                Limiter::Points.new(namespace: "shopify", limit: 1000, interval: 20.seconds)
         | 
| 87 87 | 
             
              end
         | 
| 88 88 | 
             
            end
         | 
| 89 89 | 
             
            ```
         | 
    
        data/lib/limiter/client.rb
    CHANGED
    
    | @@ -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)
         | 
    
        data/lib/limiter/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 11 | 
            +
            date: 2024-12-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: http
         |