Class: Scrobbler::Base
- Inherits:
-
Object
- Object
- Scrobbler::Base
- Defined in:
- lib/scrobbler-ng-utils/misc/rate-limiter.rb
Constant Summary collapse
- NUMBER_OF_REQUESTS_PER_SECOND =
3- @@fetch_http_lastcall =
0
Class Method Summary collapse
Class Method Details
.fetch_http(request_method, paramlist) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/scrobbler-ng-utils/misc/rate-limiter.rb', line 9 def fetch_http(request_method, paramlist) now = ("%10.6f" % Time.now.to_f).to_f threshold = now - (1.0/NUMBER_OF_REQUESTS_PER_SECOND) if (@@fetch_http_lastcall > threshold) then sleep(now - @@fetch_http_lastcall) end @@fetch_http_lastcall = now return orig_fetch_http(request_method, paramlist) end |
.orig_fetch_http ⇒ Object
8 |
# File 'lib/scrobbler-ng-utils/misc/rate-limiter.rb', line 8 alias :orig_fetch_http :fetch_http |