weather_hacker 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/weather_hacker/client.rb +4 -0
- data/lib/weather_hacker/version.rb +1 -1
- data/lib/weather_hacker.rb +5 -5
- data/spec/weather_hacker/client_spec.rb +26 -16
- metadata +15 -15
@@ -21,6 +21,8 @@ class WeatherHacker
|
|
21
21
|
"min" => hash["lwws"]["temperature"]["min"]["celsius"],
|
22
22
|
},
|
23
23
|
}
|
24
|
+
rescue ParseError
|
25
|
+
nil
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
@@ -59,6 +61,8 @@ class WeatherHacker
|
|
59
61
|
response = get ZIPCODE_URL, :query => { :zn => zipcode }
|
60
62
|
values = response["ZIP_result"]["ADDRESS_value"]["value"]
|
61
63
|
Hash[values.map { |v| v.to_a.flatten }]
|
64
|
+
rescue NoMethodError
|
65
|
+
raise ParseError, "The zipcode is not supported by API"
|
62
66
|
end
|
63
67
|
|
64
68
|
# canonical prefecture name
|
data/lib/weather_hacker.rb
CHANGED
@@ -24,10 +24,10 @@ class WeatherHacker
|
|
24
24
|
# if the date is not supported, return nil
|
25
25
|
def on(date)
|
26
26
|
now = Date.today
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
case date
|
28
|
+
when now + 0; today
|
29
|
+
when now + 1; tomorrow
|
30
|
+
when now + 2; day_after_tomorrow
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
@@ -9,33 +9,43 @@ describe "WeatherHacker::Client" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#get_weather" do
|
12
|
-
|
13
|
-
@result = @client.get_weather(@zipcode)
|
14
|
-
end
|
12
|
+
let(:result) { @client.get_weather(@zipcode) }
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
context "when server returns expected response" do
|
15
|
+
it "should get parsed weather data in Hash" do
|
16
|
+
[Hash, NilClass].should be_include result.class
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have weather" do
|
20
|
+
result["weather"].should =~ /[晴曇雨]/
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
it "should have max and min temperature" do
|
24
|
+
result["temperature"].has_key?("max").should be_true
|
25
|
+
result["temperature"].has_key?("min").should be_true
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
context "when server returns unexpeced response" do
|
30
|
+
before do
|
31
|
+
@zipcode = "999-9999"
|
32
|
+
end
|
33
|
+
|
34
|
+
it do
|
35
|
+
result.should be_nil
|
36
|
+
end
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
40
|
shared_examples_for "having area table" do
|
31
|
-
it "
|
41
|
+
it "should have area table" do
|
32
42
|
@client.send(:id_by_city).keys.size.should_not == 0
|
33
43
|
@client.send(:pref_by_city).keys.size.should_not == 0
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
37
47
|
shared_examples_for "not having area table" do
|
38
|
-
it "
|
48
|
+
it "should have not area table" do
|
39
49
|
@client.instance_variable_get(:@id_by_city).should be_nil
|
40
50
|
@client.instance_variable_get(:@pref_by_city).should be_nil
|
41
51
|
end
|
@@ -64,14 +74,14 @@ describe "WeatherHacker::Client" do
|
|
64
74
|
end
|
65
75
|
|
66
76
|
describe "#city_id_by_zipcode" do
|
67
|
-
it "return city_id" do
|
77
|
+
it "should return city_id" do
|
68
78
|
city_id = @client.send(:city_id_by_zipcode, @zipcode)
|
69
79
|
city_id.should be_kind_of Integer
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
73
83
|
describe "#id_by_pref" do
|
74
|
-
it "
|
84
|
+
it "should be cached in instance variable" do
|
75
85
|
@client.instance_variable_get(:@id_by_pref).should be_nil
|
76
86
|
@client.send(:id_by_pref)
|
77
87
|
@client.instance_variable_get(:@id_by_pref).should be_kind_of Hash
|
@@ -80,7 +90,7 @@ describe "WeatherHacker::Client" do
|
|
80
90
|
@client.send(:id_by_pref)
|
81
91
|
end
|
82
92
|
|
83
|
-
it "return table of id by pref" do
|
93
|
+
it "should return table of id by pref" do
|
84
94
|
@client.send(:id_by_pref).should be_kind_of Hash
|
85
95
|
end
|
86
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_hacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70362866214980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70362866214980
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70362866214560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70362866214560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: awesome_print
|
38
|
-
requirement: &
|
38
|
+
requirement: &70362866214100 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70362866214100
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70362866213660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70362866213660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &70362866213240 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70362866213240
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov-vim
|
71
|
-
requirement: &
|
71
|
+
requirement: &70362866212780 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70362866212780
|
80
80
|
description: Library for Livedoor Weather Web Service
|
81
81
|
email:
|
82
82
|
- r7kamura@gmail.com
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
segments:
|
119
119
|
- 0
|
120
|
-
hash:
|
120
|
+
hash: -3473716244803351994
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
none: false
|
123
123
|
requirements:
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: -3473716244803351994
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
132
|
rubygems_version: 1.8.15
|