Class: X::RateLimit
- Inherits:
-
Object
- Object
- X::RateLimit
- Defined in:
- x-core/lib/x/core/rate_limit.rb
Overview
Represents rate limit information from an API response
Constant Summary collapse
- RATE_LIMIT_TYPE =
Rate limit type identifier
"rate-limit"- APP_LIMIT_TYPE =
App limit type identifier
"app-limit-24hour"- USER_LIMIT_TYPE =
User limit type identifier
"user-limit-24hour"- TYPES =
All supported rate limit types
[RATE_LIMIT_TYPE, APP_LIMIT_TYPE, USER_LIMIT_TYPE].freeze
Instance Attribute Summary collapse
-
#type ⇒ String
readonly
The type of rate limit.
Instance Method Summary collapse
-
#exhausted? ⇒ Boolean
Check whether the limit has no requests left.
-
#limit ⇒ Integer
Get the rate limit maximum.
-
#remaining ⇒ Integer
Get the remaining requests.
-
#reset_at ⇒ Time
Get the time when the rate limit resets.
-
#reset_in ⇒ Integer
Get the seconds until the rate limit resets.
Instance Attribute Details
#type ⇒ String (readonly)
The type of rate limit
27 28 29 |
# File 'x-core/lib/x/core/rate_limit.rb', line 27 def type @type end |
Instance Method Details
#exhausted? ⇒ Boolean
Check whether the limit has no requests left
99 |
# File 'x-core/lib/x/core/rate_limit.rb', line 99 def exhausted? = remaining.zero? |
#limit ⇒ Integer
Get the rate limit maximum
83 |
# File 'x-core/lib/x/core/rate_limit.rb', line 83 def limit = field("limit") |
#remaining ⇒ Integer
Get the remaining requests
91 |
# File 'x-core/lib/x/core/rate_limit.rb', line 91 def remaining = field("remaining") |
#reset_at ⇒ Time
Get the time when the rate limit resets
107 |
# File 'x-core/lib/x/core/rate_limit.rb', line 107 def reset_at = Time.at(field("reset")) |
#reset_in ⇒ Integer
Get the seconds until the rate limit resets
115 116 117 |
# File 'x-core/lib/x/core/rate_limit.rb', line 115 def reset_in [(reset_at - Time.now).ceil, 0].max end |