Class: Transprt::RateLimiting
- Inherits:
-
Object
- Object
- Transprt::RateLimiting
- Defined in:
- lib/transprt/rate_limiting.rb
Instance Method Summary collapse
-
#get(url) ⇒ Object
The HTTP response or nil if we’re hitting the rate limit and wait_for_quota is false (@see #initialize).
-
#initialize(wait_for_quota = true) ⇒ RateLimiting
constructor
A new instance of RateLimiting.
Constructor Details
#initialize(wait_for_quota = true) ⇒ RateLimiting
Returns a new instance of RateLimiting.
7 8 9 |
# File 'lib/transprt/rate_limiting.rb', line 7 def initialize(wait_for_quota = true) @wait_for_quota = wait_for_quota end |
Instance Method Details
#get(url) ⇒ Object
Returns The HTTP response or nil if we’re hitting the rate limit and wait_for_quota is false (@see #initialize).
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/transprt/rate_limiting.rb', line 13 def get(url) begin response = perform_get(url) rescue RestClient::TooManyRequests => e # API uses HTTP 429 to notify us, # @see https://github.com/OpendataCH/Transport/blob/master/lib/Transport/Application.php return nil unless wait_for_quota sleep_until_quota_reset(e.response) response = perform_get(url) end response end |