Class: Bitsor::RateLimit

Inherits:
Struct
  • Object
show all
Defined in:
lib/bitsor/concerns/rate_limit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#limitObject

Returns the value of attribute limit

Returns:

  • (Object)

    the current value of limit



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

def limit
  @limit
end

#remainingObject

Returns the value of attribute remaining

Returns:

  • (Object)

    the current value of remaining



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

def remaining
  @remaining
end

#resets_atObject

Returns the value of attribute resets_at

Returns:

  • (Object)

    the current value of resets_at



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

def resets_at
  @resets_at
end

#resets_inObject

Returns the value of attribute resets_in

Returns:

  • (Object)

    the current value of 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