lita-your-weather 0.0.1 → 0.0.2

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: ce7b969254307d97f449249fe2f18a1190deecf9
4
- data.tar.gz: 369f4a3132c52542b9b54ee7a21db9f79d1b4251
3
+ metadata.gz: aec3979dfb9d9d1aab41dac6d7c4831e592e0a5e
4
+ data.tar.gz: f634092bba0bb745a33e1436e530cab0364a8919
5
5
  SHA512:
6
- metadata.gz: b57d7f4fa2ff6781f8e20e8ebb21a3ba0beb97bd23773a0558ba4e4f7d17987ce81c05d8bf8d7fd2d4b0a7ac73ef7ba88f7770fd3fbfb06f899b8472f2d4434f
7
- data.tar.gz: 8b7e08440973b99fd54fd9c29bf518e21204c5e9e766f7d4b085f70bbb485058336d32f448a801ae90203944d43a2bcad7c1153712ef17cac6387fd8b88cb04a
6
+ metadata.gz: 5a077eaab58a478e4e7d9ee918c4fc672b4b849cdfd8caf083db5c7bc69c28d04032e2b7c68caa9c68b3be141d0c4e43d8ffa0ebcfd64e39e1adedfa4f9e9553
7
+ data.tar.gz: e88ae9f476bc0aaffa7515579b09e5ad2c7d375e7ee53bcbcbc5e29cfe9773a9dfbe27cdddbae19cb132b17af6b1122a08b28452c6a0ae87b634b7cc9bb566d7
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # lita-your-weather
2
2
 
3
- lita-your-weather provides the ability to ask for the current weather conditions or for a 7 day forecast.
3
+ lita-your-weather provides the ability to ask for the current weather conditions or for a 7 day forecast. This gem uses the www.apixu.com api to get the current weather and a 7 day weather forecast.
4
4
 
5
5
  ## Installation
6
6
 
@@ -17,7 +17,7 @@ Obtain an API Key from www.apixu.com
17
17
  Add the following to your lita_config.rb :
18
18
 
19
19
  ``` ruby
20
- config.handlers.your_weather.default_location = 'City, State'
20
+ config.handlers.your_weather.default_location = 'City, State, Country'
21
21
  config.handlers.your_weather.api_key = 'www.apixu.com Api Key'
22
22
  ```
23
23
 
@@ -26,11 +26,11 @@ config.handlers.your_weather.api_key = 'www.apixu.com Api Key'
26
26
  Commands include:
27
27
 
28
28
  <!-- For current weather of default location -->
29
- weather c
29
+ $ weather or $ weather c
30
30
  <!-- For current weather of specified location-->
31
- weather c Your_Location,Your_State
31
+ $ weather c Your_Location,Your_State,Your_Country
32
32
 
33
33
  <!-- For weather forecast of default location-->
34
- weather f
34
+ $ weather f
35
35
  <!-- For weather forecast of specified location-->
36
- weather f Your_Location,Your_State
36
+ $ weather f Your_Location,Your_State,Your_Country
@@ -3,8 +3,6 @@ require 'json'
3
3
  module Lita
4
4
  module Handlers
5
5
  class YourWeather < Handler
6
- # insert handler code here
7
-
8
6
  Lita.register_handler(self)
9
7
 
10
8
  # Variables
@@ -13,53 +11,57 @@ module Lita
13
11
  config :api_key, type: String, required: true
14
12
 
15
13
  # Routes
16
- route(/^weather\s{1}c\s*(.*)/, :weather_current, command: false, help: { "weather c CITY/CITY,COUNTRY" => "Responds with the specified city's current weather." })
17
- route(/^weather\s{1}f\s*(.*)/, :weather_forecast, command: false, help: { "weather f CITY/CITY,COUNTRY" => "Responds with the specified city's 7 day forecast." })
14
+ route(/^weather\s{1}*(.*)/, :weather_current, command: false, help: { "weather CITY/STATE,COUNTRY" => "Responds with the specified city's current weather." })
15
+ route(/^weather\s{1}c\s*(.*)/, :weather_current, command: false, help: { "weather c CITY/STATE,COUNTRY" => "Responds with the specified city's current weather." })
16
+ route(/^weather\s{1}f\s*(.*)/, :weather_forecast, command: false, help: { "weather f CITY/STATE,COUNTRY" => "Responds with the specified city's 7 day forecast." })
18
17
 
19
18
  # Current Weather
20
19
  def weather_current(response)
21
-
22
- location = response.matches[0][0]
23
-
24
- data = request('/current.json?key=' + config.api_key , 'c', location)
20
+ location = get_location(response.matches[0][0])
21
+ data = request('/current.json?key=' + config.api_key , location)
25
22
 
26
23
  if data['error']
27
- response.reply('The location does not exist or weather has exceeded the query limit error: ' + data['error']['message'])
24
+ response.reply('Error: ' + data['error']['message'])
28
25
  else
29
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
30
33
  end
31
34
  end
32
35
 
33
36
  # Forecast Weather
34
37
  def weather_forecast(response)
35
-
36
- location = response.matches[0][0]
37
-
38
- data = request('/forecast.json?key=' + config.api_key + '&days=7', 'c', location)
38
+ location = get_location(response.matches[0][0])
39
+ data = request('/forecast.json?key=' + config.api_key + '&days=7', location)
39
40
 
40
41
  if data['error']
41
- response.reply('The location does not exist or weather has exceeded the query limit error: ' + data['error']['message'])
42
+ response.reply('Error: ' + data['error']['message'])
42
43
  else
43
44
  response.reply('The forecast for ' + data['location']['name'] + ', ' + data['location']['region'] + ', ' + data['location']['country'] + ':')
44
45
  data['forecast']['forecastday'].each do |object|
45
46
  # binding.pry
46
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'] )
47
48
  end
48
-
49
49
  end
50
50
  end
51
51
 
52
- # Request method
53
- def request(url, type, location)
54
-
55
- if location == ''
52
+ # Get location
53
+ def get_location(location)
54
+ if location.eql? ''
56
55
  location = config.default_location
57
56
  end
57
+ location
58
+ end
58
59
 
60
+ # Request method
61
+ def request(url, location)
59
62
  http_response = http.get( URL + url, q: location)
60
63
  return JSON.parse(http_response.body)
61
64
  end
62
-
63
65
  end
64
66
  end
65
67
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-your-weather"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
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."
@@ -1,18 +1,15 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Handlers::YourWeather, lita_handler: true do
4
- it { is_expected.to route("weather c") }
5
- it { is_expected.to route("weather c 90210") }
6
- it { is_expected.to route_command("weather c") }
4
+
5
+ it "route weather to correct method" do
6
+ is_expected.to route("weather").to(:weather_current)
7
+ end
7
8
 
8
9
  it "route weather f to correct method" do
9
10
  is_expected.to route("weather c").to(:weather_current)
10
11
  end
11
12
 
12
- it { is_expected.to route("weather f") }
13
- it { is_expected.to route("weather f 90210") }
14
- it { is_expected.to route_command("weather f") }
15
-
16
13
  it "route weather f to correct method" do
17
14
  is_expected.to route("weather f").to(:weather_forecast)
18
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-your-weather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoie Carnegie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita