Class: Fulfil::RateLimitHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/fulfil/rate_limit_headers.rb

Overview

The ‘Fulfil::RateLimitHeaders` parses Fulfil HTTP rate limit headers and formats them to a more usable format.

Constant Summary collapse

DEFAULT_REQUEST_LIMIT =

Test suites might mock (or at least should mock) the requests to Fulfil. However, most of these test suites will not mock the response headers. To make sure those test suites don’t break, we’re setting some defaults for them.

10
DEFAULT_REQUESTS_LEFT =
9
DEFAULT_RESETS_AT =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers = {}) ⇒ RateLimitHeaders

Returns a new instance of RateLimitHeaders.



16
17
18
19
20
# File 'lib/fulfil/rate_limit_headers.rb', line 16

def initialize(headers = {})
  self.limit = headers['X-RateLimit-Limit'] || DEFAULT_REQUEST_LIMIT
  self.requests_left = headers['X-RateLimit-Remaining'] || DEFAULT_REQUESTS_LEFT
  self.resets_at = headers['X-RateLimit-Reset'] || DEFAULT_RESETS_AT
end

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



14
15
16
# File 'lib/fulfil/rate_limit_headers.rb', line 14

def limit
  @limit
end

#requests_leftObject

Returns the value of attribute requests_left.



14
15
16
# File 'lib/fulfil/rate_limit_headers.rb', line 14

def requests_left
  @requests_left
end

#resets_atObject

Returns the value of attribute resets_at.



14
15
16
# File 'lib/fulfil/rate_limit_headers.rb', line 14

def resets_at
  @resets_at
end