Class: Lita::Handlers::ForecastLocations
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::ForecastLocations
- Defined in:
- lib/lita/handlers/forecast_locations.rb
Overview
Lita::Handlers::ForecastLocations
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.default_config(config) ⇒ Object
38 39 40 |
# File 'lib/lita/handlers/forecast_locations.rb', line 38 def self.default_config(config) config.api_key = nil end |
Instance Method Details
#location_add(response) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/lita/handlers/forecast_locations.rb', line 42 def location_add(response) r = response.matches[0] return response.reply('Already there!') if alias_exists?(r[0]) d = saved_location_hash(r) add_to_cache(d) response.reply("#{r[0]} added to the cache at [#{r[1]}, #{r[2]}]") end |
#location_rm(response) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lita/handlers/forecast_locations.rb', line 52 def location_rm(response) key = "alias:#{response.matches[0][0]}" return response.reply('Alias not found') unless alias_exists?(key) rm_from_cache(key) if LitaForecast.redis.keys(key).empty? return response.reply('Alias removed!') else return response.reply('Somehow that failed... I need an adult!') end end |
#locations(response) ⇒ Object
63 64 65 66 67 |
# File 'lib/lita/handlers/forecast_locations.rb', line 63 def locations(response) k = LitaForecast.redis.keys('alias:*').map { |v| v.gsub('alias:', '') } return response.reply('There are no weather aliases') if k.empty? response.reply("Known weather aliases: #{k.join(', ')}") end |