Class: Echowrap::RateLimit
- Inherits:
-
Object
- Object
- Echowrap::RateLimit
- Defined in:
- lib/echowrap/rate_limit.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute attrs.
Instance Method Summary collapse
- #initialize(attrs = {}) ⇒ Echowrap::RateLimit constructor
- #limit ⇒ Integer
- #remaining ⇒ Integer
- #reset_at ⇒ Time
- #reset_in ⇒ Integer (also: #retry_after)
-
#update(attrs) ⇒ Echowrap::RateLimit
Update the attributes of a RateLimit.
Constructor Details
#initialize(attrs = {}) ⇒ Echowrap::RateLimit
9 10 11 |
# File 'lib/echowrap/rate_limit.rb', line 9 def initialize(attrs={}) @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly) Also known as: to_hash
Returns the value of attribute attrs.
5 6 7 |
# File 'lib/echowrap/rate_limit.rb', line 5 def attrs @attrs end |
Instance Method Details
#limit ⇒ Integer
14 15 16 17 |
# File 'lib/echowrap/rate_limit.rb', line 14 def limit limit = @attrs['x-rate-limit-limit'] limit.to_i if limit end |
#remaining ⇒ Integer
20 21 22 23 |
# File 'lib/echowrap/rate_limit.rb', line 20 def remaining remaining = @attrs['x-rate-limit-remaining'] remaining.to_i if remaining end |
#reset_at ⇒ Time
26 27 28 29 |
# File 'lib/echowrap/rate_limit.rb', line 26 def reset_at reset = @attrs['x-rate-limit-reset'] Time.at(reset.to_i) if reset end |
#reset_in ⇒ Integer Also known as: retry_after
32 33 34 |
# File 'lib/echowrap/rate_limit.rb', line 32 def reset_in [(reset_at - Time.now).ceil, 0].max if reset_at end |
#update(attrs) ⇒ Echowrap::RateLimit
Update the attributes of a RateLimit
41 42 43 44 |
# File 'lib/echowrap/rate_limit.rb', line 41 def update(attrs) @attrs.update(attrs) self end |