Module: SmartWeather
- Includes:
- RestclientApiBase
- Defined in:
- lib/smart_weather.rb,
lib/smart_weather/data.rb,
lib/smart_weather/version.rb
Defined Under Namespace
Modules: City, ClassMethods, Province
Constant Summary
collapse
- VERSION =
"0.0.1"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.app_id ⇒ Object
Returns the value of attribute app_id.
16
17
18
|
# File 'lib/smart_weather.rb', line 16
def app_id
@app_id
end
|
.private_key ⇒ Object
Returns the value of attribute private_key.
16
17
18
|
# File 'lib/smart_weather.rb', line 16
def private_key
@private_key
end
|
Class Method Details
42
43
44
45
46
47
48
|
# 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) ⇒ Object
50
51
52
53
|
# 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 = {}) ⇒ Object
22
23
24
|
# File 'lib/smart_weather.rb', line 22
def get_forecast options = {}
get_weather(areaid: options[:areaid], type: 'forecast3d')
end
|
.get_index(options = {}) ⇒ Object
26
27
28
|
# File 'lib/smart_weather.rb', line 26
def get_index options = {}
get_weather(areaid: options[:areaid], type: 'index')
end
|
.get_observe(options = {}) ⇒ Object
18
19
20
|
# File 'lib/smart_weather.rb', line 18
def get_observe options = {}
get_weather(areaid: options[:areaid], type: 'observe')
end
|
.get_weather(options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# 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
|