tomk32-yahoo-weather 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +44 -0
- data/Manifest.txt +18 -0
- data/Rakefile +24 -0
- data/TODO +3 -0
- data/examples/example.rb +30 -0
- data/examples/get-weather.rb +21 -0
- data/lib/yahoo-weather.rb +40 -0
- data/test/test_api.rb +150 -0
- metadata +101 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= YAHOO_WEATHER_20091226_1_2_0
|
2
|
+
|
3
|
+
* [shaper] upped library to version 1.2.0 to reflect changes.
|
4
|
+
|
5
|
+
* [shaper] added new client.lookup_by_woeid method which should be
|
6
|
+
used instead of the now-deprecated lookup_location method. Thanks
|
7
|
+
to Chris Cummer (http://github.com/senorprogrammer) for pointing out
|
8
|
+
the new WOEID-based Yahoo API functionality.
|
9
|
+
|
10
|
+
* [shaper] use new Yahoo Weather API at
|
11
|
+
http://weather.yahooapis.com/forecastrss
|
12
|
+
|
13
|
+
* [shaper] shift xml parsing to use nokogiri rather than xml-simple.
|
14
|
+
|
15
|
+
* [shaper] shift from Response.image_url to Response.image which
|
16
|
+
contains the new YahooWeather::Image record with the old image url
|
17
|
+
plus more detail as now provided in the API response.
|
18
|
+
|
19
|
+
* [shaper] refactor for single class per file.
|
20
|
+
|
21
|
+
* [shaper] fix km/h unit speed in test.
|
22
|
+
|
23
|
+
= YAHOO_WEATHER_20091209_1_1_0
|
24
|
+
|
25
|
+
* [shaper] revise atmosphere.barometer to reflect tri-state as
|
26
|
+
"steady", "rising", or "falling" via one of the new
|
27
|
+
YahooWeather::Atmosphere::Barometer constants, whereas previously it
|
28
|
+
was simply a boolean for whether rising. Thanks to Andy Weber for
|
29
|
+
suggestion.
|
30
|
+
|
31
|
+
= YAHOO_WEATHER_20091021_1_0_1
|
32
|
+
|
33
|
+
* [shaper] update documentation to reflect reality and use suffix for
|
34
|
+
rdoc format.
|
35
|
+
|
36
|
+
* [shaper] move source repository to github.
|
37
|
+
|
38
|
+
* [shaper] use Hoe for Rakefile and gem management.
|
39
|
+
|
40
|
+
* [shaper] fix test warnings.
|
41
|
+
|
42
|
+
= 20061105
|
43
|
+
|
44
|
+
* [shaper] Initial version.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
CHANGELOG.rdoc
|
2
|
+
examples/example.rb
|
3
|
+
examples/get-weather.rb
|
4
|
+
lib/yahoo-weather/astronomy.rb
|
5
|
+
lib/yahoo-weather/atmosphere.rb
|
6
|
+
lib/yahoo-weather/client.rb
|
7
|
+
lib/yahoo-weather/condition.rb
|
8
|
+
lib/yahoo-weather/forecast.rb
|
9
|
+
lib/yahoo-weather/image.rb
|
10
|
+
lib/yahoo-weather/location.rb
|
11
|
+
lib/yahoo-weather/response.rb
|
12
|
+
lib/yahoo-weather/units.rb
|
13
|
+
lib/yahoo-weather/wind.rb
|
14
|
+
lib/yahoo-weather.rb
|
15
|
+
LICENSE
|
16
|
+
Rakefile
|
17
|
+
README.rdoc
|
18
|
+
test/test_api.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
4
|
+
require 'yahoo-weather'
|
5
|
+
|
6
|
+
Hoe.spec('yahoo-weather') do |p|
|
7
|
+
self.version = YahooWeather::VERSION
|
8
|
+
self.rubyforge_name = 'yahoo-weather'
|
9
|
+
self.author = 'Walter Korman'
|
10
|
+
self.email = 'shaper@fatgoose.com'
|
11
|
+
self.extra_deps << [ 'nokogiri', '>= 1.4.1' ]
|
12
|
+
self.summary = 'A Ruby object-oriented interface to the Yahoo! Weather service.'
|
13
|
+
self.description = <<EDOC
|
14
|
+
The yahoo-weather rubygem provides a Ruby object-oriented interface to the
|
15
|
+
Yahoo! Weather service described in detail at:
|
16
|
+
|
17
|
+
http://developer.yahoo.com/weather
|
18
|
+
EDOC
|
19
|
+
self.url = 'http://rubyforge.org/projects/yahoo-weather'
|
20
|
+
self.remote_rdoc_dir = '' # Release to root
|
21
|
+
self.readme_file = 'README.rdoc'
|
22
|
+
self.history_file = 'CHANGELOG.rdoc'
|
23
|
+
self.extra_rdoc_files = [ 'CHANGELOG.rdoc', 'README.rdoc' ]
|
24
|
+
end
|
data/TODO
ADDED
data/examples/example.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'yahoo-weather'
|
5
|
+
|
6
|
+
@client = YahooWeather::Client.new
|
7
|
+
# look up WOEID via http://weather.yahoo.com; enter location by city
|
8
|
+
# name or zip and WOEID is at end of resulting page url. herein we use
|
9
|
+
# the WOEID for Santa Monica, CA.
|
10
|
+
response = @client.lookup_by_woeid(2488892)
|
11
|
+
|
12
|
+
# straight text output
|
13
|
+
print <<EDOC
|
14
|
+
#{response.title}
|
15
|
+
#{response.condition.temp} degrees
|
16
|
+
#{response.condition.text}
|
17
|
+
EDOC
|
18
|
+
|
19
|
+
# sample html output
|
20
|
+
print <<EDOC
|
21
|
+
<div>
|
22
|
+
<img src="#{response.image.url}"><br/>
|
23
|
+
#{response.condition.temp} degrees #{response.units.temperature}<br/>
|
24
|
+
#{response.condition.text}<br>
|
25
|
+
Forecast:<br/>
|
26
|
+
#{response.forecasts[0].day} - #{response.forecasts[0].text}. High: #{response.forecasts[0].high} Low: #{response.forecasts[0].low}<br/>
|
27
|
+
#{response.forecasts[1].day} - #{response.forecasts[1].text}. High: #{response.forecasts[1].high} Low: #{response.forecasts[1].low}<br/>
|
28
|
+
More information <a href="#{response.page_url}">here</a>.
|
29
|
+
</div>
|
30
|
+
EDOC
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Simple example script demonstrating usage of the yahoo-weather library.
|
4
|
+
#
|
5
|
+
# 2006/11/05 - Walter Korman (shaper@wgks.org)
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'pp'
|
10
|
+
require 'yahoo-weather'
|
11
|
+
|
12
|
+
location = ARGV[0]
|
13
|
+
if !location
|
14
|
+
STDERR.print "Usage: get-weather.rb <zip code>\n"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
print "Looking up weather for #{location}...\n"
|
19
|
+
@client = YahooWeather::Client.new
|
20
|
+
response = @client.lookup_location(location)
|
21
|
+
pp(response)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# yahoo-weather -- provides OO access to the Yahoo! Weather RSS XML feed
|
2
|
+
# Copyright (C) 2006 - 2009 Walter Korman <shaper@fatgoose.com>
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
require 'net/http'
|
19
|
+
require 'cgi'
|
20
|
+
require 'time'
|
21
|
+
require 'nokogiri'
|
22
|
+
|
23
|
+
class YahooWeather
|
24
|
+
VERSION = '1.2.0'
|
25
|
+
|
26
|
+
def self._parse_time (text)
|
27
|
+
(text) ? Time.parse(text) : nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'yahoo-weather/astronomy'
|
32
|
+
require 'yahoo-weather/atmosphere'
|
33
|
+
require 'yahoo-weather/client'
|
34
|
+
require 'yahoo-weather/condition'
|
35
|
+
require 'yahoo-weather/forecast'
|
36
|
+
require 'yahoo-weather/image'
|
37
|
+
require 'yahoo-weather/location'
|
38
|
+
require 'yahoo-weather/response'
|
39
|
+
require 'yahoo-weather/units'
|
40
|
+
require 'yahoo-weather/wind'
|
data/test/test_api.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'yahoo-weather'
|
4
|
+
|
5
|
+
class TestAPI < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@client = YahooWeather::Client.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_lookup_zip
|
11
|
+
# check a seattle, wa zipcode
|
12
|
+
request_location = '98103'
|
13
|
+
response = @client.lookup_location(request_location)
|
14
|
+
_assert_valid_response(response, request_location,
|
15
|
+
YahooWeather::Units::FAHRENHEIT,
|
16
|
+
'Seattle', 'WA', 'US')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_lookup_location
|
20
|
+
# check france just for fun with the sample france location code from the
|
21
|
+
# yahoo weather developer page
|
22
|
+
request_location = 'FRXX0076'
|
23
|
+
response = @client.lookup_location(request_location)
|
24
|
+
_assert_valid_response(response, request_location,
|
25
|
+
YahooWeather::Units::FAHRENHEIT,
|
26
|
+
'Paris', '', 'FR')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_units
|
30
|
+
request_location = '10001'
|
31
|
+
city = 'New York'
|
32
|
+
region = 'NY'
|
33
|
+
country = 'US'
|
34
|
+
|
35
|
+
# check explicitly specifying fahrenheit units
|
36
|
+
response = @client.lookup_location(request_location,
|
37
|
+
YahooWeather::Units::FAHRENHEIT)
|
38
|
+
_assert_valid_response(response, request_location,
|
39
|
+
YahooWeather::Units::FAHRENHEIT,
|
40
|
+
city, region, country)
|
41
|
+
|
42
|
+
# check alternate units
|
43
|
+
response = @client.lookup_location(request_location,
|
44
|
+
YahooWeather::Units::CELSIUS)
|
45
|
+
_assert_valid_response(response, request_location,
|
46
|
+
YahooWeather::Units::CELSIUS,
|
47
|
+
city, region, country)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_lookup_by_woeid
|
51
|
+
woeid_sf = '12797168'
|
52
|
+
response = @client.lookup_by_woeid(woeid_sf)
|
53
|
+
_assert_valid_response(response, woeid_sf,
|
54
|
+
YahooWeather::Units::FAHRENHEIT,
|
55
|
+
'San Francisco', 'CA', 'United States')
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def _assert_valid_response (response, request_location, units,
|
61
|
+
city, region, country)
|
62
|
+
assert_not_nil response
|
63
|
+
|
64
|
+
# check the request location and url explicitly against what we
|
65
|
+
# know they should be
|
66
|
+
assert_equal response.request_location, request_location
|
67
|
+
assert_match(/http:\/\/weather\.yahooapis\.com\/forecastrss\?[pw]=#{request_location}&u=#{units}/, response.request_url)
|
68
|
+
|
69
|
+
# check the astronomy info
|
70
|
+
assert_instance_of YahooWeather::Astronomy, response.astronomy
|
71
|
+
assert_instance_of Time, response.astronomy.sunrise
|
72
|
+
assert_instance_of Time, response.astronomy.sunset
|
73
|
+
assert(response.astronomy.sunrise < response.astronomy.sunset)
|
74
|
+
|
75
|
+
# check the location
|
76
|
+
assert_instance_of YahooWeather::Location, response.location
|
77
|
+
assert_equal response.location.city, city
|
78
|
+
assert_equal response.location.region, region
|
79
|
+
assert_equal response.location.country, country
|
80
|
+
|
81
|
+
# check the default units
|
82
|
+
_assert_valid_units(response.units,
|
83
|
+
(units == YahooWeather::Units::FAHRENHEIT))
|
84
|
+
|
85
|
+
# check the wind info
|
86
|
+
assert_instance_of YahooWeather::Wind, response.wind
|
87
|
+
assert(response.wind.chill <= response.condition.temp)
|
88
|
+
assert_kind_of Numeric, response.wind.direction
|
89
|
+
assert_kind_of Numeric, response.wind.speed
|
90
|
+
|
91
|
+
# check the atmosphere info
|
92
|
+
assert_instance_of YahooWeather::Atmosphere, response.atmosphere
|
93
|
+
assert_kind_of Numeric, response.atmosphere.humidity
|
94
|
+
assert_kind_of Numeric, response.atmosphere.visibility
|
95
|
+
assert_kind_of Numeric, response.atmosphere.pressure
|
96
|
+
assert(YahooWeather::Atmosphere::Barometer::ALL.include?(response.atmosphere.barometer))
|
97
|
+
|
98
|
+
# check the condition info
|
99
|
+
assert_instance_of YahooWeather::Condition, response.condition
|
100
|
+
_assert_valid_weather_code response.condition.code
|
101
|
+
assert_instance_of Time, response.condition.date
|
102
|
+
assert_kind_of Numeric, response.condition.temp
|
103
|
+
assert(response.condition.text && response.condition.text.length > 0)
|
104
|
+
|
105
|
+
# check the forecast info
|
106
|
+
assert_not_nil response.forecasts
|
107
|
+
assert_kind_of Array, response.forecasts
|
108
|
+
assert_equal response.forecasts.length, 2
|
109
|
+
response.forecasts.each do |forecast|
|
110
|
+
assert_instance_of YahooWeather::Forecast, forecast
|
111
|
+
assert(forecast.day && forecast.day.length == 3)
|
112
|
+
assert_instance_of Time, forecast.date
|
113
|
+
assert_kind_of Numeric, forecast.low
|
114
|
+
assert_kind_of Numeric, forecast.high
|
115
|
+
assert(forecast.low <= forecast.high)
|
116
|
+
assert(forecast.text && forecast.text.length > 0)
|
117
|
+
_assert_valid_weather_code forecast.code
|
118
|
+
end
|
119
|
+
|
120
|
+
# check the basic attributes
|
121
|
+
assert(response.description && response.description.length > 0)
|
122
|
+
assert(response.image.url =~ /yimg\.com/)
|
123
|
+
assert_kind_of Numeric, response.latitude
|
124
|
+
assert_kind_of Numeric, response.longitude
|
125
|
+
assert(response.page_url =~ /\.html$/)
|
126
|
+
assert(response.title && response.title.length > 0)
|
127
|
+
assert_not_nil(response.title.index("#{response.location.city}, #{response.location.region}"))
|
128
|
+
end
|
129
|
+
|
130
|
+
def _assert_valid_weather_code (code)
|
131
|
+
(((code >= 0) && (code <= 47)) || (code == 3200))
|
132
|
+
end
|
133
|
+
|
134
|
+
def _assert_valid_units (units, fahrenheit_based)
|
135
|
+
assert_instance_of YahooWeather::Units, units
|
136
|
+
if fahrenheit_based
|
137
|
+
assert_equal units.temperature, 'F'
|
138
|
+
assert_equal units.distance, 'mi'
|
139
|
+
assert_equal units.pressure, 'in'
|
140
|
+
assert_equal units.speed, 'mph'
|
141
|
+
|
142
|
+
else
|
143
|
+
assert_equal units.temperature, 'C'
|
144
|
+
assert_equal units.distance, 'km'
|
145
|
+
assert_equal units.pressure, 'mb'
|
146
|
+
assert_equal units.speed, 'km/h'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tomk32-yahoo-weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
version: 1.2.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Walter Korman
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-24 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nokogiri
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 4
|
31
|
+
- 1
|
32
|
+
version: 1.4.1
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hoe
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 4
|
46
|
+
- 0
|
47
|
+
version: 2.4.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: "The yahoo-weather rubygem provides a Ruby object-oriented interface to the Yahoo! Weather service described in detail at: http://developer.yahoo.com/weather"
|
51
|
+
email: shaper@fatgoose.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- CHANGELOG.rdoc
|
60
|
+
- Manifest.txt
|
61
|
+
- Rakefile
|
62
|
+
- TODO
|
63
|
+
- examples/example.rb
|
64
|
+
- examples/get-weather.rb
|
65
|
+
- lib/yahoo-weather.rb
|
66
|
+
- test/test_api.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://rubyforge.org/projects/yahoo-weather
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --exclude
|
74
|
+
- .
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: A Ruby object-oriented interface to the Yahoo! Weather service
|
100
|
+
test_files: []
|
101
|
+
|