module SmartWeather
Constants
- VERSION
Attributes
app_id[RW]
private_key[RW]
Public Class Methods
format_weather_result(response, api_url, options = {})
click to toggle source
# File lib/smart_weather.rb, line 42 def format_weather_result response, api_url, options = {} begin Oj.load(response) rescue write_log(response, api_url, options) end end
generate_key(areaid, type, date)
click to toggle source
# File lib/smart_weather.rb, line 50 def generate_key areaid, type, date public_key = base_url + "areaid=#{areaid}&type=#{type}&date=#{date}&appid=#{@app_id}" CGI::escape(Base64.strict_encode64(OpenSSL::HMAC.digest('sha1', @private_key, public_key))) end
get_forecast(options = {})
click to toggle source
# File lib/smart_weather.rb, line 22 def get_forecast options = {} get_weather(areaid: options[:areaid], type: 'forecast3d') end
get_index(options = {})
click to toggle source
# File lib/smart_weather.rb, line 26 def get_index options = {} get_weather(areaid: options[:areaid], type: 'index') end
get_observe(options = {})
click to toggle source
# File lib/smart_weather.rb, line 18 def get_observe options = {} get_weather(areaid: options[:areaid], type: 'observe') end
get_weather(options = {})
click to toggle source
# File lib/smart_weather.rb, line 30 def get_weather options = {} areaid = options[:areaid] type = options[:type] date = Time.now.strftime("%Y%m%d%H%M") key = generate_key(areaid, type, date) url = "areaid=#{areaid}&type=#{type}&date=#{date}&appid=#{@app_id[0, 6]}&key=#{key}" res = self.get(url) format_weather_result(res, url, options) end