Class: Dinie::RateLimit

Inherits:
Object
  • Object
show all
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.

Examples:

rl = client.rate_limit
rl.remaining        # => 87
rl.reset_at         # => 2026-06-02 12:00:30 UTC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit:, remaining:, reset_at:) ⇒ RateLimit

Returns a new instance of RateLimit.

Parameters:

  • limit (Integer)
  • remaining (Integer)
  • reset_at (Time)


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

#limitInteger (readonly)

Returns ceiling for the current window (‘X-RateLimit-Limit`).

Returns:

  • (Integer)

    ceiling for the current window (‘X-RateLimit-Limit`)



20
21
22
# File 'lib/dinie/runtime/rate_limit.rb', line 20

def limit
  @limit
end

#remainingInteger (readonly)

Returns requests left in the current window (‘X-RateLimit-Remaining`).

Returns:

  • (Integer)

    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_atTime (readonly)

Returns when the window resets (‘X-RateLimit-Reset`).

Returns:

  • (Time)

    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?

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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 }`).

Parameters:

  • _keys (Array<Symbol>, nil)

Returns:

  • (Hash{Symbol => Object})


46
# File 'lib/dinie/runtime/rate_limit.rb', line 46

def deconstruct_keys(_keys) = to_h

#hashInteger

Returns:

  • (Integer)


56
57
58
# File 'lib/dinie/runtime/rate_limit.rb', line 56

def hash
  to_h.hash
end

#to_hHash{Symbol => Object} Also known as: to_hash

Returns:

  • (Hash{Symbol => Object})


37
38
39
# File 'lib/dinie/runtime/rate_limit.rb', line 37

def to_h
  { limit: limit, remaining: remaining, reset_at: reset_at }
end