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_pws(response) ⇒ Object
- #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
26 27 28 29 |
# File 'lib/lita/handlers/weather.rb', line 26 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lita/handlers/weather.rb', line 38 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_pws(response) ⇒ Object
31 32 33 34 |
# File 'lib/lita/handlers/weather.rb', line 31 def weather_pws(response) return if Lita.config.handlers.weather.api_key.nil? response.reply get_conditions(response.matches[0][0]) end |
#weather_zip(response) ⇒ Object
21 22 23 24 |
# File 'lib/lita/handlers/weather.rb', line 21 def weather_zip(response) return if Lita.config.handlers.weather.api_key.nil? response.reply get_conditions(response.matches[0][0]) end |