lita-your-weather 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lita/handlers/your_weather.rb +17 -24
- data/lita-your-weather.gemspec +1 -1
- data/spec/lita/handlers/your_weather_spec.rb +18 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac0924448f551a9a15954bdf9149c3e2e8967eaf
|
4
|
+
data.tar.gz: 7f7197292d6e14cf367cbe1895192042d9d716ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a3d581ad907eae85eb1e8577e22d7d651de2b9a8bd2633353052135fbcb4b78b226aaabe2e020b18237b34e4ca451b4e23bcf62f203d594405c89906790220
|
7
|
+
data.tar.gz: 6c71461cbda2f26873fd54cc27560035dac4335c0cd9b0fdef621cfd358abc5db0adfb120df7bd4cfa9eaa3f90fb2eb4b03ab69facbced8aa9d5082ac0085e89
|
@@ -11,40 +11,33 @@ module Lita
|
|
11
11
|
config :api_key, type: String, required: true
|
12
12
|
|
13
13
|
# Routes
|
14
|
-
route(/^weather\s
|
15
|
-
route(/^weather\s{1}c\s*(.*)/, :weather_current, command: true, help: { "weather c CITY/STATE,COUNTRY" => "Responds with the specified city's current weather." })
|
16
|
-
route(/^weather\s{1}f\s*(.*)/, :weather_forecast, command: true, help: { "weather f CITY/STATE,COUNTRY" => "Responds with the specified city's 7 day forecast." })
|
14
|
+
route(/^weather\s?[c?|f?]?\s?(.*)/, :weather, command: true, help: { "lita weather CITY,STATE,COUNTRY or lita weather CITY,STATE,COUNTRY or lita weather f CITY,STATE,COUNTRY" => "Responds with the specified city's current weather or forecast." })
|
17
15
|
|
18
16
|
# Current Weather
|
19
|
-
def
|
17
|
+
def weather(response)
|
20
18
|
location = get_location(response.matches[0][0])
|
21
|
-
data = request('/current.json?key=' + config.api_key , location)
|
22
19
|
|
23
|
-
if
|
24
|
-
|
20
|
+
if response.message.body.eql? 'weather f'
|
21
|
+
data = request('/forecast.json?key=' + config.api_key + '&days=7', location)
|
25
22
|
else
|
26
|
-
|
27
|
-
|
28
|
-
if location.downcase.include? "edmonton"
|
29
|
-
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-ne.jpg')
|
30
|
-
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-nw.jpg')
|
31
|
-
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-w.jpg')
|
32
|
-
end
|
23
|
+
data = request('/current.json?key=' + config.api_key , location)
|
33
24
|
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Forecast Weather
|
37
|
-
def weather_forecast(response)
|
38
|
-
location = get_location(response.matches[0][0])
|
39
|
-
data = request('/forecast.json?key=' + config.api_key + '&days=7', location)
|
40
25
|
|
41
26
|
if data['error']
|
42
27
|
response.reply('Error: ' + data['error']['message'])
|
43
28
|
else
|
44
|
-
response.
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
if response.message.body.eql? 'weather f'
|
30
|
+
response.reply('The forecast for ' + data['location']['name'] + ', ' + data['location']['region'] + ', ' + data['location']['country'] + ':')
|
31
|
+
data['forecast']['forecastday'].each do |object|
|
32
|
+
response.reply('On ' + object['date'] + ' forecasted is a high of ' + object['day']['maxtemp_c'].to_s + "\xC2\xB0" + 'C' + ' and a low of ' + object['day']['mintemp_c'].to_s + "\xC2\xB0" + 'C It is expected to be ' + object['day']['condition']['text'] )
|
33
|
+
end
|
34
|
+
else
|
35
|
+
response.reply( data['location']['name'] + ', ' + data['location']['region'] + ', ' + data['location']['country'] + ' currently is ' + data['current']['condition']['text'] + ' and ' + data['current']['temp_c'].to_s + "\xC2\xB0" + 'C. It feels like ' + data['current']['feelslike_c'].to_s + "\xC2\xB0" + 'C' )
|
36
|
+
if location.downcase.include? "edmonton"
|
37
|
+
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-ne.jpg')
|
38
|
+
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-nw.jpg')
|
39
|
+
response.reply('https://ssl.eas.ualberta.ca/sitecore/camera/live/camera-w.jpg')
|
40
|
+
end
|
48
41
|
end
|
49
42
|
end
|
50
43
|
end
|
data/lita-your-weather.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-your-weather"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.4"
|
4
4
|
spec.authors = ["Zoie Carnegie"]
|
5
5
|
spec.email = ["zoie.carnegie@gmail.com"]
|
6
6
|
spec.description = "lita-your-weather provides the ability to ask for the current weather conditions or for a 7 day forecast."
|
@@ -2,15 +2,27 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::YourWeather, lita_handler: true do
|
4
4
|
|
5
|
-
it "route weather to
|
6
|
-
is_expected.
|
5
|
+
it "will route lita weather to the weather method" do
|
6
|
+
is_expected.to_not route("weather").to(:weather)
|
7
7
|
end
|
8
8
|
|
9
|
-
it "route weather
|
10
|
-
is_expected.
|
9
|
+
it "will route lita weather c to the weather method" do
|
10
|
+
is_expected.to_not route("weather c").to(:weather)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "route weather f to
|
14
|
-
is_expected.
|
13
|
+
it "will route lita weather f to the weather method" do
|
14
|
+
is_expected.to_not route("weather f").to(:weather)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "will not route weather" do
|
18
|
+
is_expected.to_not route("weather")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "will not route weather c" do
|
22
|
+
is_expected.to_not route("weather c")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "will not route weather f" do
|
26
|
+
is_expected.to_not route("weather f")
|
15
27
|
end
|
16
28
|
end
|