Class: OwmSdk::Weather
- Inherits:
-
Object
- Object
- OwmSdk::Weather
- Includes:
- Request
- Defined in:
- lib/owm_sdk/weather.rb
Constant Summary collapse
- POLLING_RATE =
600
- LOCATION_CACHE_SIZE =
10
- WEATHER_CACHE_SIZE =
10
- WEATHER_CACHE_TTL =
600
Class Method Summary collapse
Instance Method Summary collapse
- #get_weather(city) ⇒ Object
-
#initialize(config = {}) ⇒ Weather
constructor
A new instance of Weather.
Constructor Details
#initialize(config = {}) ⇒ Weather
Returns a new instance of Weather.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/owm_sdk/weather.rb', line 23 def initialize(config = {}) OwmSdk::Config::ATTRIBUTES.each do |key| send(:"#{key}=", config[key] || OwmSdk.config.send(key)) end validate_configuration(config) @logger = Logger.new(STDOUT) @location_cache = LruRedux::Cache.new(LOCATION_CACHE_SIZE) @weather_cache = LruRedux::TTL::Cache.new(WEATHER_CACHE_SIZE, WEATHER_CACHE_TTL) @polling_thread = Thread.new { polling_loop } if @mode == "polling" end |
Class Method Details
.config ⇒ Object
43 44 45 |
# File 'lib/owm_sdk/weather.rb', line 43 def config Config end |
Instance Method Details
#get_weather(city) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/owm_sdk/weather.rb', line 14 def get_weather(city) location = get_location(city) weather_cached = @weather_cache[location] return weather_cached unless weather_cached.nil? get_weather_request(location) end |