china_aqi 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/china_aqi/base.rb +4 -0
- data/lib/china_aqi/utility.rb +0 -6
- data/lib/china_aqi/version.rb +1 -1
- data/spec/china_aqi/aqi_spec.rb +145 -0
- data/spec/spec_helper.rb +0 -2
- metadata +4 -12
- data/spec/china_aqi/aqi/dynamic_spec.rb +0 -47
- data/spec/china_aqi/aqi/static_spec.rb +0 -17
- data/spec/china_aqi/aqi/station_spec.rb +0 -16
- data/spec/china_aqi/helper/city_stations_spec.rb +0 -30
- data/spec/china_aqi/shared_spec.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5629478b4a11380f5cf5768d6e93381dcef35081
|
4
|
+
data.tar.gz: 73938de2bcb5dcbd52b3607f391759823dccdc6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54948bc0de829400be061cda90c2b810f87440cfb2d390dfc1188a0763186ad4744341fe6da42061f91c90399a02cda896d94b70e5532a77f1fbd5a678082ce5
|
7
|
+
data.tar.gz: 53c0da5802bc59812543ada719f660d20a47ab24e8d40eeee438fe41b6da8a936b48ac48d5f80900ba9755a4e21087af83fa0f57b10b930d139140da7fabfb43
|
data/lib/china_aqi/base.rb
CHANGED
data/lib/china_aqi/utility.rb
CHANGED
data/lib/china_aqi/version.rb
CHANGED
@@ -0,0 +1,145 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ChinaAqi do
|
5
|
+
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
6
|
+
|
7
|
+
describe 'Shared examples' do
|
8
|
+
shared_examples "common examples" do |klass, obj|
|
9
|
+
it 'should return URI::HTTP object own context when call "uri" method' do
|
10
|
+
uri = obj.uri
|
11
|
+
uri.should be_a(URI::HTTP)
|
12
|
+
uri.host.should eq('www.pm25.in')
|
13
|
+
uri.path.should eq("/api/querys/#{klass.method.to_s}.json")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return url string with own context when call "url" method' do
|
17
|
+
obj.url.should be_a(String)
|
18
|
+
obj.url.include?("http://www.pm25.in/api/querys/#{klass.method.to_s}.json").should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return an array or hash with aqi data when call "get" method' do
|
22
|
+
data = obj.get
|
23
|
+
data.class.should satisfy{|k| [Array, Hash].include?(k)}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_examples 'class attribute' do |klass, value|
|
28
|
+
it "should have class attribute 'method' equal #{value}" do
|
29
|
+
klass.method.should eq(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
shared_examples "common dynamic examples" do |klass|
|
34
|
+
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
35
|
+
obj = klass.new('shanghai')
|
36
|
+
|
37
|
+
include_examples "common examples", klass, obj
|
38
|
+
end
|
39
|
+
|
40
|
+
shared_examples "common static examples" do |klass|
|
41
|
+
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
42
|
+
obj = klass.new
|
43
|
+
|
44
|
+
include_examples "common examples", klass, obj
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'Dynamic models' do
|
49
|
+
describe ChinaAqi::City do
|
50
|
+
include_examples "common dynamic examples", ChinaAqi::City
|
51
|
+
include_examples "class attribute", ChinaAqi::City, :only_aqi
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ChinaAqi::CityPro do
|
55
|
+
include_examples "common dynamic examples", ChinaAqi::CityPro
|
56
|
+
include_examples "class attribute", ChinaAqi::CityPro, :aqi_details
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ChinaAqi::CO do
|
60
|
+
include_examples "common dynamic examples", ChinaAqi::CO
|
61
|
+
include_examples "class attribute", ChinaAqi::CO, :co
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ChinaAqi::NO2 do
|
65
|
+
include_examples "common dynamic examples", ChinaAqi::NO2
|
66
|
+
include_examples "class attribute", ChinaAqi::NO2, :no2
|
67
|
+
end
|
68
|
+
|
69
|
+
describe ChinaAqi::O3 do
|
70
|
+
include_examples "common dynamic examples", ChinaAqi::O3
|
71
|
+
include_examples "class attribute", ChinaAqi::O3, :o3
|
72
|
+
end
|
73
|
+
|
74
|
+
describe ChinaAqi::PM10 do
|
75
|
+
include_examples "common dynamic examples", ChinaAqi::PM10
|
76
|
+
include_examples "class attribute", ChinaAqi::PM10, :pm10
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ChinaAqi::PM25 do
|
80
|
+
include_examples "common dynamic examples", ChinaAqi::PM25
|
81
|
+
include_examples "class attribute", ChinaAqi::PM25, :pm2_5
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ChinaAqi::SO2 do
|
85
|
+
include_examples "common dynamic examples", ChinaAqi::SO2
|
86
|
+
include_examples "class attribute", ChinaAqi::SO2, :so2
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'Static models' do
|
91
|
+
describe ChinaAqi::Global do
|
92
|
+
include_examples "common static examples", ChinaAqi::Global
|
93
|
+
include_examples "class attribute", ChinaAqi::Global, :all_cities
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ChinaAqi::Ranking do
|
97
|
+
include_examples "common static examples", ChinaAqi::Ranking
|
98
|
+
include_examples "class attribute", ChinaAqi::Ranking, :aqi_ranking
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'Station' do
|
103
|
+
describe ChinaAqi::Station do
|
104
|
+
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
105
|
+
obj = ChinaAqi::Station.new('1141A')
|
106
|
+
|
107
|
+
include_examples "common examples", ChinaAqi::Station, obj
|
108
|
+
include_examples "class attribute", ChinaAqi::Station, :aqis_by_station
|
109
|
+
|
110
|
+
it 'should have station_code instance variable' do
|
111
|
+
obj = ChinaAqi::Station.new('1141A')
|
112
|
+
obj.instance_variable_defined?(:@station_code).should be_true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'Helper' do
|
118
|
+
describe ChinaAqi::CityStations do
|
119
|
+
include_examples "common dynamic examples", ChinaAqi::CityStations
|
120
|
+
include_examples "class attribute", ChinaAqi::CityStations, :station_names
|
121
|
+
|
122
|
+
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
123
|
+
|
124
|
+
it 'should have module function called get_stations_for_city to get stations for one city' do
|
125
|
+
ChinaAqi.respond_to?(:get_stations_for_city).should be_true
|
126
|
+
stations = ChinaAqi.get_stations_for_city('shanghai')
|
127
|
+
stations.should be_a(Hash)
|
128
|
+
stations.key?('city').should be_true
|
129
|
+
stations.key?('stations').should be_true
|
130
|
+
stations['stations'].should be_a(Array)
|
131
|
+
stations['city'].should eq('上海')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should return a hash with aqi data when call "get" instance method' do
|
135
|
+
stations = ChinaAqi::CityStations.new('shanghai').get
|
136
|
+
stations.should be_a(Hash)
|
137
|
+
stations.key?('city').should be_true
|
138
|
+
stations.key?('stations').should be_true
|
139
|
+
stations['stations'].should be_a(Array)
|
140
|
+
stations['city'].should eq('上海')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_aqi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xuhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,12 +114,8 @@ files:
|
|
114
114
|
- lib/china_aqi/version.rb
|
115
115
|
- lib/generators/china_aqi/install/USAGE
|
116
116
|
- lib/generators/china_aqi/install/install_generator.rb
|
117
|
-
- spec/china_aqi/
|
118
|
-
- spec/china_aqi/aqi/static_spec.rb
|
119
|
-
- spec/china_aqi/aqi/station_spec.rb
|
117
|
+
- spec/china_aqi/aqi_spec.rb
|
120
118
|
- spec/china_aqi/base_spec.rb
|
121
|
-
- spec/china_aqi/helper/city_stations_spec.rb
|
122
|
-
- spec/china_aqi/shared_spec.rb
|
123
119
|
- spec/china_aqi_spec.rb
|
124
120
|
- spec/spec_helper.rb
|
125
121
|
homepage: https://github.com/Xuhao/china_aqi
|
@@ -147,11 +143,7 @@ signing_key:
|
|
147
143
|
specification_version: 4
|
148
144
|
summary: China AQI API from PM25.in
|
149
145
|
test_files:
|
150
|
-
- spec/china_aqi/
|
151
|
-
- spec/china_aqi/aqi/static_spec.rb
|
152
|
-
- spec/china_aqi/aqi/station_spec.rb
|
146
|
+
- spec/china_aqi/aqi_spec.rb
|
153
147
|
- spec/china_aqi/base_spec.rb
|
154
|
-
- spec/china_aqi/helper/city_stations_spec.rb
|
155
|
-
- spec/china_aqi/shared_spec.rb
|
156
148
|
- spec/china_aqi_spec.rb
|
157
149
|
- spec/spec_helper.rb
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ChinaAqi do
|
4
|
-
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
5
|
-
|
6
|
-
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
7
|
-
|
8
|
-
describe ChinaAqi::City do
|
9
|
-
include_examples "common dynamic examples", ChinaAqi::City
|
10
|
-
include_examples "class attribute", ChinaAqi::City, :only_aqi
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ChinaAqi::CityPro do
|
14
|
-
include_examples "common dynamic examples", ChinaAqi::CityPro
|
15
|
-
include_examples "class attribute", ChinaAqi::CityPro, :aqi_details
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ChinaAqi::CO do
|
19
|
-
include_examples "common dynamic examples", ChinaAqi::CO
|
20
|
-
include_examples "class attribute", ChinaAqi::CO, :co
|
21
|
-
end
|
22
|
-
|
23
|
-
describe ChinaAqi::NO2 do
|
24
|
-
include_examples "common dynamic examples", ChinaAqi::NO2
|
25
|
-
include_examples "class attribute", ChinaAqi::NO2, :no2
|
26
|
-
end
|
27
|
-
|
28
|
-
describe ChinaAqi::O3 do
|
29
|
-
include_examples "common dynamic examples", ChinaAqi::O3
|
30
|
-
include_examples "class attribute", ChinaAqi::O3, :o3
|
31
|
-
end
|
32
|
-
|
33
|
-
describe ChinaAqi::PM10 do
|
34
|
-
include_examples "common dynamic examples", ChinaAqi::PM10
|
35
|
-
include_examples "class attribute", ChinaAqi::PM10, :pm10
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ChinaAqi::PM25 do
|
39
|
-
include_examples "common dynamic examples", ChinaAqi::PM25
|
40
|
-
include_examples "class attribute", ChinaAqi::PM25, :pm2_5
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ChinaAqi::SO2 do
|
44
|
-
include_examples "common dynamic examples", ChinaAqi::SO2
|
45
|
-
include_examples "class attribute", ChinaAqi::SO2, :so2
|
46
|
-
end
|
47
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ChinaAqi do
|
4
|
-
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
5
|
-
|
6
|
-
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
7
|
-
|
8
|
-
describe ChinaAqi::Global do
|
9
|
-
include_examples "common static examples", ChinaAqi::Global
|
10
|
-
include_examples "class attribute", ChinaAqi::Global, :all_cities
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ChinaAqi::Ranking do
|
14
|
-
include_examples "common static examples", ChinaAqi::Ranking
|
15
|
-
include_examples "class attribute", ChinaAqi::Ranking, :aqi_ranking
|
16
|
-
end
|
17
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ChinaAqi::Station do
|
4
|
-
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
5
|
-
|
6
|
-
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
7
|
-
obj = ChinaAqi::Station.new('1141A')
|
8
|
-
|
9
|
-
include_examples "common examples", ChinaAqi::Station, obj
|
10
|
-
include_examples "class attribute", ChinaAqi::Station, :aqis_by_station
|
11
|
-
|
12
|
-
it 'should have station_code instance variable' do
|
13
|
-
obj = ChinaAqi::Station.new('1141A')
|
14
|
-
obj.instance_variable_defined?(:@station_code).should be_true
|
15
|
-
end
|
16
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe ChinaAqi do
|
5
|
-
describe ChinaAqi::CityStations do
|
6
|
-
include_examples "common dynamic examples", ChinaAqi::CityStations
|
7
|
-
include_examples "class attribute", ChinaAqi::CityStations, :station_names
|
8
|
-
|
9
|
-
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
10
|
-
|
11
|
-
it 'should have module function called get_stations_for_city to get stations for one city' do
|
12
|
-
ChinaAqi.respond_to?(:get_stations_for_city).should be_true
|
13
|
-
stations = ChinaAqi.get_stations_for_city('Shanghai')
|
14
|
-
stations.should be_a(Hash)
|
15
|
-
stations.key?('city').should be_true
|
16
|
-
stations.key?('stations').should be_true
|
17
|
-
stations['stations'].should be_a(Array)
|
18
|
-
stations['city'].should eq('上海')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should return a hash with aqi data when call "get" instance method' do
|
22
|
-
stations = ChinaAqi::CityStations.new('Shanghai').get
|
23
|
-
stations.should be_a(Hash)
|
24
|
-
stations.key?('city').should be_true
|
25
|
-
stations.key?('stations').should be_true
|
26
|
-
stations['stations'].should be_a(Array)
|
27
|
-
stations['city'].should eq('上海')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ChinaAqi do
|
4
|
-
shared_examples "common examples" do |klass, obj|
|
5
|
-
it 'should return URI::HTTP object own context when call "uri" method' do
|
6
|
-
uri = obj.uri
|
7
|
-
uri.should be_a(URI::HTTP)
|
8
|
-
uri.host.should eq('www.pm25.in')
|
9
|
-
uri.path.should eq("/api/querys/#{klass.method.to_s}.json")
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should return url string with own context when call "url" method' do
|
13
|
-
obj.url.should be_a(String)
|
14
|
-
obj.url.include?("http://www.pm25.in/api/querys/#{klass.method.to_s}.json").should be_true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
shared_examples 'class attribute' do |klass, value|
|
19
|
-
it "should have class attribute 'method' equal #{value}" do
|
20
|
-
klass.method.should eq(value)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
shared_examples 'get array' do |klass|
|
25
|
-
before(:each) { ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq' }
|
26
|
-
let(:obj) { klass.new('Shanghai') }
|
27
|
-
|
28
|
-
it 'should return an array with aqi data when call "get" method' do
|
29
|
-
data = obj.get
|
30
|
-
data.should be_a(Array)
|
31
|
-
data.all? {|aqi| aqi.key? 'aqi'}.should be_true
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
shared_examples "common dynamic examples" do |klass|
|
36
|
-
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
37
|
-
obj = klass.new('Shanghai')
|
38
|
-
|
39
|
-
include_examples "common examples", klass, obj
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
shared_examples "common static examples" do |klass|
|
44
|
-
ChinaAqi.token = '5j1znBVAsnSf5xQyNQyq'
|
45
|
-
obj = klass.new
|
46
|
-
|
47
|
-
include_examples "common examples", klass, obj
|
48
|
-
end
|
49
|
-
end
|