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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 281c9788d6683f23bc1a341af1e7521aa6f5a74d
4
- data.tar.gz: 0a566a4cfd260d9582641c9fcc4b93145edaf50e
3
+ metadata.gz: 5629478b4a11380f5cf5768d6e93381dcef35081
4
+ data.tar.gz: 73938de2bcb5dcbd52b3607f391759823dccdc6b
5
5
  SHA512:
6
- metadata.gz: bd5bf0b0d3a03a68c19fe13374d2c9cb66d57d401b1e26d23fc84af1a7ddf90fa546590b743a62dc043530d8a6b9a8f79b28ef4bbfc0f246310f451c3a41e94e
7
- data.tar.gz: b7c90e31f224fa17f05f47b57671bd7b1dcd8e2d3d6da0fffe96b91ab96ff27c5468a434c04fd0ee45c94cfbf05f1a35ad8992ffee8ed3d28e0fe5912598051c
6
+ metadata.gz: 54948bc0de829400be061cda90c2b810f87440cfb2d390dfc1188a0763186ad4744341fe6da42061f91c90399a02cda896d94b70e5532a77f1fbd5a678082ce5
7
+ data.tar.gz: 53c0da5802bc59812543ada719f660d20a47ab24e8d40eeee438fe41b6da8a936b48ac48d5f80900ba9755a4e21087af83fa0f57b10b930d139140da7fabfb43
@@ -54,6 +54,10 @@ module ChinaAqi
54
54
  #{'*' * 66}~ unless ChinaAqi.token
55
55
  @token = ChinaAqi.token
56
56
  end
57
+
58
+ def self.get(*args)
59
+ self.new(*args).get
60
+ end
57
61
  end
58
62
 
59
63
  # APIs with some parameters
@@ -14,12 +14,6 @@ module ChinaAqi
14
14
  self.base_uri = URI::HTTP.build({host: 'www.pm25.in'})
15
15
  end
16
16
 
17
- module ClassMethods
18
- def get(*args)
19
- self.new(*args).get
20
- end
21
- end
22
-
23
17
  def get
24
18
  ::ActiveSupport::JSON.decode(HTTParty.get(url).body)
25
19
  end
@@ -1,3 +1,3 @@
1
1
  module ChinaAqi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
@@ -2,5 +2,3 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
4
  require 'china_aqi'
5
-
6
- require 'china_aqi/shared_spec'
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.3
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-03 00:00:00.000000000 Z
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/aqi/dynamic_spec.rb
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/aqi/dynamic_spec.rb
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