Class: Booqable::RateLimit
- Inherits:
-
Struct
- Object
- Struct
- Booqable::RateLimit
- Defined in:
- lib/booqable/rate_limit.rb,
sig/booqable.rbs
Overview
Rate limit information from API responses
Instance Attribute Summary collapse
-
#limit ⇒ Integer?
Returns the value of attribute limit.
-
#remaining ⇒ Integer?
Returns the value of attribute remaining.
-
#resets_in ⇒ Integer?
Returns the value of attribute resets_in.
Class Method Summary collapse
-
.from_response(response) ⇒ RateLimit
Extract rate limit information from HTTP response.
Instance Attribute Details
#limit ⇒ Integer?
Returns the value of attribute limit.
178 179 180 |
# File 'sig/booqable.rbs', line 178 def limit @limit end |
#remaining ⇒ Integer?
Returns the value of attribute remaining.
179 180 181 |
# File 'sig/booqable.rbs', line 179 def remaining @remaining end |
#resets_in ⇒ Integer?
Returns the value of attribute resets_in.
180 181 182 |
# File 'sig/booqable.rbs', line 180 def resets_in @resets_in end |
Class Method Details
.from_response(response) ⇒ RateLimit
Extract rate limit information from HTTP response
Parses standard rate limit headers from the HTTP response and creates a RateLimit object with the extracted information. Falls back to default values if headers are missing.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/booqable/rate_limit.rb', line 38 def self.from_response(response) info = new headers = response.headers if response.respond_to?(:headers) && !response.headers.nil? headers ||= response.response_headers if response.respond_to?(:response_headers) && !response.response_headers.nil? if headers info.limit = (headers["X-RateLimit-Limit"] || 1).to_i info.remaining = (headers["X-RateLimit-Remaining"] || 1).to_i info.resets_in = (headers["X-RateLimit-Period"] || 1).to_i end info end |