weatherhacks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/lwws_spec.rb ADDED
@@ -0,0 +1,243 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe WeatherHacks::LWWS::Forecast do
4
+ before do
5
+ @forecast = WeatherHacks::LWWS::Forecast.new($today)
6
+ end
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
15
+
16
+ it "can read title as a String" do
17
+ @forecast.title.should be_a_kind_of(String)
18
+ end
19
+
20
+ it "can read link as a URI" do
21
+ @forecast.link.should be_a_kind_of(URI)
22
+ end
23
+
24
+ it "can read forecastday as a String" do
25
+ @forecast.forecastday.should be_a_kind_of(String)
26
+ end
27
+
28
+ it "can read day as a String" do
29
+ @forecast.day.should match(/Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday/)
30
+ end
31
+
32
+ it "can read forecastdate as a Time" do
33
+ @forecast.forecastdate.should be_a_kind_of(Time)
34
+ end
35
+
36
+ it "can read publictime as a Time" do
37
+ @forecast.publictime.should be_a_kind_of(Time)
38
+ end
39
+
40
+ it "can read telop as a String" do
41
+ @forecast.telop.should be_a_kind_of(String)
42
+ end
43
+
44
+ it "can read description as String" do
45
+ @forecast.description.should be_a_kind_of(String)
46
+ end
47
+
48
+ it "can read image as a WeatherHacks::LWWS::Image" do
49
+ @forecast.image.should be_a_kind_of(WeatherHacks::LWWS::Image)
50
+ end
51
+
52
+ it "can read celsius as a WeatherHacks::LWWS::Celsius" do
53
+ @forecast.celsius.should be_a_kind_of(WeatherHacks::LWWS::Celsius)
54
+ end
55
+
56
+ it "can read fahrenheit as a WeatherHacks::LWWS::Fahrenheit" do
57
+ @forecast.fahrenheit.should be_a_kind_of(WeatherHacks::LWWS::Fahrenheit)
58
+ end
59
+
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
64
+ end
65
+
66
+ it "can read copyright as a WeatherHacks::LWWS::Copyright" do
67
+ @forecast.copyright.should be_a_kind_of(WeatherHacks::LWWS::Copyright)
68
+ end
69
+
70
+ after do
71
+ @forecast = nil
72
+ end
73
+ end
74
+
75
+ describe WeatherHacks::LWWS::Forecast, "#forecastday" do
76
+ it "allows 'today'" do
77
+ WeatherHacks::LWWS::Forecast.new($today).forecastday.should eql("today")
78
+ end
79
+
80
+ it "allows 'tomorrow'" do
81
+ WeatherHacks::LWWS::Forecast.new($tomorrow).forecastday.should eql("tomorrow")
82
+ end
83
+
84
+ it "allows 'dayaftertomorrow'" do
85
+ WeatherHacks::LWWS::Forecast.new($dayaftertomorrow).forecastday.should eql("dayaftertomorrow")
86
+ end
87
+ end
88
+
89
+ describe WeatherHacks::LWWS::Location do
90
+ before do
91
+ @location = WeatherHacks::LWWS::Forecast.new($today).location
92
+ end
93
+
94
+ it "can read area as a String" do
95
+ @location.area.should be_a_kind_of(String)
96
+ end
97
+
98
+ it "can read pref as a String" do
99
+ @location.pref.should be_a_kind_of(String)
100
+ end
101
+
102
+ it "can read city as a String" do
103
+ @location.city.should be_a_kind_of(String)
104
+ end
105
+
106
+ after do
107
+ @location = nil
108
+ end
109
+ end
110
+
111
+ describe WeatherHacks::LWWS::Image do
112
+ before do
113
+ @image = WeatherHacks::LWWS::Forecast.new($today).image
114
+ end
115
+
116
+ it "can read title as a String" do
117
+ @image.title.should be_a_kind_of(String)
118
+ end
119
+
120
+ it "can read link as a URI" do
121
+ @image.link.should be_a_kind_of(URI)
122
+ end
123
+
124
+ it "can read url as a URI" do
125
+ @image.url.should be_a_kind_of(URI)
126
+ end
127
+
128
+ it "can read width as a Integer" do
129
+ @image.width.should be_a_kind_of(Integer)
130
+ end
131
+
132
+ it "can read height as a Integer" do
133
+ @image.height.should be_a_kind_of(Integer)
134
+ end
135
+
136
+ after do
137
+ @image = nil
138
+ end
139
+ end
140
+
141
+ describe WeatherHacks::LWWS::Temperature do
142
+ before do
143
+ forecast = WeatherHacks::LWWS::Forecast.new($today)
144
+ @celsius = forecast.celsius
145
+ @fahrenheit = forecast.fahrenheit
146
+ end
147
+
148
+ it "can read min of celsius as a Integer" do
149
+ @celsius.min.should be_a_kind_of(Integer) if @celsius.min
150
+
151
+ end
152
+
153
+ it "can read max of celsius as a Integer" do
154
+ @celsius.max.should be_a_kind_of(Integer) if @celsius.max
155
+ end
156
+
157
+ it "can read min of fahrenheit as a Float" do
158
+ @fahrenheit.min.should be_a_kind_of(Float) if @fahrenheit.min
159
+ end
160
+
161
+ it "can read max of fahrenheit as a Float" do
162
+ @fahrenheit.max.should be_a_kind_of(Float) if @fahrenheit.max
163
+ end
164
+
165
+ after do
166
+ @celsius = nil
167
+ @fahrenheit = nil
168
+ end
169
+ end
170
+
171
+ describe WeatherHacks::LWWS::PinpointLocation do
172
+ before do
173
+ @pinpoints = WeatherHacks::LWWS::Forecast.new($today).pinpoints
174
+ end
175
+
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
180
+ end
181
+
182
+ it "can read link as a URI" do
183
+ @pinpoints.each do |location|
184
+ location.link.should be_a_kind_of(URI)
185
+ end
186
+ end
187
+
188
+ it "can read publictime as a Time" do
189
+ @pinpoints.each do |location|
190
+ location.publictime.should be_a_kind_of(Time)
191
+ end
192
+ end
193
+
194
+ after do
195
+ @pinpoints = nil
196
+ end
197
+ end
198
+
199
+ describe WeatherHacks::LWWS::Copyright do
200
+ before do
201
+ @copyright = WeatherHacks::LWWS::Forecast.new($today).copyright
202
+ end
203
+
204
+ it "can read title as a String" do
205
+ @copyright.title.should be_a_kind_of(String)
206
+ end
207
+
208
+ it "can read link as a URI" do
209
+ @copyright.link.should be_a_kind_of(URI)
210
+ end
211
+
212
+ it "can read image as a WeatherHacks::LWWS::Image" do
213
+ @copyright.image.should be_a_kind_of(WeatherHacks::LWWS::Image)
214
+ end
215
+
216
+ it "can read providers as a list of WeatherHacks::LWWS::Provider" do
217
+ @copyright.providers.each do |provider|
218
+ provider.should be_a_kind_of(WeatherHacks::LWWS::Provider)
219
+ end
220
+ end
221
+
222
+ after do
223
+ @copyright = nil
224
+ end
225
+ end
226
+
227
+ describe WeatherHacks::LWWS::Provider do
228
+ before do
229
+ @provider = WeatherHacks::LWWS::Forecast.new($today).copyright.providers[0]
230
+ end
231
+
232
+ it "can read name as a String" do
233
+ @provider.name.should be_a_kind_of(String)
234
+ end
235
+
236
+ it "can read link as a URI" do
237
+ @provider.link.should be_a_kind_of(URI)
238
+ end
239
+
240
+ after do
241
+ @provider = nil
242
+ end
243
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ -fs --colour
@@ -0,0 +1,11 @@
1
+ require 'spec'
2
+ ROOT = File.join(File.dirname(__FILE__), "..")
3
+ $LOAD_PATH << File.join(ROOT, "lib")
4
+ require "weatherhacks"
5
+
6
+ $today =
7
+ REXML::Document.new(File.read(File.join(ROOT, "tmp", "lwws_today.xml")))
8
+ $tomorrow =
9
+ REXML::Document.new(File.read(File.join(ROOT, "tmp", "lwws_tomorrow.xml")))
10
+ $dayaftertomorrow =
11
+ REXML::Document.new(File.read(File.join(ROOT, "tmp", "lwws_dayaftertomorrow.xml")))
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/*_spec.rb']
21
+ end
@@ -0,0 +1,20 @@
1
+ namespace :weatherhacks do
2
+ desc 'Download forecastmap.xml'
3
+ task :download_forecastmap do
4
+ url = "http://weather.livedoor.com/forecast/rss/forecastmap.xml"
5
+ sh %{wget -O tmp/forecastmap.xml #{url}}
6
+ end
7
+
8
+ desc 'Generate forecastmap.rb'
9
+ task :forecastmap do
10
+ sh %{xsltproc -o lib/weatherhacks/forecastmap.rb misc/forecastmap.xsl tmp/forecastmap.xml}
11
+ end
12
+
13
+ desc 'Download test data'
14
+ task :download_test_lwws_data do
15
+ url = "http://weather.livedoor.com/forecast/webservice/rest/v1?city=113&day="
16
+ sh %{curl -o tmp/lwws_today.xml "#{url + "today"}"}
17
+ sh %{curl -o tmp/lwws_tomorrow.xml "#{url + "tomorrow"}"}
18
+ sh %{curl -o tmp/lwws_dayaftertomorrow.xml "#{url + "dayaftertomorrow"}"}
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,119 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ ruby-weatherhacks
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>ruby-weatherhacks</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/weatherhacks"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/weatherhacks" class="numbers">0.1.0</a>
37
+ </div>
38
+ <h2>What</h2>
39
+
40
+
41
+ <p>ruby-weatherhacks is a wrapper library for livedoor WeatherHacks <span class="caps">API</span>.</p>
42
+
43
+
44
+ <p>- <a href="http://www.livedoor.com/">livdoor</a>
45
+ - <a href="http://weather.livedoor.com/weather_hacks/">livedoor WeatherHacks</a></p>
46
+
47
+
48
+ <h2>Installing</h2>
49
+
50
+
51
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">weatherhacks</span></pre></p>
52
+
53
+
54
+ <h2><span class="caps">API</span> Document</h2>
55
+
56
+
57
+ <p><a href="http://weatherhacks.rubyforge.org/rdoc/">http://weatherhacks.rubyforge.org/rdoc/</a></p>
58
+
59
+
60
+ <h2>Demonstration of usage</h2>
61
+
62
+
63
+ <pre><code>
64
+ require "weatherhacks"
65
+
66
+ matsue = WeatherHacks::CITY["松江"]
67
+ forecast = WeatherHacks::LWWS.request(matuse.id, :today)
68
+ forecast.telop # =&gt; ex. 雨時々曇
69
+ forecast.celsius.max # =&gt; ex. 12
70
+
71
+ </code></pre>
72
+
73
+ <h2>Usage of lwws command</h2>
74
+
75
+
76
+ <pre><code>
77
+ % lwws 松江
78
+ 中国地方/島根県/松江
79
+ 今日: 雨時々曇(最高気温12度)
80
+ 明日: 雨のち曇()
81
+ 明後日: 曇時々雨(最高気温5度)
82
+
83
+ </code></pre>
84
+
85
+ <h2>Forum</h2>
86
+
87
+
88
+ <p><a href="http://groups.google.com/group/ruby-weatherhacks">http://groups.google.com/group/ruby-weatherhacks</a></p>
89
+
90
+
91
+ <h2>How to submit patches</h2>
92
+
93
+
94
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
95
+
96
+
97
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/weatherhacks/trunk</code> for anonymous access.</p>
98
+
99
+
100
+ <h2>License</h2>
101
+
102
+
103
+ <p>This code is free to use under the terms of the Ruby License.</p>
104
+
105
+
106
+ <h2>Contact</h2>
107
+
108
+
109
+ <p>Comments are welcome. Send an email to <a href="mailto:keita.yamaguchi@gmail.com">Keita Yamaguchi</a> or the <a href="http://groups.google.com/group/ruby-weatherhacks">forum</a>.</p>
110
+ <p class="coda">
111
+ <a href="keita.yamaguchi@gmail.com">FIXME full name</a>, 12th December 2007<br>
112
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
113
+ </p>
114
+ </div>
115
+
116
+ <!-- insert site tracking codes here, like Google Urchin -->
117
+
118
+ </body>
119
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,57 @@
1
+ h1. ruby-weatherhacks
2
+
3
+ h2. What
4
+
5
+ ruby-weatherhacks is a wrapper library for livedoor WeatherHacks API.
6
+
7
+ - "livdoor":http://www.livedoor.com/
8
+ - "livedoor WeatherHacks":http://weather.livedoor.com/weather_hacks/
9
+
10
+ h2. Installing
11
+
12
+ <pre syntax="ruby">sudo gem install weatherhacks</pre>
13
+
14
+ h2. API Document
15
+
16
+ "http://weatherhacks.rubyforge.org/rdoc/":http://weatherhacks.rubyforge.org/rdoc/
17
+
18
+ h2. Demonstration of usage
19
+
20
+ <pre><code>
21
+ require "weatherhacks"
22
+
23
+ matsue = WeatherHacks::CITY["松江"]
24
+ forecast = WeatherHacks::LWWS.request(matuse.id, :today)
25
+ forecast.telop # => ex. 雨時々曇
26
+ forecast.celsius.max # => ex. 12
27
+
28
+ </code></pre>
29
+
30
+ h2. Usage of lwws command
31
+
32
+ <pre><code>
33
+ % lwws 松江
34
+ 中国地方/島根県/松江
35
+ 今日: 雨時々曇(最高気温12度)
36
+ 明日: 雨のち曇()
37
+ 明後日: 曇時々雨(最高気温5度)
38
+
39
+ </code></pre>
40
+
41
+ h2. Forum
42
+
43
+ "http://groups.google.com/group/ruby-weatherhacks":http://groups.google.com/group/ruby-weatherhacks
44
+
45
+ h2. How to submit patches
46
+
47
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
48
+
49
+ The trunk repository is <code>svn://rubyforge.org/var/svn/weatherhacks/trunk</code> for anonymous access.
50
+
51
+ h2. License
52
+
53
+ This code is free to use under the terms of the Ruby License.
54
+
55
+ h2. Contact
56
+
57
+ Comments are welcome. Send an email to "Keita Yamaguchi":mailto:keita.yamaguchi@gmail.com or the "forum":http://groups.google.com/group/ruby-weatherhacks.