Class: Dinie::RateLimit
- Inherits:
-
Object
- Object
- Dinie::RateLimit
- Defined in:
- lib/dinie/runtime/rate_limit.rb
Overview
The rate-limit snapshot read from the most recent response’s ‘X-RateLimit-*` headers (architecture §10, RB6). Surfaced as `client.rate_limit`; `nil` until a response carries valid headers.
‘reset_at` is the SDK’s only ‘Time` (RB6): every body timestamp stays an `Integer` epoch, but this value comes from a transport header (not the wire body), so it is normalized to a `Time` — mirroring the `Date` the TypeScript SDK exposes here.
Instance Attribute Summary collapse
-
#limit ⇒ Integer
readonly
Ceiling for the current window (‘X-RateLimit-Limit`).
-
#remaining ⇒ Integer
readonly
Requests left in the current window (‘X-RateLimit-Remaining`).
-
#reset_at ⇒ Time
readonly
When the window resets (‘X-RateLimit-Reset`).
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
-
#deconstruct_keys(_keys) ⇒ Hash{Symbol => Object}
Enable pattern matching (‘case rl; in { remaining: 0 }`).
- #hash ⇒ Integer
-
#initialize(limit:, remaining:, reset_at:) ⇒ RateLimit
constructor
A new instance of RateLimit.
- #to_h ⇒ Hash{Symbol => Object} (also: #to_hash)
Constructor Details
#initialize(limit:, remaining:, reset_at:) ⇒ RateLimit
Returns a new instance of RateLimit.
29 30 31 32 33 34 |
# File 'lib/dinie/runtime/rate_limit.rb', line 29 def initialize(limit:, remaining:, reset_at:) @limit = limit @remaining = remaining @reset_at = reset_at freeze end |
Instance Attribute Details
#limit ⇒ Integer (readonly)
Returns ceiling for the current window (‘X-RateLimit-Limit`).
20 21 22 |
# File 'lib/dinie/runtime/rate_limit.rb', line 20 def limit @limit end |
#remaining ⇒ Integer (readonly)
Returns requests left in the current window (‘X-RateLimit-Remaining`).
22 23 24 |
# File 'lib/dinie/runtime/rate_limit.rb', line 22 def remaining @remaining end |
#reset_at ⇒ Time (readonly)
Returns when the window resets (‘X-RateLimit-Reset`).
24 25 26 |
# File 'lib/dinie/runtime/rate_limit.rb', line 24 def reset_at @reset_at end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
50 51 52 |
# File 'lib/dinie/runtime/rate_limit.rb', line 50 def ==(other) other.is_a?(RateLimit) && other.to_h == to_h end |
#deconstruct_keys(_keys) ⇒ Hash{Symbol => Object}
Enable pattern matching (‘case rl; in { remaining: 0 }`).
46 |
# File 'lib/dinie/runtime/rate_limit.rb', line 46 def deconstruct_keys(_keys) = to_h |
#hash ⇒ Integer
56 57 58 |
# File 'lib/dinie/runtime/rate_limit.rb', line 56 def hash to_h.hash end |
#to_h ⇒ Hash{Symbol => Object} Also known as: to_hash
37 38 39 |
# File 'lib/dinie/runtime/rate_limit.rb', line 37 def to_h { limit: limit, remaining: remaining, reset_at: reset_at } end |