lita-your-weather 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6d96a35d92d2d0a9a584223af41a051d580c575
4
- data.tar.gz: 56922aef152490923fb6273b7a539e8b81a5a14a
3
+ metadata.gz: ac0924448f551a9a15954bdf9149c3e2e8967eaf
4
+ data.tar.gz: 7f7197292d6e14cf367cbe1895192042d9d716ef
5
5
  SHA512:
6
- metadata.gz: 51e74f8fd77a1b39040b970a2cdf6802db17c9a83267b5550ba317daf9316a72c5055787a95dde51b7bad47fe4e173542c68386fe8dbfb06d393080f3a3260db
7
- data.tar.gz: 087a23df19e6deb7f180f0fcfb45020323ebc30398e4aa80a14a361119849cbd8a7f2c4463d8810c4121ca3ae1fd14832427994ee00651d4a8ef1de4ae795e2c
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{1}*(.*)/, :weather_current, command: true, help: { "weather CITY/STATE,COUNTRY" => "Responds with the specified city's current weather." })
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 weather_current(response)
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 data['error']
24
- response.reply('Error: ' + data['error']['message'])
20
+ if response.message.body.eql? 'weather f'
21
+ data = request('/forecast.json?key=' + config.api_key + '&days=7', location)
25
22
  else
26
- 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' )
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.reply('The forecast for ' + data['location']['name'] + ', ' + data['location']['region'] + ', ' + data['location']['country'] + ':')
45
- data['forecast']['forecastday'].each do |object|
46
- # binding.pry
47
- 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'] )
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-your-weather"
3
- spec.version = "0.0.3"
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 correct method" do
6
- is_expected.to route("weather").to(:weather_current)
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 f to correct method" do
10
- is_expected.to route("weather c").to(:weather_current)
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 correct method" do
14
- is_expected.to route("weather f").to(:weather_forecast)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-your-weather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoie Carnegie