Class: Uber::RateLimit
- Inherits:
-
Object
- Object
- Uber::RateLimit
- Defined in:
- lib/uber/rate_limit.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ RateLimit
constructor
A new instance of RateLimit.
- #limit ⇒ Integer
- #remaining ⇒ Integer
- #reset_at ⇒ Time
- #reset_in ⇒ Integer
Constructor Details
#initialize(attrs = {}) ⇒ RateLimit
Returns a new instance of RateLimit.
5 6 7 8 |
# File 'lib/uber/rate_limit.rb', line 5 def initialize(attrs = {}) return if attrs.nil? || attrs.empty? @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/uber/rate_limit.rb', line 3 def attrs @attrs end |
Instance Method Details
#limit ⇒ Integer
11 12 13 14 |
# File 'lib/uber/rate_limit.rb', line 11 def limit limit = @attrs['x-rate-limit-limit'] limit.to_i if limit end |
#remaining ⇒ Integer
17 18 19 20 |
# File 'lib/uber/rate_limit.rb', line 17 def remaining remaining = @attrs['x-rate-limit-remaining'] remaining.to_i if remaining end |
#reset_at ⇒ Time
23 24 25 26 |
# File 'lib/uber/rate_limit.rb', line 23 def reset_at reset = @attrs['x-rate-limit-reset'] ::Time.at(reset.to_i) if reset end |
#reset_in ⇒ Integer
29 30 31 |
# File 'lib/uber/rate_limit.rb', line 29 def reset_in [(reset_at - ::Time.now).ceil, 0].max if reset_at end |