rubyweather 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +504 -0
- data/README +113 -0
- data/lib/forecast.rb +318 -0
- data/lib/service.rb +84 -0
- data/lib/util.rb +17 -0
- data/test/forecast_test.rb +77 -0
- data/test/service_test.rb +62 -0
- data/test/test_weather.xml +215 -0
- data/weather.rb +3 -0
- metadata +60 -0
data/lib/util.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Zukowski (http://blog.roughest.net)
|
3
|
+
# Copyright:: Copyright (c) 2006 Urbacon Ltd.
|
4
|
+
# License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
|
5
|
+
#
|
6
|
+
|
7
|
+
module Weather
|
8
|
+
|
9
|
+
# Misc utility functions used by the weather library.
|
10
|
+
#
|
11
|
+
# NOTE: This used to contain unit converstion routines (i.e. F to C) but
|
12
|
+
# now we just fetch the desired unit type in the Weather.com service query,
|
13
|
+
# so this module is left only as a placeholder for future functionality.
|
14
|
+
module Util
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Zukowski (http://blog.roughest.net)
|
3
|
+
# Copyright:: Copyright (c) 2006 Urbacon Ltd.
|
4
|
+
# License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
|
5
|
+
#
|
6
|
+
|
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'
|
11
|
+
|
12
|
+
class ForecastTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@filename = File.expand_path(File.dirname(__FILE__) + "/test_weather.xml")
|
16
|
+
#puts "Test file exists? "+(FileTest.exists? @filename).to_s
|
17
|
+
@forecast = Weather::Service.new.load_forecast(@filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_iteration
|
21
|
+
assert_equal(5, @forecast.entries.size)
|
22
|
+
|
23
|
+
@forecast.each do |f|
|
24
|
+
assert_kind_of(Weather::Forecast::Conditions, f)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_attributes
|
29
|
+
assert_equal("Toronto, Canada", @forecast.location_name)
|
30
|
+
assert_equal("Toronto", @forecast.location_city)
|
31
|
+
assert_equal("CAXX0504", @forecast.location_code)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_current_conditions
|
35
|
+
cur = @forecast.current
|
36
|
+
|
37
|
+
assert_equal(84, cur.temp)
|
38
|
+
assert_not_equal(85, cur.temp) # just to make sure there isn't something funny going on
|
39
|
+
assert_equal(28, cur.icon)
|
40
|
+
assert_equal("Mostly Cloudy", cur.outlook)
|
41
|
+
|
42
|
+
# test implicit attribute
|
43
|
+
assert_equal("Unlimited", cur.vis)
|
44
|
+
|
45
|
+
# test complex attribute
|
46
|
+
assert_equal("13", cur.wind.s)
|
47
|
+
assert_equal(13, cur.wind.speed)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_future_conditions
|
51
|
+
today = @forecast.day(0)
|
52
|
+
tomorrow = @forecast.day(1)
|
53
|
+
tomorrow_night = @forecast.night(1)
|
54
|
+
|
55
|
+
assert_equal(14, today.date.day)
|
56
|
+
assert_equal(7, today.date.mon)
|
57
|
+
assert_equal(2006, today.date.year)
|
58
|
+
assert_equal(today.date.day + 1, tomorrow.date.day)
|
59
|
+
assert_equal(87, tomorrow.high)
|
60
|
+
assert_equal(87, tomorrow.hi)
|
61
|
+
assert_equal(69, tomorrow.low)
|
62
|
+
assert_equal(69, tomorrow.lo)
|
63
|
+
assert_equal(37, tomorrow.icon)
|
64
|
+
|
65
|
+
assert_equal(33, tomorrow_night.icon)
|
66
|
+
assert_equal("Mostly Clear", tomorrow_night.outlook)
|
67
|
+
|
68
|
+
# test implicit attribute
|
69
|
+
assert_equal("M Clear", tomorrow_night.bt)
|
70
|
+
|
71
|
+
# test complex attribute
|
72
|
+
assert_equal(314, tomorrow_night.wind.direction)
|
73
|
+
assert_equal("NW", tomorrow_night.wind.heading)
|
74
|
+
assert_equal(8, tomorrow_night.wind.speed)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Zukowski (http://blog.roughest.net)
|
3
|
+
# Copyright:: Copyright (c) 2006 Urbacon Ltd.
|
4
|
+
# License:: GNU Lesser General Public License v2.1 (LGPL 2.1)
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require File.dirname(__FILE__) + '/../lib/service'
|
9
|
+
|
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."
|
12
|
+
end
|
13
|
+
|
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."
|
16
|
+
end
|
17
|
+
|
18
|
+
class ServiceTest < Test::Unit::TestCase
|
19
|
+
TEST_LOCATION = "CAXX0504"
|
20
|
+
|
21
|
+
# Note that for this test to work the WEATHER.COM_PARTNER_ID and WEATHER.COM_LICENSE_KEY
|
22
|
+
# environment variables must be set!
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@filename = File.expand_path(File.dirname(__FILE__) + "/test_weather.xml")
|
26
|
+
@service = Weather::Service.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_load_forecast
|
30
|
+
forecast = @service.load_forecast(@filename)
|
31
|
+
assert_kind_of(Weather::Forecast::Forecast, forecast)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_fetch_forecast
|
35
|
+
forecast = @service.fetch_forecast(TEST_LOCATION, 8)
|
36
|
+
|
37
|
+
assert_kind_of(Weather::Forecast::Forecast, forecast)
|
38
|
+
assert_equal("CAXX0504", forecast.location_code)
|
39
|
+
assert_equal("Toronto", forecast.location_city)
|
40
|
+
assert_equal(8, forecast.entries.size)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_imperial_metric_choice
|
44
|
+
@service.imperial = true
|
45
|
+
forecast = @service.fetch_forecast(TEST_LOCATION, 2)
|
46
|
+
assert(!forecast.metric?)
|
47
|
+
|
48
|
+
@service.imperial = false
|
49
|
+
forecast = @service.fetch_forecast(TEST_LOCATION, 2)
|
50
|
+
assert(forecast.metric?)
|
51
|
+
|
52
|
+
ENV['USE_IMPERIAL_UNITS'] = "yes"
|
53
|
+
@service.imperial = true
|
54
|
+
forecast = @service.fetch_forecast(TEST_LOCATION, 2)
|
55
|
+
assert(!forecast.metric?)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_find_location
|
59
|
+
locations = @service.find_location("Toronto")
|
60
|
+
assert(locations.has_key?(TEST_LOCATION))
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
2
|
+
<!--This document is intended only for use by authorized licensees of The Weather Channel. Unauthorized use is prohibited. Copyright 1995-2005, The Weather Channel Interactive, Inc. All Rights Reserved.-->
|
3
|
+
<weather ver="2.0">
|
4
|
+
<head>
|
5
|
+
<locale>en_US</locale>
|
6
|
+
<form>MEDIUM</form>
|
7
|
+
<ut>F</ut>
|
8
|
+
<ud>mi</ud>
|
9
|
+
<us>mph</us>
|
10
|
+
<up>in</up>
|
11
|
+
<ur>in</ur>
|
12
|
+
</head>
|
13
|
+
<loc id="CAXX0504">
|
14
|
+
<dnam>Toronto, Canada</dnam>
|
15
|
+
<tm>3:43 PM</tm>
|
16
|
+
<lat>43.63</lat>
|
17
|
+
<lon>-79.4</lon>
|
18
|
+
<sunr>5:49 AM</sunr>
|
19
|
+
<suns>8:57 PM</suns>
|
20
|
+
<zone>-4</zone>
|
21
|
+
</loc>
|
22
|
+
<cc>
|
23
|
+
<lsup>7/14/06 3:00 PM Local Time</lsup>
|
24
|
+
<obst>Mississauga, Canada</obst>
|
25
|
+
<tmp>84</tmp>
|
26
|
+
<flik>87</flik>
|
27
|
+
<t>Mostly Cloudy</t>
|
28
|
+
<icon>28</icon>
|
29
|
+
<bar>
|
30
|
+
<r>29.95</r>
|
31
|
+
<d>falling</d>
|
32
|
+
</bar>
|
33
|
+
<wind>
|
34
|
+
<s>13</s>
|
35
|
+
<gust>N/A</gust>
|
36
|
+
<d>150</d>
|
37
|
+
<t>SSE</t>
|
38
|
+
</wind>
|
39
|
+
<hmid>55</hmid>
|
40
|
+
<vis>Unlimited</vis>
|
41
|
+
<uv>
|
42
|
+
<i>7</i>
|
43
|
+
<t>High</t>
|
44
|
+
</uv>
|
45
|
+
<dewp>66</dewp>
|
46
|
+
<moon>
|
47
|
+
<icon>18</icon>
|
48
|
+
<t>Waning Gibbous</t>
|
49
|
+
</moon>
|
50
|
+
</cc>
|
51
|
+
<dayf>
|
52
|
+
<lsup>7/14/06 2:15 PM Local Time</lsup>
|
53
|
+
<day d="0" t="Friday" dt="Jul 14">
|
54
|
+
<hi>N/A</hi>
|
55
|
+
<low>71</low>
|
56
|
+
<sunr>5:49 AM</sunr>
|
57
|
+
<suns>8:57 PM</suns>
|
58
|
+
<part p="d">
|
59
|
+
<icon>44</icon>
|
60
|
+
<t>N/A</t>
|
61
|
+
<wind>
|
62
|
+
<s>N/A</s>
|
63
|
+
<gust>N/A</gust>
|
64
|
+
<d>N/A</d>
|
65
|
+
<t>N/A</t>
|
66
|
+
</wind>
|
67
|
+
<bt>N/A</bt>
|
68
|
+
<ppcp>10</ppcp>
|
69
|
+
<hmid>N/A</hmid>
|
70
|
+
</part>
|
71
|
+
<part p="n">
|
72
|
+
<icon>33</icon>
|
73
|
+
<t>Mostly Clear</t>
|
74
|
+
<wind>
|
75
|
+
<s>8</s>
|
76
|
+
<gust>N/A</gust>
|
77
|
+
<d>239</d>
|
78
|
+
<t>WSW</t>
|
79
|
+
</wind>
|
80
|
+
<bt>M Clear</bt>
|
81
|
+
<ppcp>10</ppcp>
|
82
|
+
<hmid>69</hmid>
|
83
|
+
</part>
|
84
|
+
</day>
|
85
|
+
<day d="1" t="Saturday" dt="Jul 15">
|
86
|
+
<hi>87</hi>
|
87
|
+
<low>69</low>
|
88
|
+
<sunr>5:50 AM</sunr>
|
89
|
+
<suns>8:57 PM</suns>
|
90
|
+
<part p="d">
|
91
|
+
<icon>37</icon>
|
92
|
+
<t>Isolated T-Storms</t>
|
93
|
+
<wind>
|
94
|
+
<s>9</s>
|
95
|
+
<gust>N/A</gust>
|
96
|
+
<d>290</d>
|
97
|
+
<t>WNW</t>
|
98
|
+
</wind>
|
99
|
+
<bt>Iso T-Storms</bt>
|
100
|
+
<ppcp>30</ppcp>
|
101
|
+
<hmid>65</hmid>
|
102
|
+
</part>
|
103
|
+
<part p="n">
|
104
|
+
<icon>33</icon>
|
105
|
+
<t>Mostly Clear</t>
|
106
|
+
<wind>
|
107
|
+
<s>8</s>
|
108
|
+
<gust>N/A</gust>
|
109
|
+
<d>314</d>
|
110
|
+
<t>NW</t>
|
111
|
+
</wind>
|
112
|
+
<bt>M Clear</bt>
|
113
|
+
<ppcp>20</ppcp>
|
114
|
+
<hmid>73</hmid>
|
115
|
+
</part>
|
116
|
+
</day>
|
117
|
+
<day d="2" t="Sunday" dt="Jul 16">
|
118
|
+
<hi>91</hi>
|
119
|
+
<low>74</low>
|
120
|
+
<sunr>5:51 AM</sunr>
|
121
|
+
<suns>8:56 PM</suns>
|
122
|
+
<part p="d">
|
123
|
+
<icon>32</icon>
|
124
|
+
<t>Sunny</t>
|
125
|
+
<wind>
|
126
|
+
<s>12</s>
|
127
|
+
<gust>N/A</gust>
|
128
|
+
<d>245</d>
|
129
|
+
<t>WSW</t>
|
130
|
+
</wind>
|
131
|
+
<bt>Sunny</bt>
|
132
|
+
<ppcp>0</ppcp>
|
133
|
+
<hmid>59</hmid>
|
134
|
+
</part>
|
135
|
+
<part p="n">
|
136
|
+
<icon>33</icon>
|
137
|
+
<t>Mostly Clear</t>
|
138
|
+
<wind>
|
139
|
+
<s>8</s>
|
140
|
+
<gust>N/A</gust>
|
141
|
+
<d>263</d>
|
142
|
+
<t>W</t>
|
143
|
+
</wind>
|
144
|
+
<bt>M Clear</bt>
|
145
|
+
<ppcp>10</ppcp>
|
146
|
+
<hmid>67</hmid>
|
147
|
+
</part>
|
148
|
+
</day>
|
149
|
+
<day d="3" t="Monday" dt="Jul 17">
|
150
|
+
<hi>89</hi>
|
151
|
+
<low>77</low>
|
152
|
+
<sunr>5:52 AM</sunr>
|
153
|
+
<suns>8:55 PM</suns>
|
154
|
+
<part p="d">
|
155
|
+
<icon>30</icon>
|
156
|
+
<t>Partly Cloudy</t>
|
157
|
+
<wind>
|
158
|
+
<s>13</s>
|
159
|
+
<gust>N/A</gust>
|
160
|
+
<d>232</d>
|
161
|
+
<t>SW</t>
|
162
|
+
</wind>
|
163
|
+
<bt>P Cloudy</bt>
|
164
|
+
<ppcp>20</ppcp>
|
165
|
+
<hmid>60</hmid>
|
166
|
+
</part>
|
167
|
+
<part p="n">
|
168
|
+
<icon>33</icon>
|
169
|
+
<t>Mostly Clear</t>
|
170
|
+
<wind>
|
171
|
+
<s>10</s>
|
172
|
+
<gust>N/A</gust>
|
173
|
+
<d>251</d>
|
174
|
+
<t>WSW</t>
|
175
|
+
</wind>
|
176
|
+
<bt>M Clear</bt>
|
177
|
+
<ppcp>20</ppcp>
|
178
|
+
<hmid>59</hmid>
|
179
|
+
</part>
|
180
|
+
</day>
|
181
|
+
<day d="4" t="Tuesday" dt="Jul 18">
|
182
|
+
<hi>88</hi>
|
183
|
+
<low>70</low>
|
184
|
+
<sunr>5:53 AM</sunr>
|
185
|
+
<suns>8:55 PM</suns>
|
186
|
+
<part p="d">
|
187
|
+
<icon>37</icon>
|
188
|
+
<t>Isolated T-Storms</t>
|
189
|
+
<wind>
|
190
|
+
<s>12</s>
|
191
|
+
<gust>N/A</gust>
|
192
|
+
<d>314</d>
|
193
|
+
<t>NW</t>
|
194
|
+
</wind>
|
195
|
+
<bt>Iso T-Storms</bt>
|
196
|
+
<ppcp>30</ppcp>
|
197
|
+
<hmid>60</hmid>
|
198
|
+
</part>
|
199
|
+
<part p="n">
|
200
|
+
<icon>33</icon>
|
201
|
+
<t>Mostly Clear</t>
|
202
|
+
<wind>
|
203
|
+
<s>7</s>
|
204
|
+
<gust>N/A</gust>
|
205
|
+
<d>355</d>
|
206
|
+
<t>N</t>
|
207
|
+
</wind>
|
208
|
+
<bt>M Clear</bt>
|
209
|
+
<ppcp>10</ppcp>
|
210
|
+
<hmid>66</hmid>
|
211
|
+
</part>
|
212
|
+
</day>
|
213
|
+
</dayf>
|
214
|
+
</weather>
|
215
|
+
|
data/weather.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: rubyweather
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.9.1
|
7
|
+
date: 2006-07-28 00:00:00 -04:00
|
8
|
+
summary: Client library for accessing weather.com's xoap weather data.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- .
|
12
|
+
email: matt@roughest.net
|
13
|
+
homepage: http://rubyforge.org/projects/rubyweather
|
14
|
+
rubyforge_project: rubyweather
|
15
|
+
description: RubyWeather is a Ruby library for fetching weather forecast data from weather.com. The library provides a nice Ruby-like abstraction layer for interacting with the service. Note that (free) registration with weather.com is required to access multi-day forecasts.
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- Matt Zukowski
|
31
|
+
files:
|
32
|
+
- weather.rb
|
33
|
+
- lib/service.rb
|
34
|
+
- lib/forecast.rb
|
35
|
+
- lib/util.rb
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- test/forecast_test.rb
|
39
|
+
- test/service_test.rb
|
40
|
+
- test/test_weather.xml
|
41
|
+
test_files:
|
42
|
+
- test/forecast_test.rb
|
43
|
+
- test/service_test.rb
|
44
|
+
rdoc_options:
|
45
|
+
- --title
|
46
|
+
- RubyWeather RDocs
|
47
|
+
- --main
|
48
|
+
- README
|
49
|
+
- --line-numbers
|
50
|
+
extra_rdoc_files:
|
51
|
+
- README
|
52
|
+
- LICENSE
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
dependencies: []
|
60
|
+
|