Class: ChinaAqi::Base
Overview
Fetch data with different method
Pass city name and params those API accept.
shanghai = ChinaAqi::PM25.new('city_name', params = { avg: true/false, stations: :yes/:no })
shanghai.get
this is same as:
ChinaAqi::PM25.get('city_name', params = { avg: true/false, stations: :yes/:no })
params:
avg: if true,return average for all monitoring stations, default is true
stations: if yes, return data for all monitoring stations; if no, just return average.
checkout explanation in http://www.pm25.in/api_doc
examples
shanghai = ChinaAqi::PM25.new('上海') # #<ChinaAqi::PM25:0x007fe2a631aef8 @city="上海"...
shanghai.get # [{"aqi"=>74, "area"=>"上海", "pm2_5"=>48,...
ChinaAqi::PM25.get('shanghai') # Same as above
# Get so2 data for 上海
ChinaAqi::SO2.new('上海', avg: false, stations: :no).get # [{"aqi"=>74, "area"=>"上海", "pm2_5"=>48,...
# Get all data for one stations with code "1141A"
ChinaAqi::Station.new('1141A').get # [{"aqi"=>75, "area"=>"上海", "co"=>0.0, "co_24h"=>0.0
# Get all data that the API provide
ChinaAqi::Global.new.get
Direct Known Subclasses
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
Methods included from Utility
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/china_aqi/base.rb', line 40 def initialize(*args) raise TokenMissingError, %~ #{'*' * 66} Token is missing! Set token as below: ChinaAqi.token = "you_token" If you use it under Rails, set token as normal rails configuration: # config/application.rb config.china_aqi_token = "you_token" #{'*' * 66}~ unless ChinaAqi.token @token = ChinaAqi.token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
38 39 40 |
# File 'lib/china_aqi/base.rb', line 38 def token @token end |