Expose rate limit data via optional block on API responses - #774
Open
ProdigyTom wants to merge 1 commit into
Open
Expose rate limit data via optional block on API responses#774ProdigyTom wants to merge 1 commit into
ProdigyTom wants to merge 1 commit into
Conversation
Adds an optional block to API methods that yields the parsed response body and the rate limit information (x-ratelimit-limit / -remaining / -reset) from the response headers, without changing the return value for existing callers. This lets consumers monitor how close they are to Auth0's rate limits without monkey-patching. - Add Auth0::RateLimit value object built from response headers - Thread an optional block through the HTTPProxy request path and yield (response_body, rate_limit) on successful responses - Support the block on Users#user_sessions per the requested example - Add unit tests and an EXAMPLES.md usage section Closes auth0#606
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Adds an optional block to Management API methods that yields rate limit information alongside the response, without changing the return value for existing callers. Resolves the request in #606 to monitor rate-limit headroom without monkey-patching.
Auth0::RateLimitvalue object (lib/auth0/mixins/rate_limit_struct.rb) built from thex-ratelimit-limit/x-ratelimit-remaining/x-ratelimit-resetresponse headers. Exposeslimit(Integer),remaining(Integer), andreset(UTCTime); fields arenilwhen a header is absent.HTTPProxynow threads an optional block through the request path and, on a successful (2xx) response, yields(response_body, rate_limit). Existing callers are unaffected — the return value is unchanged and the block is entirely optional.Users#user_sessionsaccepts and forwards the block, matching the usage in Rate limit data returned from API methods #606:The plumbing is generic, so extending the block to additional endpoints is a one-line forward per method; kept to
user_sessionshere to match the issue and keep the change to a single concern.References
Testing
Unit tests cover the new value object (header parsing incl. symbol/dashed keys and missing headers), the proxy yielding
(body, rate_limit)on success while leaving the return value unchanged, anduser_sessionsforwarding the block. Full suite passes locally (bundle exec rspec).Checklist