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