rubyweather 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -27,8 +27,8 @@ directory:
27
27
  === Examples
28
28
 
29
29
  First, we need to find out the weather.com location code for your city.
30
- This will print out a list of locations and their codes matching the
31
- string "Toronto":
30
+ The following code will print out a list of locations and their codes
31
+ matching the string "Toronto":
32
32
 
33
33
  require 'rubygems'
34
34
  require_gem 'rubyweather'
@@ -83,10 +83,10 @@ There are a lot of attributes you can fetch for a forecast. Here are just a few:
83
83
  +latest_update+:: The datetime when the conditions were last measured/forecast.
84
84
 
85
85
  Additionally, most of the attributes for a given day in the raw weather.com xml data are
86
- also directly accessible. For example, you can call <tt>forecast.tomorrow.dewp</tt> to get the dewpoint, because the xml file
87
- contains a <tt>dewp</tt> element for that day. Have a look at <tt>test/test_weather.xml</tt> to see what data is
88
- available in the xml file. Note though that raw xml elements will be returned as a string, without any nice
89
- class casting or unit conversion.
86
+ also directly accessible. For example, you can call <tt>forecast.tomorrow.dewp</tt> to get the dewpoint, because
87
+ the xml file contains a <tt>dewp</tt> element for that day. Have a look at <tt>test/test_weather.xml</tt> to see
88
+ what data is available in the xml file. Note though that raw xml element values will be returned as a string, \
89
+ without any nice class casting or unit conversion.
90
90
 
91
91
  Other programmers are encouraged to add more functionality to the <tt>lib/forecast.rb</tt> module to provide better
92
92
  accessor methods for the underlying xml data. See below for how to obtain subversion access to contribute
@@ -95,8 +95,9 @@ your changes back to the project.
95
95
  === Caching Forecast Data
96
96
 
97
97
  RubyWeather supports data caching using the memcached[http://www.danga.com/memcached/] daemon. This allows for
98
- much quicker response time -- especially if you have a lot of clients accessing the weather data -- and is
99
- just a polite thing to do in regards weather.com's servers.
98
+ much quicker response time -- especially if you have a lot of clients accessing the weather data -- and it's
99
+ just a polite thing to do in regards to weather.com's servers.
100
+
100
101
  If you have a memcached server running, you can turn on data caching as follows:
101
102
 
102
103
  s = Weather::Service.new
@@ -108,8 +109,8 @@ From now on, any fetch_forecast calls made on this service will cache their data
108
109
  server will not be queried again as long as the data is cached.
109
110
 
110
111
  You can check if a forecast came from the cache by calling <tt>#from_cache?</tt>, which returns true if this
111
- forecast came from the local cache, or <tt>#cached_on</tt>, which returns the datetime when this forecast was
112
- entered into the cache or nil if the forecast didn't come from the cache.
112
+ forecast came from the local cache. You can also call <tt>#cached_on</tt> to find out when this forecast was entered
113
+ into the cache or nil if the forecast didn't come from the cache.
113
114
 
114
115
  The above requires that a ruby memcache client be installed. RubyWeather has been tested with the
115
116
  Ruby-MemCache[http://www.deveiate.org/projects/RMemCache] implementation which you can install using:
@@ -126,7 +126,6 @@ module Weather
126
126
  # forecast.current.latest_update
127
127
  #
128
128
  def latest_update
129
- puts xml.root.to_s
130
129
  Time.parse(xml.root.elements['dayf'].elements['lsup'].text)
131
130
  end
132
131
 
@@ -19,7 +19,7 @@ module Weather
19
19
  # Returns the forecast data fetched from the weather.com xoap service for the given location and number of days.
20
20
  def fetch_forecast(location_id, days = 5)
21
21
 
22
- days = 5 if days.nil? or days.empty?
22
+ days = 5 if days.nil? or days == 0 or days == ""
23
23
 
24
24
  # try to pull the partner_id and license_key from the environment if not already set
25
25
  partner_id = ENV['WEATHER_COM_PARTNER_ID'] unless partner_id
@@ -44,7 +44,6 @@ module Weather
44
44
 
45
45
  # default to metric (degrees fahrenheit are just silly :)
46
46
  unit = imperial ? "s" : "m"
47
- puts "#{location_id} #{partner_id} #{license_key} DAYS: #{days.inspect}"
48
47
  host = "xoap.weather.com"
49
48
  url = "/weather/local/#{location_id}?cc=*&dayf=#{days}&prod=xoap&par=#{partner_id}&key=#{license_key}&unit=#{unit}"
50
49
 
@@ -62,7 +61,6 @@ module Weather
62
61
  cache.set("#{location_id}:#{days}", doc.to_s, cache_expiry)
63
62
  end
64
63
  end
65
- puts xml
66
64
  doc = REXML::Document.new(xml)
67
65
 
68
66
  Forecast::Forecast.new(doc)
@@ -0,0 +1,71 @@
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
+ # This test ensures that the examples in the README run without errors.
7
+ #
8
+
9
+ require 'test/unit'
10
+ require File.dirname(__FILE__) + '/../lib/weather/service'
11
+
12
+ if not ENV['WEATHER_COM_PARTNER_ID']
13
+ 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."
14
+ end
15
+
16
+ if not ENV['WEATHER_COM_LICENSE_KEY']
17
+ 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."
18
+ end
19
+
20
+ class ServiceTest < Test::Unit::TestCase
21
+ TORONTO = "CAXX0504"
22
+
23
+ # Note that for this test to work the WEATHER.COM_PARTNER_ID and WEATHER.COM_LICENSE_KEY
24
+ # environment variables must be set!
25
+
26
+ def setup
27
+ @service = Weather::Service.new
28
+ end
29
+
30
+ def test_find_location_example
31
+ assert_nothing_raised do
32
+ #require 'weather/service'
33
+
34
+ service = Weather::Service.new
35
+ service.partner_id = ""
36
+ service.license_key = ""
37
+
38
+ locations = service.find_location('Toronto')
39
+ "Matching Locations: " + locations.inspect
40
+ end
41
+ end
42
+
43
+ def test_forecast_example
44
+ assert_nothing_raised do
45
+ forecast = @service.fetch_forecast("CAXX0504", 5)
46
+
47
+ "Location: %s" % forecast.location_name
48
+
49
+ "Current Temperature: %s" % forecast.current.temperature
50
+ "Current Windspeed: %s" % forecast.current.wind.speed
51
+
52
+ "Tomorrow's High: %s" % forecast.tomorrow.high
53
+ "Tomorrow's Outlook: %s" % forecast.tomorrow.outlook
54
+ "Tomorrow's Wind Direction: %s" % forecast.tomorrow.wind.direction
55
+
56
+ "High 3 days from now: %s" % forecast.day(3).high
57
+ "Probability of precipitation 4 days from now: %s" % forecast.day(4).pop
58
+
59
+ "Probability of precipitation three nights from now: %s" % forecast.night(3).pop
60
+ end
61
+ end
62
+
63
+ def test_caching_example
64
+ assert_nothing_raised do
65
+ s = Weather::Service.new
66
+ s.enable_cache
67
+ s.cache_expiry = 60 # cached data will expire after 60 seconds; if omitted, the default is 10 minutes
68
+ s.cache.servers = ['127.0.0.1:11211']
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rubyweather
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2006-07-28 00:00:00 -04:00
6
+ version: 1.1.2
7
+ date: 2007-01-11 00:00:00 -05:00
8
8
  summary: Client library for accessing weather.com's xoap weather data.
9
9
  require_paths:
10
10
  - lib
@@ -40,6 +40,7 @@ files:
40
40
  - test/service_test.rb
41
41
  - test/forecast_test.rb
42
42
  - test/profiler.rb
43
+ - test/examples_test.rb
43
44
  - test/test_weather.xml
44
45
  - example/weather_portlet_controller.rb
45
46
  - example/weather_32
@@ -97,9 +98,10 @@ files:
97
98
  test_files:
98
99
  - test/service_test.rb
99
100
  - test/forecast_test.rb
101
+ - test/examples_test.rb
100
102
  rdoc_options:
101
103
  - --title
102
- - RubyWeather 1.1.1 RDocs
104
+ - RubyWeather 1.1.2 RDocs
103
105
  - --main
104
106
  - README
105
107
  - --line-numbers