|
1 |
| -china_aqi |
2 |
| -========= |
| 1 | +# ChinaAqi |
3 | 2 |
|
4 |
| -China AQI API from PM25.in |
| 3 | +China Air Quality Index API for Rails. |
| 4 | + |
| 5 | +Thanks [pm25.in][pm25_in] for provide all the AQI sources for us as free, all the data is form China's official sector. it's a reall gread work! |
| 6 | + |
| 7 | +ChinaAqi gem provide some interface base on Ruby On Rails, before to use it, you need ask for a token form [pm25.in][pm25_in_api]. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Add this line to your application's Gemfile: |
| 12 | + |
| 13 | + gem 'china_aqi' |
| 14 | + |
| 15 | +And then execute: |
| 16 | + |
| 17 | + $ bundle |
| 18 | + |
| 19 | +Or install it yourself as: |
| 20 | + |
| 21 | + $ gem install china_aqi |
| 22 | + |
| 23 | +Run install generator: |
| 24 | + |
| 25 | + $ rails generate china_aqi:install |
| 26 | + |
| 27 | +It will create file: config/initializers/china_aqi.rb |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +As we mention at the beginning, we must get a token form [pm25.in][pm25_in_api] before we use their APIs, it's free! |
| 32 | + |
| 33 | +Once you get the token, put it in config/initializers/china_aqi.rb, then enjoy! |
| 34 | + |
| 35 | +Most AQI data are available, they are: |
| 36 | + |
| 37 | + - **co**: 一氧化碳 |
| 38 | + - **no2**: 二氧化氮 |
| 39 | + - **o3**: 臭氧 |
| 40 | + - **pm10**: 颗粒物(粒径小于等于10μm) |
| 41 | + - **pm2.5**: 颗粒物(粒径小于等于2.5μm) |
| 42 | + - **so2**: 二氧化硫 |
| 43 | + |
| 44 | +All monitoring stations in most cities of China are available. |
| 45 | + |
| 46 | +### Examples |
| 47 | + |
| 48 | + # City name can be Chinese characters, pinyin and area code |
| 49 | + # params: |
| 50 | + # avg: if true,return average for all monitoring stations, default is true |
| 51 | + # stations: if yes, return data for all monitoring stations; if no, just return average. |
| 52 | + |
| 53 | + shanghai = ChinaAqi::PM25.new('上海') # #<ChinaAqi::PM25:0x007fe2a631aef8 @city="上海" ... |
| 54 | + shanghai.get # [{"aqi"=>74, "area"=>"上海", "pm2_5"=>48 ... |
| 55 | + ChinaAqi::PM25.new('021', avg: true, stations: :yes).get # Same as above. |
| 56 | + |
| 57 | + |
| 58 | + # Get so2 data for Shanghai |
| 59 | + ChinaAqi::SO2.new('shanghai', avg: true, stations: :no).get # [{"aqi"=>74, "area"=> ... |
| 60 | + |
| 61 | + # Get all data for one stations with code "1141A" |
| 62 | + ChinaAqi::Station.new('1141A').get # [{"aqi"=>75, "area"=>"上海", "co"=>0.0, ... |
| 63 | + |
| 64 | + # Get all data that the API provide, never use it unless you have to. |
| 65 | + ChinaAqi::Global.new.get # [{"aqi"=>144, "area"=>"天津" |
| 66 | + |
| 67 | +### Helpers |
| 68 | + |
| 69 | + # get station names and station codes for one city |
| 70 | + ChinaAqi.get_stations_for_city('上海') # {"city"=>"上海", "stations"=>[{"station_name"=>"普陀" |
| 71 | + |
| 72 | +## Contributing |
| 73 | + |
| 74 | +1. Fork it |
| 75 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 76 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 77 | +4. Push to the branch (`git push origin my-new-feature`) |
| 78 | +5. Create new Pull Request |
| 79 | + |
| 80 | + |
| 81 | +[pm25_in]: http://www.pm25.in |
| 82 | +[pm25_in_api]: http://www.pm25.in/api_doc |
0 commit comments