Class: Bitsor::RateLimit
- Inherits:
-
Struct
- Object
- Struct
- Bitsor::RateLimit
- Defined in:
- lib/bitsor/concerns/rate_limit.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#remaining ⇒ Object
Returns the value of attribute remaining.
-
#resets_at ⇒ Object
Returns the value of attribute resets_at.
-
#resets_in ⇒ Object
Returns the value of attribute resets_in.
Class Method Summary collapse
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit
4 5 6 |
# File 'lib/bitsor/concerns/rate_limit.rb', line 4 def limit @limit end |
#remaining ⇒ Object
Returns the value of attribute remaining
4 5 6 |
# File 'lib/bitsor/concerns/rate_limit.rb', line 4 def remaining @remaining end |
#resets_at ⇒ Object
Returns the value of attribute resets_at
4 5 6 |
# File 'lib/bitsor/concerns/rate_limit.rb', line 4 def resets_at @resets_at end |
#resets_in ⇒ Object
Returns the value of attribute resets_in
4 5 6 |
# File 'lib/bitsor/concerns/rate_limit.rb', line 4 def resets_in @resets_in end |
Class Method Details
.from_response(response) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bitsor/concerns/rate_limit.rb', line 5 def self.from_response(response) info = new unless response&.headers.nil? info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i) info.resets_in = [(info.resets_at - Time.now).to_i, 0].max end info end |