rubyweather 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/README +65 -52
  2. data/example/forecast.rhtml +26 -0
  3. data/example/weather_32/0.png +0 -0
  4. data/example/weather_32/1.png +0 -0
  5. data/example/weather_32/10.png +0 -0
  6. data/example/weather_32/11.png +0 -0
  7. data/example/weather_32/12.png +0 -0
  8. data/example/weather_32/13.png +0 -0
  9. data/example/weather_32/14.png +0 -0
  10. data/example/weather_32/15.png +0 -0
  11. data/example/weather_32/16.png +0 -0
  12. data/example/weather_32/17.png +0 -0
  13. data/example/weather_32/18.png +0 -0
  14. data/example/weather_32/19.png +0 -0
  15. data/example/weather_32/2.png +0 -0
  16. data/example/weather_32/20.png +0 -0
  17. data/example/weather_32/21.png +0 -0
  18. data/example/weather_32/22.png +0 -0
  19. data/example/weather_32/23.png +0 -0
  20. data/example/weather_32/24.png +0 -0
  21. data/example/weather_32/25.png +0 -0
  22. data/example/weather_32/26.png +0 -0
  23. data/example/weather_32/27.png +0 -0
  24. data/example/weather_32/28.png +0 -0
  25. data/example/weather_32/29.png +0 -0
  26. data/example/weather_32/3.png +0 -0
  27. data/example/weather_32/30.png +0 -0
  28. data/example/weather_32/31.png +0 -0
  29. data/example/weather_32/32.png +0 -0
  30. data/example/weather_32/33.png +0 -0
  31. data/example/weather_32/34.png +0 -0
  32. data/example/weather_32/35.png +0 -0
  33. data/example/weather_32/36.png +0 -0
  34. data/example/weather_32/37.png +0 -0
  35. data/example/weather_32/38.png +0 -0
  36. data/example/weather_32/39.png +0 -0
  37. data/example/weather_32/4.png +0 -0
  38. data/example/weather_32/40.png +0 -0
  39. data/example/weather_32/41.png +0 -0
  40. data/example/weather_32/42.png +0 -0
  41. data/example/weather_32/43.png +0 -0
  42. data/example/weather_32/44.png +0 -0
  43. data/example/weather_32/45.png +0 -0
  44. data/example/weather_32/46.png +0 -0
  45. data/example/weather_32/47.png +0 -0
  46. data/example/weather_32/5.png +0 -0
  47. data/example/weather_32/6.png +0 -0
  48. data/example/weather_32/7.png +0 -0
  49. data/example/weather_32/8.png +0 -0
  50. data/example/weather_32/9.png +0 -0
  51. data/example/weather_32/Thumbs.db +0 -0
  52. data/example/weather_32/WS_FTP.LOG +49 -0
  53. data/example/weather_32/na.png +0 -0
  54. data/example/weather_portlet_controller.rb +49 -0
  55. data/init.rb +3 -0
  56. data/install.rb +0 -0
  57. data/lib/{forecast.rb → weather/forecast.rb} +56 -20
  58. data/lib/{service.rb → weather/service.rb} +1 -1
  59. data/lib/{util.rb → weather/util.rb} +0 -0
  60. data/test/forecast_test.rb +9 -3
  61. data/test/service_test.rb +3 -3
  62. data/weather.rb +5 -3
  63. metadata +60 -5
data/README CHANGED
@@ -8,87 +8,94 @@ License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
8
8
 
9
9
  Simple usage example:
10
10
 
11
- require 'rubygems'
12
- require_gem 'rubyweather'
11
+ require 'rubygems'
12
+ require_gem 'rubyweather'
13
13
 
14
- require 'weather'
14
+ require 'weather/service'
15
15
 
16
- service = Weather::Service.new
17
- service.partner_id = <b>your partner id</b>
18
- service.license_key = <b>your license key</b>
16
+ service = Weather::Service.new
17
+ service.partner_id = <b>your partner id</b>
18
+ service.license_key = <b>your license key</b>
19
19
 
20
- locations = service.find_location('Toronto')
21
- puts "Matching Locations: " + locations.inspect
20
+ locations = service.find_location('Toronto')
21
+ puts "Matching Locations: " + locations.inspect
22
22
 
23
23
  The above will print out a list of available locations and their codes. We can
24
24
  now use these codes to fetch the weather data for our city:
25
25
 
26
- forecast = service.fetch_forecast("CAXX0504", 5)
26
+ forecast = service.fetch_forecast("CAXX0504", 5)
27
27
 
28
- puts "Location: %s" % forecast.location_name
28
+ puts "Location: %s" % forecast.location_name
29
29
 
30
- puts "Current Temperature: %s" % forecast.current.temperature
31
- puts "Current Windspeed: %s" % forecast.current.wind.speed
30
+ puts "Current Temperature: %s" % forecast.current.temperature
31
+ puts "Current Windspeed: %s" % forecast.current.wind.speed
32
32
 
33
- puts "Tomorrow's High: %s" % forecast.tomorrow.high
34
- puts "Tomorrow's Outlook: %s" % forecast.tomorrow.outlook
35
- puts "Tomorrow's Wind Direction: %s" % forecast.tomorrow.wind.direction
33
+ puts "Tomorrow's High: %s" % forecast.tomorrow.high
34
+ puts "Tomorrow's Outlook: %s" % forecast.tomorrow.outlook
35
+ puts "Tomorrow's Wind Direction: %s" % forecast.tomorrow.wind.direction
36
36
 
37
37
  Forecasts for days in the future are accessed via <tt>forecast.day(#)</tt> where <tt>#</tt> is the number of day sinto the future
38
38
  (assuming that you've fetched data for as many days in your <tt>service.fetch_forecast</tt> request):
39
39
 
40
- puts "High 3 days from now: %s" % forecast.day(3).high
41
- puts "Probability of precipitation 4 days from now: %s" % forecast.day(4).pop
40
+ puts "High 3 days from now: %s" % forecast.day(3).high
41
+ puts "Probability of precipitation 4 days from now: %s" % forecast.day(4).pop
42
42
 
43
43
  There are a lot of attributes you can fetch for a forecast day. Here are just a few:
44
44
 
45
- <tt>temp</tt>, <tt>temperature</tt>, <tt>temp</tt>::
46
- The temperature. For future days this is equivalent to the low for nighttime and high for daytime.
47
- <tt>icon</tt>::
48
- The number of the icon gif file from the weather.com SDK[http://www.weather.com/services/xmloap.html] that
49
- identifies the conditions (e.g. a little icon of a cloud with rain, or sun, or whatever).
50
- <tt>outlook</tt>, <tt>outlook_brief</tt>::
51
- Brief text describing the conditions (e.g. "Mostly Cloudy", "Rain", "Scattered T-Storms"). An abbreviated
52
- version is available in <tt>outlook_brief</tt> (e.g. "M Cloudy", "Scat T-Storms").
53
- <tt>low</tt>, <tt>lo</tt>::
54
- The forecasted low temperature. (Not available for current conditions)
55
- <tt>high</tt>, <tt>hi</tt>::
56
- The forecasted high temperature. (Not available for current conditions)
57
- <tt>wind</tt>, <tt>wind.direction</tt>, <tt>wind.speed</tt>, <tt>wind.heading</tt>::
58
- Wind conditions. The <tt>wind</tt> attribute returns an object with sub-attributes.
59
- <tt>pop</tt>, <tt>ppcp</tt>::
60
- Probability of precipitation.
61
- <tt>date</tt>::
62
- The date that this forecast is for, returned as a ruby Time object.
63
- <tt>sunrise</tt>::
64
- The time of sunrise on the day of the forecast.
65
- <tt>sunset</tt>::
66
- The time of sunset on the day of the forecast.
67
-
68
- Additionally, all (or at least most) of the attributes for a given day in the raw weather.com xml data are
69
- also available. For example, you can call forecast.tomorrow.dewp to get the dewpoint, because the xml file
45
+ +temp+, +temperature+:: The temperature. For future days this is equivalent to the low for nighttime, and high for daytime.
46
+ +icon+:: The number of the icon gif file from the weather.com SDK[http://www.weather.com/services/xmloap.html] that
47
+ identifies the conditions (e.g. a little icon of a cloud with rain, or sun, or whatever).
48
+ +outlook+:: Brief text describing the conditions (e.g. "Mostly Cloudy", "Rain", "Scattered T-Storms").
49
+ +outlook_brief+:: An abbreviated version of +outlook+ (e.g. "M Cloudy", "Scat T-Storms").
50
+ +low+, +lo+:: The forecasted low temperature. (Not available for current conditions)
51
+ +high+, +hi+:: The forecasted high temperature. (Not available for current conditions)
52
+ +wind+:: Wind conditions. The <tt>wind</tt> attribute returns an object with sub-attributes that can be
53
+ addressed like <tt>wind.direction</tt>, <tt>wind.speed</tt>, <tt>wind.heading</tt>, etc.
54
+ +pop+, +ppcp+:: Probability of precipitation.
55
+ +date+:: The date that this forecast is for, returned as a ruby Time object.
56
+ +sunrise+:: The time of sunrise on the day of the forecast.
57
+ +sunset+:: The time of sunset on the day of the forecast.
58
+ +latest_update+:: The datetime when the conditions were last measured/forecast.
59
+
60
+ Additionally, most of the attributes for a given day in the raw weather.com xml data are
61
+ also directly accessible. For example, you can call forecast.tomorrow.dewp to get the dewpoint, because the xml file
70
62
  contains a <tt>dewp</tt> element for that day. Have a look at #test/test_weather.xml to see what data is
71
63
  available in the xml file. Note though that raw xml elements will be returned as a string, without any nice
72
64
  class casting or unit conversion.
73
65
 
74
- I encourage other programmers to add more functionality to the lib/forecast.rb module to provide better
75
- accessor methods for the underlying xml data.
66
+ Other programmers are encouraged to add more functionality to the lib/forecast.rb module to provide better
67
+ accessor methods for the underlying xml data. See below for how to obtain subversion access to contribute
68
+ your changes back to the project.
76
69
 
77
70
  == Download
78
71
 
79
72
  You can download the latest stable version of RubyWeather from http://rubyforge.org/projects/rubyweather/.
80
- Alternatively, the files <em>may</em> be available from http://roughest.net/rubyweather (but no promises -- the
81
- rubyforge site is a better bet).
82
73
 
83
- You can also check out the latest copy via subversion from svn://rubyforge.org//var/svn/rubyweather/trunk. If you would
84
- like to contribute back your changes to the code, please contact me via the rubyforge project site to obtain a subversion
85
- account.
74
+ You can also check out the latest copy via subversion from svn://rubyforge.org//var/svn/rubyweather/trunk.
75
+ If you would like to contribute back your changes to the code, please contact me via the rubyforge project
76
+ site to obtain a subversion account.
86
77
 
87
- == Note
78
+ RubyWeather can also be installed as a Rails plugin using the following command from your Rails application's
79
+ directory:
80
+
81
+ ./script/plugin install -x svn://rubyforge.org//var/svn/rubyweather/trunk
82
+
83
+ == Sample Rails Controller
84
+
85
+ In the <tt>example</tt> directory you will find a sample Rails controller that uses RubyWeather to show
86
+ a simple weather forecast. To try this out:
87
+
88
+ 1. Copy the controller into your Rails app's <tt>app/controllers/</tt>.
89
+ 2. Copy the <tt>forecast.rhtml</tt> template into <tt>apps/view/weather_portlet/</tt>
90
+ 3. Copy <tt>weather_32</tt> into <tt>public/images/</tt>.
91
+
92
+ Fire up your Rails server, and go to <tt>/weather_portlet/forecast</tt> to see the controller in action.
93
+
94
+ == Note About Weather.com Licensing & Registration
88
95
 
89
96
  To use this library you will need a partner id and license key from
90
97
  weather.com. The service is completely free, but requires that you agree
91
- to weather.com's legal stuff, which, among other things, requires your software
98
+ to weather.com's legal stuff, which, among other things, asks that your software
92
99
  to include a link back to the weather.com website (although this is not actually
93
100
  enforced in any way by the service).
94
101
 
@@ -96,7 +103,13 @@ To obtain the free license visit http://www.weather.com/services/xmloap.html.
96
103
  This will also allow you to download an SDK that includes nice weather icons for
97
104
  use with the data.
98
105
 
99
- == License
106
+ Note that weather.com doesn't seem to be enforcing the partner id/license key at this time.
107
+ You can specify any value for partner id and license key (e.g. par=123456&key=abcdefg) and
108
+ the weather.com service will happily accept it (in fact, you can even leave both fields blank,
109
+ i.e. part=&key=). However, this is probably unintentional and subject to change, so it is
110
+ highly recommended that you obtain a valid id and key.
111
+
112
+ == Software License
100
113
 
101
114
  This program is free software; you can redistribute it and/or modify
102
115
  it under the terms of the GNU General Public License as published by
@@ -0,0 +1,26 @@
1
+
2
+ <table>
3
+ <thead>
4
+ <tr>
5
+ <% for d in @forecasts.first -%>
6
+ <th><%= d.date.strftime('%a') %></th>
7
+ <% end -%>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <% for f in @forecasts -%>
12
+ <tr>
13
+ <th colspan="<%= f.entries.size %>"><%= f.location_city %></th>
14
+ <!-- LATEST UPDATE: <%= f.latest_update %> -->
15
+ </tr>
16
+ <tr>
17
+ <% for d in f -%>
18
+ <td>
19
+ <%= image_tag("weather_32/"+d.icon.to_s+".png", {:alt => d.outlook, :title => outlook_tooltip(d)}) %>
20
+ <br /><%= d.temp.nil? ? "N/A" : d.temp.to_s+"&deg;" %>
21
+ </td>
22
+ <% end -%>
23
+ </tr>
24
+ <% end -%>
25
+ </tbody>
26
+ </table>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,49 @@
1
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\0.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 0.png
2
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\1.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 1.png
3
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\10.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 10.png
4
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\11.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 11.png
5
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\12.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 12.png
6
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\13.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 13.png
7
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\14.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 14.png
8
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\15.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 15.png
9
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\16.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 16.png
10
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\17.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 17.png
11
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\18.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 18.png
12
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\19.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 19.png
13
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\2.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 2.png
14
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\20.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 20.png
15
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\21.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 21.png
16
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\22.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 22.png
17
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\23.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 23.png
18
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\24.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 24.png
19
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\25.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 25.png
20
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\26.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 26.png
21
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\27.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 27.png
22
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\28.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 28.png
23
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\29.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 29.png
24
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\3.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 3.png
25
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\30.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 30.png
26
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\31.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 31.png
27
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\32.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 32.png
28
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\33.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 33.png
29
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\34.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 34.png
30
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\35.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 35.png
31
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\36.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 36.png
32
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\37.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 37.png
33
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\38.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 38.png
34
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\39.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 39.png
35
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\4.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 4.png
36
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\40.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 40.png
37
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\41.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 41.png
38
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\42.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 42.png
39
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\43.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 43.png
40
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\44.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 44.png
41
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\45.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 45.png
42
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\46.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 46.png
43
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\47.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 47.png
44
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\5.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 5.png
45
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\6.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 6.png
46
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\7.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 7.png
47
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\8.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 8.png
48
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\9.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 9.png
49
+ 2005.11.14 11:00 B U:\cq's\14773\wx_icons32x32\na.png <-- ftp.twc.weather.com /Server HD/Web Folder/wx_icons_pngs/wx_icons32x32 na.png
Binary file
@@ -0,0 +1,49 @@
1
+ require 'portlet_controller'
2
+ require_gem 'rubyweather'
3
+ require 'weather/service'
4
+
5
+ # Simple Rails controller that shows the weather forecast.
6
+ class WeatherPortletController < ActionController::Base
7
+
8
+ configurable
9
+
10
+ def rescue_action_in_public(exception)
11
+ render :text => <<ERROR
12
+ <em>Sorry, this portlet is temporarily out of service.</em>
13
+
14
+ <!--
15
+ ERROR: #{exception.message}
16
+ #{exception.backtrace.join("\n\t\t\t")}
17
+ -->
18
+ ERROR
19
+ end
20
+
21
+ def forecast
22
+ if params['locations'] and params['locations'].is_array? and params['locations'].length > 0
23
+ locations = params['locations']
24
+ else
25
+ locations = ["CAXX0504", "CAXX0301", "CAXX0054"]
26
+ end
27
+
28
+ days = params['days'] || 5
29
+
30
+ @forecasts = []
31
+
32
+ service = Weather::Service.new
33
+ locations.each do |loc|
34
+ @forecasts << service.fetch_forecast(loc, days)
35
+ end
36
+ end
37
+
38
+ # Normally this would go in the weather_portlet_helper, but to reduce the number of files in this example it is included.
39
+ def outlook_tooltip(d)
40
+ tooltip = d.outlook.to_s
41
+ tooltip += ", PoP: "+d.pop.to_s+"%" if (not d.pop.nil?)
42
+
43
+ return tooltip
44
+ end
45
+ helper_method :outlook_tooltip
46
+ hidden_actions :outlook_tooltip
47
+
48
+ end
49
+
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require File.dirname(File.expand_path(__FILE__)) + '/lib/weather/util'
2
+ require File.dirname(File.expand_path(__FILE__)) + '/lib/weather/service'
3
+ require File.dirname(File.expand_path(__FILE__)) + '/lib/weather/forecast'
data/install.rb ADDED
File without changes
@@ -4,7 +4,8 @@
4
4
  # License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
5
5
  #
6
6
 
7
- require File.dirname(__FILE__) + '/util'
7
+ require 'time'
8
+ require File.dirname(File.expand_path(__FILE__)) + '/util'
8
9
 
9
10
  module Weather
10
11
 
@@ -27,9 +28,16 @@ module Weather
27
28
  end
28
29
 
29
30
  @xml = weather_xmldoc
31
+
32
+ # add the lsup (latest update) element to individual days to make parsing easier later on
33
+ # FIXME: I can't seem to add the lsup as an element (which would be the consistent way to do it)... adding it as an attribute seems to work though
34
+ lsup = @xml.root.elements['dayf'].elements['lsup'].text
35
+ REXML::XPath.match(@xml, "//dayf/day").each do |dxml|
36
+ dxml.add_attribute "lsup", lsup
37
+ end
30
38
  end
31
39
 
32
- # Returns the current conditions as a Conditions object.
40
+ # The current conditions as a Conditions object.
33
41
  def current
34
42
  CurrentConditions.new(xml.root.elements['cc'])
35
43
  end
@@ -39,7 +47,7 @@ module Weather
39
47
  day(1)
40
48
  end
41
49
 
42
- # Returns the conditions for the given day (0 = today, 1 = tomorrow, etc.)
50
+ # The conditions for the given day (0 = today, 1 = tomorrow, etc.)
43
51
  # The maximum day number depends on the data available in the xml that was used to create this Forecast.
44
52
  def day(num)
45
53
  element = xml.root.elements['dayf'].elements["day[@d='#{num.to_s}']"]
@@ -55,7 +63,7 @@ module Weather
55
63
  end
56
64
  end
57
65
 
58
- # Returns the conditions for the given night (0 = tonight, 1 = tomorrow night, etc.)
66
+ # The conditions for the given night (0 = tonight, 1 = tomorrow night, etc.)
59
67
  # The maximum day number depends on the data available in the xml that was used to create this Forecast.
60
68
  def night(num)
61
69
  element = xml.root.elements['dayf'].elements["day[@d='#{num.to_s}']"]
@@ -79,12 +87,12 @@ module Weather
79
87
  end
80
88
  end
81
89
 
82
- # Returns the full human-readable name of the place that this Forecast is for.
90
+ # The full human-readable name of the place that this Forecast is for.
83
91
  def location_name
84
92
  xml.root.elements['loc'].elements['dnam'].text
85
93
  end
86
94
 
87
- # Returns the name of the city that this Forecast is for.
95
+ # The name of the city that this Forecast is for.
88
96
  def location_city
89
97
  xml.root.elements['loc'].elements['dnam'].text.split(",").first
90
98
  end
@@ -94,10 +102,25 @@ module Weather
94
102
  xml.root.elements['loc'].attributes['id']
95
103
  end
96
104
 
97
- # Returns true if the units returned by this Forecast will be in the metric system (i.e. Celcius).
105
+ # True if the units returned by this Forecast will be in the metric system (i.e. Celcius).
98
106
  def metric?
99
107
  xml.root.elements['head'].elements['ut'].text == "C"
100
108
  end
109
+
110
+ # The date and time when the conditions were last measured/forecast.
111
+ # Returned as a Time object.
112
+ #
113
+ # Note that this is a bit misleading, because the Forecast actually contains
114
+ # two "latest update" times -- one for the current conditions and the other
115
+ # for the future forecast. This method will return the latest update time
116
+ # of the <em>future forecast</em>. If you want the latest update time of the current
117
+ # conditions, you should do:
118
+ #
119
+ # forecast.current.latest_update
120
+ #
121
+ def latest_update
122
+ Time.parse(xml.root.elements['dayf'].elements['lsup'].text)
123
+ end
101
124
  end
102
125
 
103
126
  # Abstract class that all Forecast entities (roughly "days") are based on.
@@ -113,15 +136,22 @@ module Weather
113
136
  end
114
137
  end
115
138
 
116
- # Returns the wind conditions as an anonymous object (i.e. wind.d for wind
139
+ # The wind conditions as an anonymous object (i.e. wind.d for wind
117
140
  # direction, wind.s for wind speed, etc.) See the <wind> element in the
118
141
  # weather.com XML data spec for more info.
119
142
  def wind
120
143
  fix_wind(complex_attribute(@xml.elements['wind']))
121
144
  end
145
+
146
+ # The date and time when the conditions were last measured/forecast.
147
+ # Returned as a Time object.
148
+ def latest_update
149
+ Time.parse(self.lsup)
150
+ end
151
+
122
152
 
123
153
  private
124
- # Returns the element specified by name as a cleaned-up temperature value.
154
+ # The element specified by name as a cleaned-up temperature value.
125
155
  # That is, if the temperature is "N/A", then nil is returned; otherwise
126
156
  # the value is converted to an integer.
127
157
  def clean_temp(name)
@@ -134,7 +164,7 @@ module Weather
134
164
  end
135
165
  end
136
166
 
137
- # Return the given xml element as an anonymous object, with the text nodes of the element's
167
+ # The given xml element as an anonymous object, with the text nodes of the element's
138
168
  # immediate children available as accessor methods.
139
169
  # This allows for accessing attributes that have child elements (i.e. wind, bar, etc.)
140
170
  # as anonymous objects (i.e. wind.d for wind direction, wind.s for wind speed, etc.)
@@ -182,8 +212,8 @@ module Weather
182
212
  def temp
183
213
  clean_temp('tmp')
184
214
  end
185
- alias_method :tmp, :temp
186
- alias_method :temperature, :temp
215
+ alias tmp temp
216
+ alias temperature temp
187
217
 
188
218
  def outlook
189
219
  xml.elements['t'].text
@@ -196,7 +226,7 @@ module Weather
196
226
  def pop
197
227
  nil
198
228
  end
199
- alias_method :ppcp, :pop
229
+ alias ppcp pop
200
230
 
201
231
  def date
202
232
  Time.now
@@ -224,6 +254,12 @@ module Weather
224
254
  end
225
255
  end
226
256
 
257
+ # The date and time when the conditions were last measured/forecast.
258
+ # Returned as a Time object.
259
+ def latest_update
260
+ Time.parse(@xml.attributes['lsup'])
261
+ end
262
+
227
263
  def wind
228
264
  fix_wind(complex_attribute(mypart.elements['wind']))
229
265
  end
@@ -241,12 +277,12 @@ module Weather
241
277
  def high
242
278
  clean_temp('hi')
243
279
  end
244
- alias_method :hi, :high
280
+ alias hi high
245
281
 
246
282
  def low
247
283
  clean_temp('low')
248
284
  end
249
- alias_method :lo, :low
285
+ alias lo low
250
286
 
251
287
 
252
288
  def outlook
@@ -260,7 +296,7 @@ module Weather
260
296
  def pop
261
297
  mypart.elements['ppcp'].text.to_i
262
298
  end
263
- alias_method :ppcp, :pop
299
+ alias ppcp pop
264
300
 
265
301
  def sunrise
266
302
  hour,minute = @xml.elements['sunr'].text.split(" ").first.split(":")
@@ -287,8 +323,8 @@ module Weather
287
323
  def temp
288
324
  high
289
325
  end
290
- alias_method :tmp, :temp
291
- alias_method :temperature, :temp
326
+ alias tmp temp
327
+ alias temperature temp
292
328
 
293
329
  private
294
330
  def mypart
@@ -305,8 +341,8 @@ module Weather
305
341
  def temp
306
342
  low
307
343
  end
308
- alias_method :tmp, :temp
309
- alias_method :temperature, :temp
344
+ alias tmp temp
345
+ alias temperature temp
310
346
 
311
347
  private
312
348
  def mypart
@@ -7,7 +7,7 @@
7
7
  require 'net/http'
8
8
  require 'rexml/document'
9
9
 
10
- require File.dirname(__FILE__) + '/forecast'
10
+ require File.dirname(File.expand_path(__FILE__)) + '/forecast'
11
11
 
12
12
  module Weather
13
13
 
File without changes
@@ -5,9 +5,10 @@
5
5
  #
6
6
 
7
7
  require 'test/unit'
8
- require File.dirname(__FILE__) + '/../lib/service'
9
- require File.dirname(__FILE__) + '/../lib/forecast'
10
- require File.dirname(__FILE__) + '/../lib/util'
8
+ require 'time'
9
+ require File.dirname(__FILE__) + '/../lib/weather/service'
10
+ require File.dirname(__FILE__) + '/../lib/weather/forecast'
11
+ require File.dirname(__FILE__) + '/../lib/weather/util'
11
12
 
12
13
  class ForecastTest < Test::Unit::TestCase
13
14
 
@@ -74,4 +75,9 @@ class ForecastTest < Test::Unit::TestCase
74
75
  assert_equal(8, tomorrow_night.wind.speed)
75
76
  end
76
77
 
78
+ def test_latest_update
79
+ assert_equal Time.parse("2006-07-14 14:15"), @forecast.latest_update
80
+ assert_equal Time.parse("2006-07-14 15:00"), @forecast.current.latest_update
81
+ assert_equal Time.parse("2006-07-14 14:15"), @forecast.tomorrow.latest_update
82
+ end
77
83
  end
data/test/service_test.rb CHANGED
@@ -5,14 +5,14 @@
5
5
  #
6
6
 
7
7
  require 'test/unit'
8
- require File.dirname(__FILE__) + '/../lib/service'
8
+ require File.dirname(__FILE__) + '/../lib/weather/service'
9
9
 
10
10
  if not ENV['WEATHER_COM_PARTNER_ID']
11
- puts "WARNING: You should set the WEATHER_COM_PARTNER_ID env variable (i.e. export WEATHER_COM_PARTNER_ID=###########) before running this test."
11
+ puts "WARNING: You should set the WEATHER_COM_PARTNER_ID env variable (i.e. export WEATHER_COM_PARTNER_ID=<your weather.com partner id>) before running this test."
12
12
  end
13
13
 
14
14
  if not ENV['WEATHER_COM_LICENSE_KEY']
15
- puts "WARNING: You should set the WEATHER_COM_LICENSE_KEY env variable (i.e. export WEATHER_COM_LICENSE_KEY=###########) before running this test."
15
+ puts "WARNING: You should set the WEATHER_COM_LICENSE_KEY env variable (i.e. export WEATHER_COM_LICENSE_KEY=<your weather.com license key>) before running this test."
16
16
  end
17
17
 
18
18
  class ServiceTest < Test::Unit::TestCase
data/weather.rb CHANGED
@@ -1,3 +1,5 @@
1
- require 'lib/util'
2
- require 'lib/forecast'
3
- require 'lib/service'
1
+ # DEPRECATED
2
+ # This file will likely go away within the next few versions.
3
+ # Use init.rb instead, or just require 'weather/service'
4
+
5
+ require File.dirname(File.expand_path(__FILE__)) + '/init'
metadata CHANGED
@@ -3,12 +3,11 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rubyweather
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.1
6
+ version: 1.0.0
7
7
  date: 2006-07-28 00:00:00 -04:00
8
8
  summary: Client library for accessing weather.com's xoap weather data.
9
9
  require_paths:
10
10
  - lib
11
- - .
12
11
  email: matt@roughest.net
13
12
  homepage: http://rubyforge.org/projects/rubyweather
14
13
  rubyforge_project: rubyweather
@@ -30,14 +29,70 @@ authors:
30
29
  - Matt Zukowski
31
30
  files:
32
31
  - weather.rb
33
- - lib/service.rb
34
- - lib/forecast.rb
35
- - lib/util.rb
32
+ - install.rb
33
+ - init.rb
34
+ - lib/weather/service.rb
35
+ - lib/weather/forecast.rb
36
+ - lib/weather/util.rb
36
37
  - LICENSE
37
38
  - README
38
39
  - test/forecast_test.rb
39
40
  - test/service_test.rb
40
41
  - test/test_weather.xml
42
+ - example/weather_32
43
+ - example/weather_portlet_controller.rb
44
+ - example/forecast.rhtml
45
+ - example/weather_32/0.png
46
+ - example/weather_32/1.png
47
+ - example/weather_32/2.png
48
+ - example/weather_32/3.png
49
+ - example/weather_32/4.png
50
+ - example/weather_32/5.png
51
+ - example/weather_32/6.png
52
+ - example/weather_32/7.png
53
+ - example/weather_32/8.png
54
+ - example/weather_32/9.png
55
+ - example/weather_32/WS_FTP.LOG
56
+ - example/weather_32/Thumbs.db
57
+ - example/weather_32/na.png
58
+ - example/weather_32/10.png
59
+ - example/weather_32/11.png
60
+ - example/weather_32/12.png
61
+ - example/weather_32/13.png
62
+ - example/weather_32/14.png
63
+ - example/weather_32/15.png
64
+ - example/weather_32/16.png
65
+ - example/weather_32/17.png
66
+ - example/weather_32/18.png
67
+ - example/weather_32/19.png
68
+ - example/weather_32/20.png
69
+ - example/weather_32/21.png
70
+ - example/weather_32/22.png
71
+ - example/weather_32/23.png
72
+ - example/weather_32/24.png
73
+ - example/weather_32/25.png
74
+ - example/weather_32/26.png
75
+ - example/weather_32/27.png
76
+ - example/weather_32/28.png
77
+ - example/weather_32/29.png
78
+ - example/weather_32/30.png
79
+ - example/weather_32/31.png
80
+ - example/weather_32/32.png
81
+ - example/weather_32/33.png
82
+ - example/weather_32/34.png
83
+ - example/weather_32/35.png
84
+ - example/weather_32/36.png
85
+ - example/weather_32/37.png
86
+ - example/weather_32/38.png
87
+ - example/weather_32/39.png
88
+ - example/weather_32/40.png
89
+ - example/weather_32/41.png
90
+ - example/weather_32/42.png
91
+ - example/weather_32/43.png
92
+ - example/weather_32/44.png
93
+ - example/weather_32/45.png
94
+ - example/weather_32/46.png
95
+ - example/weather_32/47.png
41
96
  test_files:
42
97
  - test/forecast_test.rb
43
98
  - test/service_test.rb