weatherhacks 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,9 +1,18 @@
1
+ == 0.2.0 2008-04-11
2
+
3
+ * Keita Yamaguchi
4
+ * GitHub: http://github.com/keita/ruby-weatherhacks/tree/master
5
+ * Reduced files included in the gem package
6
+ * New: WeatherHacks.lwws and WeatherHacks::LWWS[] are alias of WeatherHacks::LWWS.request
7
+ * WeatherHacks::LWWS.request can handle city name(e.g. request("松江"))
8
+ * WeatherHacks::LWWS.request(city, :all) returns 3 days forecasts.
9
+
1
10
  == 0.1.1 2007-12-12
2
11
 
3
- * Keita Yamaguchi:
4
- * fix bin/lwws
12
+ * Keita Yamaguchi
13
+ * Fixed bin/lwws
5
14
 
6
15
  == 0.1.0 2007-12-12
7
16
 
8
- * Keita Yamaguchi:
17
+ * Keita Yamaguchi
9
18
  * Initial release
data/License.txt CHANGED
@@ -1,4 +1,4 @@
1
- Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
1
+ ruby-weatherhacks is copyrighted free software by Keita Yamaguchi <keita.yamaguchi@gmail.com>.
2
2
  You can redistribute it and/or modify it under either the terms of the GPL
3
3
  (see the file GPL), or the conditions below:
4
4
 
data/Manifest.txt CHANGED
@@ -4,27 +4,9 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  bin/lwws
7
- config/hoe.rb
8
- config/requirements.rb
9
7
  lib/weatherhacks.rb
10
8
  lib/weatherhacks/forecastmap.rb
11
9
  lib/weatherhacks/lwws.rb
12
- lib/weatherhacks/version.rb
13
10
  misc/forecastmap.xsl
14
- script/destroy
15
- script/generate
16
- script/txt2html
17
11
  setup.rb
18
12
  spec/lwws_spec.rb
19
- spec/spec.opts
20
- spec/spec_helper.rb
21
- tasks/deployment.rake
22
- tasks/environment.rake
23
- tasks/rspec.rake
24
- tasks/weatherhacks.rake
25
- tasks/website.rake
26
- website/index.html
27
- website/index.txt
28
- website/javascripts/rounded_corners_lite.inc.js
29
- website/stylesheets/screen.css
30
- website/template.rhtml
data/README.txt CHANGED
@@ -1,9 +1,20 @@
1
- README for ruby-weatherhacks
2
- ============================
3
- ruby-weatherhacks is a wrapper library for livdoor WeatherHacks API.
1
+ = ruby-weatherhacks
4
2
 
5
- livedoor ... http://www.livedoor.com/
6
- WeatherHacks ... http://weather.livedoor.com/weather_hacks/
3
+ Author:: Keita Yamaguchi(山口 慶太) <keita.yamaguchi@gmail.com>
4
+ Copyright:: © Keita Yamaguchi, 2007ー2008. All rights reserved.
5
+ License:: Ruby License
7
6
 
8
- Copyright (C) 2007 Keita Yamaguchi
9
- Mail: keita.yamaguchi@gmail.com
7
+ ruby-weatherhacks is a wrapper library for {livdoor WeatherHacks}[http://weather.livedoor.com/weather_hacks/] API.
8
+
9
+ == Usage
10
+
11
+ See {the documentation}[http://github.com/keita/ruby-weatherhacks/wikis].
12
+
13
+ == Links
14
+
15
+ * {livedoor WeatherHacks}[http://weather.livedoor.com/weather_hacks/]
16
+ * ruby-weatherhacks
17
+ * {RubyForge}[http://rubyforge.org/projects/weatherhacks/]
18
+ * {GitHub}[http://github.com/keita/ruby-weatherhacks/tree/master]
19
+ * author's blog(written in Japanese)
20
+ * {¬¬日常日記}[http://d.hatena.ne.jp/keita_yamaguchi/]
data/Rakefile CHANGED
@@ -1,4 +1,23 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
1
+ require "rubygems"
2
+ require "rtask"
3
+
4
+ RTask.new
5
+
6
+ desc "Run the specs"
7
+ task :spec do
8
+ sh "bacon"
9
+ end
10
+
11
+ desc 'Update forecastmap.rb'
12
+ task :forecastmap do
13
+ # download forecastmap.xml
14
+ url = "http://weather.livedoor.com/forecast/rss/forecastmap.xml"
15
+ sh "wget -O forecastmap.xml #{url}"
16
+ # generate
17
+ out = "lib/weatherhacks/forecastmap.rb"
18
+ xsl = "misc/forecastmap.xsl"
19
+ sh "xsltproc -o #{out} #{xsl} forecastmap.xml"
20
+ # remove
21
+ sh "rm forecastmap.xml"
22
+ end
3
23
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/lwws CHANGED
File without changes
data/lib/weatherhacks.rb CHANGED
@@ -1,4 +1,13 @@
1
1
  module WeatherHacks
2
+ module Version #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ VERSION = Version::STRING
10
+
2
11
  module ForecastMap
3
12
  class Area
4
13
  attr_reader :name, :rss, :prefs
@@ -55,4 +64,11 @@ end
55
64
 
56
65
  require "weatherhacks/lwws"
57
66
  require "weatherhacks/forecastmap"
58
- require "weatherhacks/version"
67
+
68
+ module WeatherHacks
69
+ module_function
70
+
71
+ def lwws(city, day = :all)
72
+ LWWS.request(city, day)
73
+ end
74
+ end
@@ -121,20 +121,33 @@ module WeatherHacks::LWWS
121
121
  end
122
122
  end
123
123
 
124
- # Returns a Forecast object.
125
- # city_id:: city id
126
- # day:: :today, :tomorrow or :dayaftertomorrow
127
- def self.request(city_id, day = :today)
128
- unless day == :today or day == :tomorrow or day == :dayaftertomorrow
129
- raise ArgumentError, day
130
- end
131
- req = Net::HTTP::Get.new(path(city_id, day.to_s))
132
- http = Net::HTTP.new(URL.host)
133
- case res = http.request(req)
134
- when Net::HTTPSuccess
135
- Forecast.new(REXML::Document.new(res.body))
136
- else
137
- raise Error.new(res)
124
+ class << self
125
+
126
+ # Returns a Forecast object.
127
+ # city_id:: city id
128
+ # day:: :today, :tomorrow or :dayaftertomorrow
129
+ def request(city, day = :all)
130
+ city_id = if city.kind_of?(String)
131
+ WeatherHacks::ForecastMap::CITY[city].id
132
+ else city end
133
+ unless day.to_s =~ /today|tomorrow|dayaftertomorrow|all/
134
+ raise ArgumentError, day
135
+ end
136
+ if day == :all
137
+ return [ request(city, :today),
138
+ request(city, :tomorrow),
139
+ request(city, :dayaftertomorrow) ]
140
+ end
141
+ req = Net::HTTP::Get.new(path(city_id, day.to_s))
142
+ http = Net::HTTP.new(URL.host)
143
+ case res = http.request(req)
144
+ when Net::HTTPSuccess
145
+ Forecast.new(REXML::Document.new(res.body))
146
+ else
147
+ raise Error.new(res)
148
+ end
138
149
  end
150
+
151
+ alias [] request
139
152
  end
140
153
  end
data/spec/lwws_spec.rb CHANGED
@@ -1,106 +1,100 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ $LOAD_PATH.unshift File.join(File.join(File.dirname(__FILE__), ".."), "lib")
2
+ require "weatherhacks"
3
+ require "rubygems"
4
+ require "bacon"
2
5
 
3
- describe WeatherHacks::LWWS::Forecast do
4
- before do
5
- @forecast = WeatherHacks::LWWS::Forecast.new($today)
6
- end
6
+ include WeatherHacks::LWWS
7
7
 
8
- it "can read author as a String" do
9
- @forecast.author.should be_a_kind_of(String)
10
- end
11
-
12
- it "can read location as a WeatherHacks::LWWS::Location" do
13
- @forecast.location.should be_a_kind_of(WeatherHacks::LWWS::Location)
14
- end
8
+ $today, $tomorrow, $dayaftertomorrow = WeatherHacks.lwws("松江")
15
9
 
16
- it "can read title as a String" do
17
- @forecast.title.should be_a_kind_of(String)
18
- end
10
+ describe "WeatherHacks::LWWS::Forecast" do
19
11
 
20
- it "can read link as a URI" do
21
- @forecast.link.should be_a_kind_of(URI)
12
+ def forecast(&block)
13
+ [$today, $tomorrow, $dayaftertomorrow].each {|f| yield f }
22
14
  end
23
15
 
24
- it "can read forecastday as a String" do
25
- @forecast.forecastday.should be_a_kind_of(String)
16
+ it "#author" do
17
+ forecast {|f| f.author.should.be.kind_of(String) }
26
18
  end
27
19
 
28
- it "can read day as a String" do
29
- @forecast.day.should match(/Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday/)
20
+ it "#location" do
21
+ forecast {|f| f.location.should.be.kind_of(::Location) }
30
22
  end
31
23
 
32
- it "can read forecastdate as a Time" do
33
- @forecast.forecastdate.should be_a_kind_of(Time)
24
+ it "#title" do
25
+ forecast {|f| f.title.should.be.kind_of(String) }
34
26
  end
35
27
 
36
- it "can read publictime as a Time" do
37
- @forecast.publictime.should be_a_kind_of(Time)
28
+ it "#link" do
29
+ forecast {|f| f.link.should.be.kind_of(URI) }
38
30
  end
39
31
 
40
- it "can read telop as a String" do
41
- @forecast.telop.should be_a_kind_of(String)
32
+ it "#forecastday" do
33
+ $today.forecastday.should == "today"
34
+ $tomorrow.forecastday.should == "tomorrow"
35
+ $dayaftertomorrow.forecastday.should == "dayaftertomorrow"
42
36
  end
43
37
 
44
- it "can read description as String" do
45
- @forecast.description.should be_a_kind_of(String)
38
+ it "#day" do
39
+ forecast {|f| f.day.should =~ /(Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day/ }
46
40
  end
47
41
 
48
- it "can read image as a WeatherHacks::LWWS::Image" do
49
- @forecast.image.should be_a_kind_of(WeatherHacks::LWWS::Image)
42
+ it "#forecastdate" do
43
+ forecast {|f| f.forecastdate.should.be.kind_of(Time) }
50
44
  end
51
45
 
52
- it "can read celsius as a WeatherHacks::LWWS::Celsius" do
53
- @forecast.celsius.should be_a_kind_of(WeatherHacks::LWWS::Celsius)
46
+ it "#publictime" do
47
+ forecast {|f| f.publictime.should.be.kind_of(Time) }
54
48
  end
55
49
 
56
- it "can read fahrenheit as a WeatherHacks::LWWS::Fahrenheit" do
57
- @forecast.fahrenheit.should be_a_kind_of(WeatherHacks::LWWS::Fahrenheit)
50
+ it "#telop" do
51
+ forecast {|f| f.telop.should.be.kind_of(String) }
58
52
  end
59
53
 
60
- it "can read pinpoints as a list of WeatherHacks::LWWS::PinpointLocation" do
61
- @forecast.pinpoints.each do |location|
62
- location.should be_a_kind_of(WeatherHacks::LWWS::PinpointLocation)
63
- end
54
+ it "#description" do
55
+ forecast {|f| f.description.should.be.kind_of(String) }
64
56
  end
65
57
 
66
- it "can read copyright as a WeatherHacks::LWWS::Copyright" do
67
- @forecast.copyright.should be_a_kind_of(WeatherHacks::LWWS::Copyright)
58
+ it "#image" do
59
+ forecast {|f| f.image.should.be.kind_of(Image) }
68
60
  end
69
61
 
70
- after do
71
- @forecast = nil
62
+ it "#celsius" do
63
+ forecast {|f| f.celsius.should.be.kind_of(Celsius) }
72
64
  end
73
- end
74
65
 
75
- describe WeatherHacks::LWWS::Forecast, "#forecastday" do
76
- it "allows 'today'" do
77
- WeatherHacks::LWWS::Forecast.new($today).forecastday.should eql("today")
66
+ it "#fahrenheit" do
67
+ forecast {|f| f.fahrenheit.should.be.kind_of(Fahrenheit) }
78
68
  end
79
69
 
80
- it "allows 'tomorrow'" do
81
- WeatherHacks::LWWS::Forecast.new($tomorrow).forecastday.should eql("tomorrow")
70
+ it "#pinpoints" do
71
+ forecast do |f|
72
+ f.pinpoints.each do |location|
73
+ location.should.be.kind_of(PinpointLocation)
74
+ end
75
+ end
82
76
  end
83
77
 
84
- it "allows 'dayaftertomorrow'" do
85
- WeatherHacks::LWWS::Forecast.new($dayaftertomorrow).forecastday.should eql("dayaftertomorrow")
78
+ it "#copyright" do
79
+ forecast{|f| f.copyright.should.be.kind_of(Copyright) }
86
80
  end
87
81
  end
88
82
 
89
- describe WeatherHacks::LWWS::Location do
83
+ describe "WeatherHacks::LWWS::Location" do
90
84
  before do
91
- @location = WeatherHacks::LWWS::Forecast.new($today).location
85
+ @location = $today.location
92
86
  end
93
87
 
94
- it "can read area as a String" do
95
- @location.area.should be_a_kind_of(String)
88
+ it "area" do
89
+ @location.area.should.be.kind_of(String)
96
90
  end
97
91
 
98
- it "can read pref as a String" do
99
- @location.pref.should be_a_kind_of(String)
92
+ it "pref" do
93
+ @location.pref.should.be.kind_of(String)
100
94
  end
101
95
 
102
- it "can read city as a String" do
103
- @location.city.should be_a_kind_of(String)
96
+ it "city" do
97
+ @location.city.should.be.kind_of(String)
104
98
  end
105
99
 
106
100
  after do
@@ -108,136 +102,135 @@ describe WeatherHacks::LWWS::Location do
108
102
  end
109
103
  end
110
104
 
111
- describe WeatherHacks::LWWS::Image do
105
+ describe "WeatherHacks::LWWS::Image" do
112
106
  before do
113
- @image = WeatherHacks::LWWS::Forecast.new($today).image
107
+ @image = $today.image
114
108
  end
115
109
 
116
- it "can read title as a String" do
117
- @image.title.should be_a_kind_of(String)
110
+ after do
111
+ @image = nil
118
112
  end
119
113
 
120
- it "can read link as a URI" do
121
- @image.link.should be_a_kind_of(URI)
114
+ it "title" do
115
+ @image.title.should.be.kind_of(String)
122
116
  end
123
117
 
124
- it "can read url as a URI" do
125
- @image.url.should be_a_kind_of(URI)
118
+ it "link" do
119
+ @image.link.should.be.kind_of(URI)
126
120
  end
127
121
 
128
- it "can read width as a Integer" do
129
- @image.width.should be_a_kind_of(Integer)
122
+ it "url" do
123
+ @image.url.should.be.kind_of(URI)
130
124
  end
131
125
 
132
- it "can read height as a Integer" do
133
- @image.height.should be_a_kind_of(Integer)
126
+ it "width" do
127
+ @image.width.should.be.kind_of(Integer)
134
128
  end
135
129
 
136
- after do
137
- @image = nil
130
+ it "height" do
131
+ @image.height.should.be.kind_of(Integer)
138
132
  end
139
133
  end
140
134
 
141
- describe WeatherHacks::LWWS::Temperature do
135
+ describe "WeatherHacks::LWWS::Temperature" do
142
136
  before do
143
- forecast = WeatherHacks::LWWS::Forecast.new($today)
144
- @celsius = forecast.celsius
145
- @fahrenheit = forecast.fahrenheit
137
+ @celsius = $today.celsius
138
+ @fahrenheit = $today.fahrenheit
146
139
  end
147
140
 
148
- it "can read min of celsius as a Integer" do
149
- @celsius.min.should be_a_kind_of(Integer) if @celsius.min
150
-
141
+ after do
142
+ @celsius = nil
143
+ @fahrenheit = nil
151
144
  end
152
145
 
153
- it "can read max of celsius as a Integer" do
154
- @celsius.max.should be_a_kind_of(Integer) if @celsius.max
146
+ it "min celsius" do
147
+ @celsius.min.should.be.kind_of(Integer) if @celsius.min
155
148
  end
156
149
 
157
- it "can read min of fahrenheit as a Float" do
158
- @fahrenheit.min.should be_a_kind_of(Float) if @fahrenheit.min
150
+ it "max celsius" do
151
+ @celsius.max.should.be.kind_of(Integer) if @celsius.max
159
152
  end
160
153
 
161
- it "can read max of fahrenheit as a Float" do
162
- @fahrenheit.max.should be_a_kind_of(Float) if @fahrenheit.max
154
+ it "min fahrenheit" do
155
+ @fahrenheit.min.should.be.kind_of(Float) if @fahrenheit.min
163
156
  end
164
157
 
165
- after do
166
- @celsius = nil
167
- @fahrenheit = nil
158
+ it "max fahrenheit" do
159
+ @fahrenheit.max.should.be.kind_of(Float) if @fahrenheit.max
168
160
  end
169
161
  end
170
162
 
171
- describe WeatherHacks::LWWS::PinpointLocation do
163
+ describe "WeatherHacks::LWWS::PinpointLocation" do
172
164
  before do
173
- @pinpoints = WeatherHacks::LWWS::Forecast.new($today).pinpoints
165
+ @pinpoints = $today.pinpoints
174
166
  end
175
167
 
176
- it "can read title as a String" do
177
- @pinpoints.each do |location|
178
- location.title.should be_a_kind_of(String)
179
- end
168
+ after do
169
+ @pinpoints = nil
180
170
  end
181
171
 
182
- it "can read link as a URI" do
172
+ it "title" do
183
173
  @pinpoints.each do |location|
184
- location.link.should be_a_kind_of(URI)
174
+ location.title.should.be.kind_of(String)
185
175
  end
186
176
  end
187
177
 
188
- it "can read publictime as a Time" do
178
+ it "link" do
189
179
  @pinpoints.each do |location|
190
- location.publictime.should be_a_kind_of(Time)
180
+ location.link.should.be.kind_of(URI)
191
181
  end
192
182
  end
193
183
 
194
- after do
195
- @pinpoints = nil
184
+ it "publictime" do
185
+ @pinpoints.each do |location|
186
+ location.publictime.should.be.kind_of(Time)
187
+ end
196
188
  end
197
189
  end
198
190
 
199
- describe WeatherHacks::LWWS::Copyright do
191
+ describe "WeatherHacks::LWWS::Copyright" do
200
192
  before do
201
- @copyright = WeatherHacks::LWWS::Forecast.new($today).copyright
193
+ @copyright = $today.copyright
194
+ end
195
+
196
+ after do
197
+ @copyright = nil
202
198
  end
203
199
 
204
- it "can read title as a String" do
205
- @copyright.title.should be_a_kind_of(String)
200
+ it "title" do
201
+ @copyright.title.should.be.kind_of(String)
206
202
  end
207
203
 
208
- it "can read link as a URI" do
209
- @copyright.link.should be_a_kind_of(URI)
204
+ it "link" do
205
+ @copyright.link.should.be.kind_of(URI)
210
206
  end
211
207
 
212
- it "can read image as a WeatherHacks::LWWS::Image" do
213
- @copyright.image.should be_a_kind_of(WeatherHacks::LWWS::Image)
208
+ it "image" do
209
+ @copyright.image.should.be.kind_of(WeatherHacks::LWWS::Image)
214
210
  end
215
211
 
216
- it "can read providers as a list of WeatherHacks::LWWS::Provider" do
212
+ it "providers" do
217
213
  @copyright.providers.each do |provider|
218
- provider.should be_a_kind_of(WeatherHacks::LWWS::Provider)
214
+ provider.should.be.kind_of(WeatherHacks::LWWS::Provider)
219
215
  end
220
216
  end
221
217
 
222
- after do
223
- @copyright = nil
224
- end
225
218
  end
226
219
 
227
- describe WeatherHacks::LWWS::Provider do
220
+ describe "WeatherHacks::LWWS::Provider" do
228
221
  before do
229
- @provider = WeatherHacks::LWWS::Forecast.new($today).copyright.providers[0]
222
+ @provider = $today.copyright.providers[0]
230
223
  end
231
224
 
232
- it "can read name as a String" do
233
- @provider.name.should be_a_kind_of(String)
225
+ after do
226
+ @provider = nil
234
227
  end
235
228
 
236
- it "can read link as a URI" do
237
- @provider.link.should be_a_kind_of(URI)
229
+ it "name" do
230
+ @provider.name.should.be.kind_of(String)
238
231
  end
239
232
 
240
- after do
241
- @provider = nil
233
+ it "link" do
234
+ @provider.link.should.be.kind_of(URI)
242
235
  end
243
236
  end