weather-underground 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -1,3 +1,6 @@
1
+ === 1.1.1 2011-03-05
2
+ * Fix packaging issues with 1.1.0
3
+
1
4
  === 1.1.0 2011-03-04
2
5
 
3
6
  * 3 major enhancements:
@@ -1,10 +1,17 @@
1
+ Gemfile
1
2
  History.txt
2
3
  Manifest.txt
3
4
  PostInstall.txt
4
5
  README.rdoc
5
6
  Rakefile
6
7
  lib/weather-underground.rb
8
+ lib/weather-underground/alerts.rb
9
+ lib/weather-underground/base.rb
10
+ lib/weather-underground/current_observation.rb
11
+ lib/weather-underground/forecast.rb
12
+ lib/weather-underground/geo_lookup.rb
7
13
  lib/weather-underground/uploader.rb
14
+ lib/weather-underground/utils.rb
8
15
  script/console
9
16
  script/destroy
10
17
  script/generate
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ $hoe = Hoe.spec 'weather-underground' do
19
19
  self.rubyforge_name = 'sdaguegems' # self.name # TODO this is default value
20
20
  self.extra_rdoc_files = ["README.rdoc"]
21
21
  self.readme_file = "README.rdoc"
22
- self.extra_deps = [['temperature', '>= 1.0.0'], 'rest-client', 'happymapper']
22
+ self.extra_deps = [['temperature', '>= 1.0.0'], ['rest-client', '>=0'], ['happymapper','>=0'] ]
23
23
  # self.extra_deps = [['activesupport','>= 2.0.2']]
24
24
 
25
25
  end
@@ -10,5 +10,5 @@ require "weather-underground/geo_lookup"
10
10
  require "weather-underground/uploader"
11
11
 
12
12
  module WeatherUnderground
13
- VERSION = '1.1.0'
13
+ VERSION = '1.1.1'
14
14
  end
@@ -0,0 +1,61 @@
1
+ # Weather Underground API subject to TOS at http://www.wunderground.com/members/tos.asp#api
2
+
3
+ module WeatherUnderground
4
+
5
+ class AlertExpires
6
+ include HappyMapper
7
+
8
+ tag 'expires'
9
+
10
+ attribute 'epoch', Integer
11
+ content 'text'
12
+
13
+ def text
14
+ @text
15
+ end
16
+
17
+ def datetime
18
+ Time.at( @epoch )
19
+ end
20
+ end
21
+
22
+ class AlertDate
23
+ include HappyMapper
24
+
25
+ tag 'date'
26
+
27
+ attribute 'epoch', Integer
28
+ content 'text'
29
+
30
+ def text
31
+ @text
32
+ end
33
+
34
+ def datetime
35
+ Time.at( @epoch )
36
+ end
37
+ end
38
+
39
+ class Alert
40
+ include HappyMapper
41
+
42
+ tag 'AlertItem'
43
+
44
+ element :type, String
45
+ element :description, String
46
+ has_one :date, AlertDate
47
+ has_one :expires, AlertExpires
48
+ element :message, String
49
+ element :phenomena, String
50
+ element :significance, String
51
+ end
52
+
53
+
54
+ class Alerts
55
+ include HappyMapper
56
+
57
+ tag 'alerts'
58
+
59
+ has_many :alerts, Alert
60
+ end
61
+ end
@@ -0,0 +1,120 @@
1
+ require 'happymapper'
2
+ require 'rest_client'
3
+
4
+ module WeatherUnderground
5
+
6
+ # This is an data retriever for the weather underground personal weather
7
+ # station service, as found at http://wunderground.com.
8
+ #
9
+ # It is build from the documentation provided at
10
+ # http://wiki.wunderground.com/index.php/API_-_XML
11
+ class Base
12
+ include Utils
13
+
14
+
15
+ def initialize
16
+ end
17
+
18
+ # Return the current observed weather data from location for +loc+
19
+ #
20
+ # +loc+ can be:
21
+ # * zipcode (US or Canadian)
22
+ # * city state; city, state
23
+ # * city
24
+ # * state
25
+ # * country
26
+ # * airport code (3-letter or 4-letter)
27
+ # * lat,lon
28
+ def CurrentObservations( loc )
29
+ WXCurrentObXML( loc )
30
+ end
31
+
32
+ # Return the forecast weather data from location for +loc+
33
+ #
34
+ # A +SimpleForecast+ contains more detailed data for each day than
35
+ # a +TextForcase+ of the same location.
36
+ #
37
+ # +loc+ can be:
38
+ # * zipcode (US or Canadian)
39
+ # * city state; city, state
40
+ # * city
41
+ # * state
42
+ # * country
43
+ # * airport code (3-letter or 4-letter)
44
+ # * lat,lon
45
+ def SimpleForecast( loc )
46
+ f = ForecastXML( loc )
47
+ f.simple_forecast
48
+ end
49
+
50
+ # Return the forecast weather data from location for +loc+
51
+ #
52
+ # A +TextForecast+ contains basic data in sentence form for the
53
+ # location queried. If you need more detailed data use
54
+ # a +SimpleForecast+
55
+ #
56
+ # +loc+ can be:
57
+ # * zipcode (US or Canadian)
58
+ # * city state; city, state
59
+ # * city
60
+ # * state
61
+ # * country
62
+ # * airport code (3-letter or 4-letter)
63
+ # * lat,lon
64
+ def TextForecast( loc )
65
+ f = ForecastXML( loc )
66
+ f.text_forecast
67
+ end
68
+
69
+ #--
70
+ # TODO: Implement GeoLookup
71
+ #++
72
+ def GeoLookup( loc )
73
+
74
+ end
75
+
76
+ # Return any active weather alerts for +loc+
77
+ #
78
+ # +loc+ can be:
79
+ # * zipcode (US or Canadian)
80
+ # * city state; city, state
81
+ # * city
82
+ # * state
83
+ # * country
84
+ # * airport code (3-letter or 4-letter)
85
+ # * lat,lon
86
+ def Alerts( loc )
87
+ AlertsXML( loc )
88
+ end
89
+
90
+ private
91
+
92
+ def GeoLookupXML( loc )
93
+ #TODO: Build Out
94
+ puts "GeoLookup not yet implemented"
95
+
96
+ #base_url = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml"
97
+ #location_xml = RestClient.get base_url, {:params => {:query => loc}}
98
+ #GeoLookup.parse( location_xml )
99
+ end
100
+
101
+ def AlertsXML( loc )
102
+ base_url = "http://api.wunderground.com/auto/wui/geo/AlertsXML/index.xml"
103
+ alert_xml = RestClient.get base_url, {:params => {:query => loc}}
104
+ Alerts.parse( alert_xml )
105
+ end
106
+
107
+ def WXCurrentObXML( loc )
108
+ base_url = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml"
109
+ current_observations_xml = RestClient.get base_url, {:params => {:query => loc}}
110
+ CurrentObservation::Base.parse( current_observations_xml )
111
+ end
112
+
113
+ def ForecastXML( loc )
114
+ base_url = "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml"
115
+
116
+ forecast_xml = RestClient.get base_url, {:params => {:query => loc}}
117
+ Forecast::Base.parse( forecast_xml )
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,115 @@
1
+ module WeatherUnderground
2
+ module CurrentObservation
3
+
4
+ class IconSet
5
+ include HappyMapper
6
+
7
+ tag 'icon_set'
8
+
9
+ attribute :name, String
10
+ element :icon_url, String
11
+ end
12
+
13
+ class Icons
14
+ include HappyMapper
15
+
16
+ tag 'icons'
17
+
18
+ has_many :icon_sets, IconSet
19
+ end
20
+
21
+ class ObservationLocation
22
+ include HappyMapper
23
+
24
+ tag 'observation_location'
25
+
26
+ element :full, String
27
+ element :city, String
28
+ element :state, String
29
+ element :country, String
30
+ element :latitude, String
31
+ element :longitude, String
32
+ element :elevation, String
33
+ end
34
+
35
+ class DisplayLocation
36
+ include HappyMapper
37
+
38
+ tag 'display_location'
39
+
40
+ element :full, String
41
+ element :city, String
42
+ element :state, String
43
+ element :state_name, String
44
+ element :country, String
45
+ element :zip, String
46
+ element :latitude, String
47
+ element :longitude, String
48
+ element :elevation, String
49
+ end
50
+
51
+ class Image
52
+ include HappyMapper
53
+
54
+ tag 'image'
55
+
56
+ element :url, String
57
+ element :title, String
58
+ element :link, String
59
+ end
60
+
61
+ class Base
62
+ include HappyMapper
63
+
64
+ tag 'current_observation'
65
+
66
+ element :credit, String
67
+ element :credit_URL, String
68
+ element :station_id, String
69
+ element :image, Image
70
+ element :display_location, DisplayLocation
71
+ element :observation_location, ObservationLocation
72
+
73
+ element :station_id, String
74
+ element :observation_time, String
75
+ element :observation_time_rfc822, String
76
+ element :observation_epoch, String
77
+ element :local_time, String
78
+ element :local_time_rfc822, String
79
+ element :local_epoch, String
80
+ element :weather, String
81
+ element :temperature_string, String
82
+ element :temp_f, String
83
+ element :temp_c, String
84
+ element :relative_humidity, String
85
+ element :wind_string, String
86
+ element :wind_dir, String
87
+ element :wind_degrees, String
88
+ element :wind_mph, String
89
+ element :wind_gust_mph, String
90
+ element :pressure_string, String
91
+ element :pressure_mb, String
92
+ element :pressure_in, String
93
+ element :dewpoint_string, String
94
+ element :dewpoint_f, String
95
+ element :dewpoint_c, String
96
+ element :heat_index_string, String
97
+ element :heat_index_f, String
98
+ element :heat_index_c, String
99
+ element :windchill_string, String
100
+ element :windchill_f, String
101
+ element :windchill_c, String
102
+ element :visibility_mi, String
103
+ element :visibility_km, String
104
+
105
+ element :icons, Icons
106
+
107
+ element :icon_url_base, String
108
+ element :icon_url_name, String
109
+ element :icon, String
110
+ element :forecast_url, String
111
+ element :history_url, String
112
+ element :ob_url, String
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,124 @@
1
+ # Weather Underground API subject to TOS at http://www.wunderground.com/members/tos.asp#api
2
+ module WeatherUnderground
3
+ module Forecast
4
+ class High
5
+ include HappyMapper
6
+
7
+ tag 'high'
8
+
9
+ element :fahrenheit, Float
10
+ element :celsius, Float
11
+
12
+ def f
13
+ @fahrenheit
14
+ end
15
+
16
+ def c
17
+ @celsius
18
+ end
19
+ end
20
+
21
+ class Low
22
+ include HappyMapper
23
+
24
+ tag 'low'
25
+
26
+ element :fahrenheit, Float
27
+ element :celsius, Float
28
+
29
+ def f
30
+ @fahrenheit
31
+ end
32
+
33
+ def c
34
+ @celsius
35
+ end
36
+ end
37
+
38
+ class Date
39
+ include HappyMapper
40
+
41
+ tag 'date'
42
+
43
+ element :epoch, Integer
44
+ element :pretty_short, String
45
+ element :pretty, String
46
+ element :day, Integer
47
+ element :month, Integer
48
+ element :year, Integer
49
+ element :yday, Integer
50
+ element :hour, Integer
51
+ element :min, Integer
52
+ element :sec, Integer
53
+ element :isdst, Boolean
54
+ element :monthname, String
55
+ element :weekday_short, String
56
+ element :weekday, String
57
+ element :ampm, String
58
+ element :tz_short, String
59
+ element :tz_long, String
60
+ end
61
+
62
+ class SimpleForecastDay
63
+ include HappyMapper
64
+
65
+ tag 'forecastday'
66
+
67
+ element :period, Integer
68
+ element :icon, String
69
+ element :conditions, String
70
+ element :icon, String
71
+ element :skyicon, String
72
+ has_one :date_info, Date
73
+ has_one :high, High
74
+ has_one :low, Low
75
+
76
+ attr_accessor :datetime
77
+
78
+ after_parse { |o|
79
+ o.datetime = Time.at( o.date_info.epoch ) if o.date_info
80
+ o.date_info = nil
81
+ }
82
+ end
83
+
84
+ class TextForecastDay
85
+ include HappyMapper
86
+
87
+ tag 'forecastday'
88
+
89
+ element :period, Integer
90
+ element :icon, String
91
+ element :title, String
92
+ element :text, String, :tag => 'fcttext'
93
+
94
+ end
95
+
96
+ class TextForecast
97
+ include HappyMapper
98
+
99
+ tag 'txt_forecast'
100
+ element :date, Time
101
+ element :number, Integer
102
+ has_many :days, TextForecastDay
103
+ end
104
+
105
+ class SimpleForecast
106
+ include HappyMapper
107
+
108
+ tag 'simpleforecast'
109
+
110
+ has_many :days, SimpleForecastDay
111
+ end
112
+
113
+ class Base
114
+ include HappyMapper
115
+
116
+ tag 'forecast'
117
+
118
+ has_one :simple_forecast, SimpleForecast
119
+ has_one :text_forecast, TextForecast
120
+ end
121
+ end
122
+ end
123
+
124
+
@@ -0,0 +1,7 @@
1
+ # Weather Underground API subject to TOS at http://www.wunderground.com/members/tos.asp#api
2
+ # TODO: Build out
3
+ module WeatherUnderground
4
+ class GeoLookup
5
+ end
6
+ end
7
+
@@ -0,0 +1,5 @@
1
+ #Any helpers of sorts go here. Used as a mixin
2
+ module WeatherUnderground
3
+ module Utils
4
+ end
5
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather-underground
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Dague
@@ -125,13 +125,20 @@ extra_rdoc_files:
125
125
  - PostInstall.txt
126
126
  - README.rdoc
127
127
  files:
128
+ - Gemfile
128
129
  - History.txt
129
130
  - Manifest.txt
130
131
  - PostInstall.txt
131
132
  - README.rdoc
132
133
  - Rakefile
133
134
  - lib/weather-underground.rb
135
+ - lib/weather-underground/alerts.rb
136
+ - lib/weather-underground/base.rb
137
+ - lib/weather-underground/current_observation.rb
138
+ - lib/weather-underground/forecast.rb
139
+ - lib/weather-underground/geo_lookup.rb
134
140
  - lib/weather-underground/uploader.rb
141
+ - lib/weather-underground/utils.rb
135
142
  - script/console
136
143
  - script/destroy
137
144
  - script/generate