simple_weather 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/simple_weather.rb +43 -41
  2. metadata +1 -1
@@ -4,52 +4,54 @@ require 'net/http'
4
4
 
5
5
  # api key from wunderground: 7b1e71b12f5535c0
6
6
  module SimpleWeather
7
- def self.initialize
8
- @last_update = Time.now
9
- @conditions = {}
10
- end
11
-
12
- def self.included(base)
13
- SimpleWeather.configure { |c| nil }
14
- base.extend ClassMethods
15
- base.send :include, InstanceMethods
16
- end
17
-
18
- def self.updateWeather(city = 'MD/College Park')
19
- base_url = 'http://api.wunderground.com/api/'
20
- api_key = '7b1e71b12f5535c0'
21
- query = '/conditions/q/'
22
- format = '.json'
7
+ class Weather
8
+ def initialize
9
+ @last_update = Time.now
10
+ @conditions = {}
11
+ end
23
12
 
24
- url = URI.escape(base_url << api_key << query << city << format)
25
- res = Net::HTTP.get_response(URI(url))
26
- data = res.body if res.is_a?(Net::HTTPSuccess)
13
+ def included(base)
14
+ SimpleWeather.configure { |c| nil }
15
+ base.extend ClassMethods
16
+ base.send :include, InstanceMethods
17
+ end
18
+
19
+ def updateWeather(city = 'MD/College Park')
20
+ base_url = 'http://api.wunderground.com/api/'
21
+ api_key = '7b1e71b12f5535c0'
22
+ query = '/conditions/q/'
23
+ format = '.json'
24
+
25
+ url = URI.escape(base_url << api_key << query << city << format)
26
+ res = Net::HTTP.get_response(URI(url))
27
+ data = res.body if res.is_a?(Net::HTTPSuccess)
27
28
 
28
- @conditions = JSON.parse(data)
29
+ @conditions = JSON.parse(data)
30
+
31
+ if @conditions.has_key? 'error'
32
+ raise 'Web service error'
33
+ end
34
+ end
35
+
36
+ def getImageUrl
37
+ @conditions['current_observation']['icon_url']
38
+ end
29
39
 
30
- if @conditions.has_key? 'error'
31
- raise 'Web service error'
40
+ def getWeather
41
+ @conditions['current_observation']['weather']
32
42
  end
33
- end
34
43
 
35
- def self.getImageUrl
36
- @conditions['current_observation']['icon_url']
37
- end
38
-
39
- def self.getWeather
40
- @conditions['current_observation']['weather']
41
- end
42
-
43
- def self.getTemp_f
44
- @conditions['current_observation']['temp_f']
45
- end
46
-
47
- def self.getTemp_c
48
- @conditions['current_observation']['temp_c']
49
- end
50
-
51
- def self.getFeelsLike
52
- @conditions['current_observation']['fellslike_string']
44
+ def getTemp_f
45
+ @conditions['current_observation']['temp_f']
46
+ end
47
+
48
+ def getTemp_c
49
+ @conditions['current_observation']['temp_c']
50
+ end
51
+
52
+ def getFeelsLike
53
+ @conditions['current_observation']['fellslike_string']
54
+ end
53
55
  end
54
56
  end
55
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_weather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: