weather-report 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af1d8192f60c896b77e6ce11143ab06ed934ff7f
4
+ data.tar.gz: e1d2070cb70c0ce54e8b6f521ef023cd01b66a69
5
+ SHA512:
6
+ metadata.gz: 4197fa2fdb3e78d748d4423c940e2910c7b328be3d195dc410e4e420ff6b13dc9f8480b2282b5a292d83b67fe1d36eeab45768d246eb011f961be347fd5e030a
7
+ data.tar.gz: ced5d01c569fa21cc33ea9383326b075a906c941fadc758c205a3fe531db5200316d46e69f21ebd43b63dfcd590b5c94c5c514199db9adb8b74c1e5ef06b90d9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather-report.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
7
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
+ watch(%r|^test/test_helper\.rb|) { "test" }
9
+
10
+ # with Minitest::Spec
11
+ # watch(%r|^spec/(.*)_spec\.rb|)
12
+ # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ # watch(%r|^spec/spec_helper\.rb|) { "spec" }
14
+
15
+ # Rails 3.2
16
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
17
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
18
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
19
+
20
+ # Rails
21
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
22
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
23
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
24
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 zakuni
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Weather Report
2
+
3
+ A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'weather-report'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install weather-report
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'weather-report'
23
+
24
+ id = WeatherReport::Weather.request_cityid("東京")
25
+ weather = WeatherReport::Weather.new(id)
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'weather-report'
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'json'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+ require "weather-report/version"
6
+
7
+ module WeatherReport
8
+ class WeatherReportError < StandardError; end
9
+
10
+ class Weather
11
+ attr_reader :today, :tomorrow, :day_after_tomorrow
12
+
13
+ def initialize(city_id)
14
+ @uri = URI.parse("http://weather.livedoor.com/forecast/webservice/json/v1?city=#{city_id}")
15
+ end
16
+
17
+ def self.request_cityid(city)
18
+ doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml"))
19
+ doc.search("//city[@title='#{city}']").attr("id").value
20
+ rescue
21
+ raise WeatherReportError
22
+ end
23
+
24
+ def today
25
+ @today ||= forecast("今日")
26
+ end
27
+
28
+ def tomorrow
29
+ @tomorrow ||= forecast("明日")
30
+ end
31
+
32
+ def day_after_tomorrow
33
+ @day_after_tomorrow ||= forecast("明後日")
34
+ end
35
+
36
+ private
37
+
38
+ def forecast(dateLabel)
39
+ forecasts.each {|elem| return elem if elem["dateLabel"] == dateLabel}
40
+ end
41
+
42
+ def forecasts
43
+ @forecasts ||= read["forecasts"]
44
+ end
45
+
46
+ def read
47
+ @response ||= JSON.parse(@uri.read)
48
+ rescue
49
+ raise WeatherReportError
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherReport
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ require 'minitest/pride'
4
+
5
+ require 'weather-report'
6
+
7
+ MiniTest::Reporters.use! [MiniTest::Reporters::DefaultReporter.new, MiniTest::Reporters::GuardReporter.new]
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'test_helper'
4
+
5
+ class TestWeatherReport < MiniTest::Unit::TestCase
6
+ include WeatherReport
7
+
8
+ def setup
9
+ @id = Weather.request_cityid("東京")
10
+ @weather = Weather.new(@id)
11
+ end
12
+
13
+ def test_initialize
14
+ assert_raises ArgumentError do
15
+ Weather.new
16
+ end
17
+ assert_instance_of Weather, Weather.new(@id)
18
+ end
19
+
20
+ def test_today
21
+ assert_respond_to @weather, :today
22
+
23
+ today = @weather.today
24
+ assert_includes(today, "date")
25
+ assert_includes(today, "telop")
26
+ assert_includes(today, "temperature")
27
+ end
28
+
29
+ def test_tomorrow
30
+ assert_respond_to @weather, :tomorrow
31
+
32
+ tomorrow = @weather.tomorrow
33
+ assert_includes(tomorrow, "date")
34
+ assert_includes(tomorrow, "telop")
35
+ assert_includes(tomorrow, "temperature")
36
+ end
37
+
38
+ def test_day_after_tomorrow
39
+ assert_respond_to @weather, :day_after_tomorrow
40
+
41
+ day_after_tomorrow = @weather.day_after_tomorrow
42
+ assert_includes(day_after_tomorrow, "date")
43
+ assert_includes(day_after_tomorrow, "telop")
44
+ assert_includes(day_after_tomorrow, "temperature")
45
+ end
46
+
47
+ def test_request_cityid
48
+ assert_respond_to Weather, :request_cityid
49
+ assert_equal "130010", Weather.request_cityid("東京")
50
+ assert_equal "140010", Weather.request_cityid("横浜")
51
+ assert_raises(WeatherReportError) do
52
+ Weather.request_cityid(nil)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather-report/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather-report"
8
+ spec.version = WeatherReport::VERSION
9
+ spec.authors = ["zakuni"]
10
+ spec.email = ["kunio038@gmail.com"]
11
+ spec.description = %q{A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).}
12
+ spec.summary = %q{A Ruby client of Livedoor Weather Web Service.}
13
+ spec.homepage = "https://github.com/zakuni/weather-report"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "guard-minitest"
25
+ spec.add_development_dependency "rb-fsevent"
26
+ spec.add_development_dependency "minitest-reporters"
27
+ spec.add_development_dependency "growl"
28
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather-report
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - zakuni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rb-fsevent
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).
112
+ email:
113
+ - kunio038@gmail.com
114
+ executables:
115
+ - weather-report
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - Guardfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/weather-report
126
+ - lib/weather-report.rb
127
+ - lib/weather-report/version.rb
128
+ - test/test_helper.rb
129
+ - test/test_weather-report.rb
130
+ - weather-report.gemspec
131
+ homepage: https://github.com/zakuni/weather-report
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.0.0
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: A Ruby client of Livedoor Weather Web Service.
155
+ test_files:
156
+ - test/test_helper.rb
157
+ - test/test_weather-report.rb
158
+ has_rdoc: