Class: Echowrap::RateLimit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attrsObject (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

#limitInteger

Returns:

  • (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

#remainingInteger

Returns:

  • (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_atTime

Returns:

  • (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_inInteger Also known as: retry_after

Returns:

  • (Integer)


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

Parameters:

  • attrs (Hash)

Returns:



41
42
43
44
# File 'lib/echowrap/rate_limit.rb', line 41

def update(attrs)
  @attrs.update(attrs)
  self
end