xero-kiwi 0.3.0 → 0.4.0
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/CHANGELOG.md +6 -0
- data/docs/throttling.md +28 -0
- data/lib/xero_kiwi/client.rb +1 -1
- data/lib/xero_kiwi/version.rb +1 -1
- data/lib/xero_kiwi.rb +16 -0
- 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: 353faef8c28dbf7801d5c9e8ebd152e0db172ede1aa69378144ac47cfa603436
|
|
4
|
+
data.tar.gz: b7decf2d114e9cbfba300c0274d6d9a3604c8d464ce080ac46b4a6df1e23d548
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff17d3c14fb35e1d6b3334935cda29c4fba9441ab012692dabc5518bb116a6615007e62a2e3c5c06a9c490f0b56d1fc16f8f42f9ff4b59d389088d68f7b2e3b9
|
|
7
|
+
data.tar.gz: ed0c6a55bcf9ed6d013f02ad76a3486a8d66f59961b959d85d7ed3e2a9f53c85cf43edb5e6f454f8c5fa556ad73983086105860983ca16c3db23633d39b3e31e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-04-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `XeroKiwi.default_throttle` + `XeroKiwi.configure { |c| c.default_throttle = ... }` for configuring one shared throttle limiter at the module level. New `Client` instances pick it up automatically when no `throttle:` kwarg is passed, so a Rails app can wire a single `RedisTokenBucket` in an initializer instead of threading it through every call site. Per-instance `throttle:` still overrides. See `docs/throttling.md`.
|
|
8
|
+
|
|
3
9
|
## [0.3.0] - 2026-04-20
|
|
4
10
|
|
|
5
11
|
### Added
|
data/docs/throttling.md
CHANGED
|
@@ -45,6 +45,34 @@ client.organisation(tenant_id) # blocks briefly if the bucket is empty
|
|
|
45
45
|
Same `throttle:` instance across all clients that share a Redis — that's how
|
|
46
46
|
coordination happens.
|
|
47
47
|
|
|
48
|
+
## Sharing one limiter across every client (Eg. Rails)
|
|
49
|
+
|
|
50
|
+
Passing `throttle:` to every `Client.new` call gets tedious. Configure a
|
|
51
|
+
module-level default once, and every new client picks it up automatically:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# config/initializers/xero_kiwi.rb
|
|
55
|
+
XeroKiwi.configure do |c|
|
|
56
|
+
c.default_throttle = XeroKiwi::Throttle::RedisTokenBucket.new(
|
|
57
|
+
redis: Redis.new(url: ENV.fetch("REDIS_URL")),
|
|
58
|
+
per_minute: 55,
|
|
59
|
+
per_day: 4_900
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
From then on:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
XeroKiwi::Client.new(access_token: token) # uses default_throttle
|
|
68
|
+
XeroKiwi::Client.new(access_token: token, throttle: other) # explicit override wins
|
|
69
|
+
XeroKiwi::Client.new(access_token: token, throttle: XeroKiwi::Throttle::NullLimiter.new) # opt out
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Precedence is: explicit `throttle:` kwarg → `XeroKiwi.default_throttle` →
|
|
73
|
+
`NullLimiter`. Reset in tests with `XeroKiwi.default_throttle = nil` so global
|
|
74
|
+
state doesn't leak between examples.
|
|
75
|
+
|
|
48
76
|
## How it works
|
|
49
77
|
|
|
50
78
|
A token bucket per tenant, stored as a Redis hash. Each call to Xero consumes
|
data/lib/xero_kiwi/client.rb
CHANGED
|
@@ -77,7 +77,7 @@ module XeroKiwi
|
|
|
77
77
|
@adapter = adapter
|
|
78
78
|
@user_agent = user_agent
|
|
79
79
|
@retry_options = DEFAULT_RETRY_OPTIONS.merge(retry_options)
|
|
80
|
-
@throttle = throttle || Throttle::NullLimiter.new
|
|
80
|
+
@throttle = throttle || XeroKiwi.default_throttle || Throttle::NullLimiter.new
|
|
81
81
|
@refresh_mutex = Mutex.new
|
|
82
82
|
end
|
|
83
83
|
|
data/lib/xero_kiwi/version.rb
CHANGED
data/lib/xero_kiwi.rb
CHANGED
|
@@ -35,4 +35,20 @@ require_relative "xero_kiwi/oauth/pkce"
|
|
|
35
35
|
require_relative "xero_kiwi/oauth/id_token"
|
|
36
36
|
|
|
37
37
|
module XeroKiwi
|
|
38
|
+
class << self
|
|
39
|
+
# Default throttle limiter applied to every new Client that doesn't pass
|
|
40
|
+
# its own `throttle:` kwarg. Lets a Rails app wire one shared limiter
|
|
41
|
+
# (e.g. a RedisTokenBucket) in an initializer without threading it
|
|
42
|
+
# through every call site. Per-instance `throttle:` still wins.
|
|
43
|
+
attr_accessor :default_throttle
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Yields the module for block-style configuration.
|
|
47
|
+
#
|
|
48
|
+
# XeroKiwi.configure do |c|
|
|
49
|
+
# c.default_throttle = XeroKiwi::Throttle::RedisTokenBucket.new(...)
|
|
50
|
+
# end
|
|
51
|
+
def self.configure
|
|
52
|
+
yield self
|
|
53
|
+
end
|
|
38
54
|
end
|