lib/ruboty/rainfall_jp.rb in ruboty-rainfall_jp-1.2.0 vs lib/ruboty/rainfall_jp.rb in ruboty-rainfall_jp-1.3.0
- old
+ new
@@ -18,36 +18,36 @@
if YAHOO_JAPAN_APP_ID.nil?
raise "ENV['YAHOO_JAPAN_APP_ID'] is required for this command"
end
query = message.match_data['query'] || DEFAULT_LOCATION
- geometry = fetch_coodinated_geometry(query)
+ name, geometry = fetch_location_name_and_coodinated_geometry(query)
if geometry.nil?
message.reply('ಠ_ಠ')
message.reply("Location '#{query}' is not found.")
return
end
result = fetch_rainfall(geometry)
- message.reply("Rainfall forecast: #{query} (l/l: #{geometry})")
+ message.reply("Rainfall forecast: #{name} (l/l: #{geometry})")
message.reply(result)
rescue Exception => e
message.reply('ಠ_ಠ')
message.reply(e)
message.reply(e.backtrace)
end
private
- def fetch_coodinated_geometry(query)
+ def fetch_location_name_and_coodinated_geometry(query)
url = "http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder?appid=#{YAHOO_JAPAN_APP_ID}&output=json&query=#{CGI.escape(query)}"
response = JSON.parse(open(url).read)
features = response["Feature"]
if features.nil? || features.first.nil?
return nil
end
- features.first["Geometry"]["Coordinates"]
+ [features.first["Name"], features.first["Geometry"]["Coordinates"]]
end
def fetch_rainfall(geometry)
url = "http://weather.olp.yahooapis.jp/v1/place\?appid\=#{YAHOO_JAPAN_APP_ID}\&output=json&coordinates\=#{geometry}"
response = JSON.parse(open(url).read)