Class: Uber::RateLimit

Inherits:
Object
  • Object
show all
Defined in:
lib/uber/rate_limit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ RateLimit

Returns a new instance of RateLimit.



6
7
8
9
# File 'lib/uber/rate_limit.rb', line 6

def initialize(attrs = {})
  return if attrs.nil? || attrs.empty?
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



4
5
6
# File 'lib/uber/rate_limit.rb', line 4

def attrs
  @attrs
end

Instance Method Details

#limitInteger

Returns:

  • (Integer)


12
13
14
15
# File 'lib/uber/rate_limit.rb', line 12

def limit
  limit = @attrs["x-rate-limit-limit"]
  limit.to_i if limit
end

#remainingInteger

Returns:

  • (Integer)


18
19
20
21
# File 'lib/uber/rate_limit.rb', line 18

def remaining
  remaining = @attrs["x-rate-limit-remaining"]
  remaining.to_i if remaining
end

#reset_atTime

Returns:



24
25
26
27
# File 'lib/uber/rate_limit.rb', line 24

def reset_at
  reset = @attrs["x-rate-limit-reset"]
  ::Time.at(reset.to_i) if reset
end

#reset_inInteger

Returns:

  • (Integer)


30
31
32
# File 'lib/uber/rate_limit.rb', line 30

def reset_in
  [(reset_at - ::Time.now).ceil, 0].max if reset_at
end