Class: Lita::Handlers::Weather
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Weather
- Defined in:
- lib/lita/handlers/weather.rb
Class Method Summary collapse
Instance Method Summary collapse
- #weather_airport(response) ⇒ Object
-
#weather_city(response) ⇒ Object
For a city search, we send the request to google, and get the lat/lng pairs then send the coordinates to weather underground.
- #weather_zip(response) ⇒ Object
Class Method Details
.default_config(config) ⇒ Object
7 8 9 |
# File 'lib/lita/handlers/weather.rb', line 7 def self.default_config(config) config.api_key = nil end |
Instance Method Details
#weather_airport(response) ⇒ Object
24 25 26 27 |
# File 'lib/lita/handlers/weather.rb', line 24 def weather_airport(response) return if Lita.config.handlers.weather.api_key.nil? response.reply get_conditions(response.matches[0][0]) end |
#weather_city(response) ⇒ Object
For a city search, we send the request to google, and get the lat/lng pairs then send the coordinates to weather underground
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lita/handlers/weather.rb', line 31 def weather_city(response) return if Lita.config.handlers.weather.api_key.nil? resp = http.get('http://maps.googleapis.com/maps/api/geocode/json', address: response.matches[0][0], sensor: 'false') raise 'GoogleFail' unless resp.status == 200 obj = MultiJson.load(resp.body) raise 'GoogleError' unless obj['status'].eql?('OK') location = obj['results'].first['geometry']['location'] response.reply get_conditions("#{location['lat']},#{location['lng']}") rescue response.reply 'Sorry, but there was a problem locating that city.' end |
#weather_zip(response) ⇒ Object
19 20 21 22 |
# File 'lib/lita/handlers/weather.rb', line 19 def weather_zip(response) return if Lita.config.handlers.weather.api_key.nil? response.reply get_conditions(response.matches[0][0]) end |