simple_weather 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_weather.rb +38 -32
- metadata +1 -1
data/lib/simple_weather.rb
CHANGED
@@ -8,41 +8,47 @@ module SimpleWeather
|
|
8
8
|
class << self
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def self.included(base)
|
12
|
+
base.send :include, InstanceMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
def updateWeather(conditions, city = 'MD/College Park')
|
17
|
+
base_url = 'http://api.wunderground.com/api/'
|
18
|
+
api_key = '7b1e71b12f5535c0'
|
19
|
+
query = '/conditions/q/'
|
20
|
+
format = '.json'
|
21
|
+
|
22
|
+
url = URI.escape(base_url << api_key << query << city << format)
|
23
|
+
res = Net::HTTP.get_response(URI(url))
|
24
|
+
data = res.body if res.is_a?(Net::HTTPSuccess)
|
20
25
|
|
21
|
-
|
26
|
+
conditions = JSON.parse(data)
|
27
|
+
|
28
|
+
if conditions.has_key? 'error'
|
29
|
+
raise 'Web service error'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def getImageUrl(conditions)
|
34
|
+
conditions['current_observation']['icon_url']
|
35
|
+
end
|
22
36
|
|
23
|
-
|
24
|
-
|
37
|
+
def getWeather(conditions)
|
38
|
+
conditions['current_observation']['weather']
|
39
|
+
end
|
40
|
+
|
41
|
+
def getTemp_f(conditions)
|
42
|
+
conditions['current_observation']['temp_f']
|
43
|
+
end
|
44
|
+
|
45
|
+
def getTemp_c(conditions)
|
46
|
+
conditions['current_observation']['temp_c']
|
47
|
+
end
|
48
|
+
|
49
|
+
def getFeelsLike(conditions)
|
50
|
+
conditions['current_observation']['fellslike_string']
|
25
51
|
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def getImageUrl(conditions)
|
29
|
-
conditions['current_observation']['icon_url']
|
30
|
-
end
|
31
|
-
|
32
|
-
def getWeather(conditions)
|
33
|
-
conditions['current_observation']['weather']
|
34
|
-
end
|
35
|
-
|
36
|
-
def getTemp_f(conditions)
|
37
|
-
conditions['current_observation']['temp_f']
|
38
|
-
end
|
39
|
-
|
40
|
-
def getTemp_c(conditions)
|
41
|
-
conditions['current_observation']['temp_c']
|
42
|
-
end
|
43
|
-
|
44
|
-
def getFeelsLike(conditions)
|
45
|
-
conditions['current_observation']['fellslike_string']
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|