Class: RemoveBg::RateLimitInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/remove_bg/rate_limit_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ RateLimitInfo

Returns a new instance of RateLimitInfo.



9
10
11
12
13
14
15
16
# File 'lib/remove_bg/rate_limit_info.rb', line 9

def initialize(headers)
  @total = headers["X-RateLimit-Limit"]&.to_i
  @remaining = headers["X-RateLimit-Remaining"]&.to_i
  @reset_timestamp = headers["X-RateLimit-Reset"]&.to_i

  # Only present if rate limit exceeded
  @retry_after_seconds = headers["Retry-After"]&.to_i
end

Instance Attribute Details

#remainingObject (readonly)

Returns the value of attribute remaining.



7
8
9
# File 'lib/remove_bg/rate_limit_info.rb', line 7

def remaining
  @remaining
end

#retry_after_secondsObject (readonly)

Returns the value of attribute retry_after_seconds.



7
8
9
# File 'lib/remove_bg/rate_limit_info.rb', line 7

def retry_after_seconds
  @retry_after_seconds
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/remove_bg/rate_limit_info.rb', line 7

def total
  @total
end

Instance Method Details

#reset_atObject



18
19
20
21
22
# File 'lib/remove_bg/rate_limit_info.rb', line 18

def reset_at
  return if reset_timestamp.nil?

  Time.at(reset_timestamp).utc
end

#to_sObject



24
25
26
27
28
29
30
31
# File 'lib/remove_bg/rate_limit_info.rb', line 24

def to_s
  "<RateLimit " \
    "reset_at='#{reset_at.iso8601}' " \
    "retry_after_seconds=#{retry_after_seconds} " \
    "total=#{total} " \
    "remaining=#{remaining}" \
    ">"
end