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