Class: OpenWeather::Manager
- Inherits:
-
Object
- Object
- OpenWeather::Manager
- Defined in:
- lib/manager.rb
Overview
Manage the number of calls to the api
Constant Summary collapse
- LIMIT_CALLS =
free plan
59- LIMIT_SECONDS =
60
Class Method Summary collapse
Class Method Details
.call ⇒ Object
23 24 25 |
# File 'lib/manager.rb', line 23 def self.call @calls += 1 end |
.can_consume? ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/manager.rb', line 10 def self.can_consume? if @calls < LIMIT_CALLS call true elsif valid_time? reset true else # puts (Time.now - @last_call_at) false end end |
.reset ⇒ Object
27 28 29 30 31 |
# File 'lib/manager.rb', line 27 def self.reset # puts "Reset..." @calls = 0 @last_call_at = Time.now end |
.valid_time? ⇒ Boolean
33 34 35 |
# File 'lib/manager.rb', line 33 def self.valid_time? (Time.now - @last_call_at) >= LIMIT_SECONDS end |