diff --git a/app/models/ruling_weather_setting.rb b/app/models/ruling_weather_setting.rb index 15dbe7e..3975bb0 100644 --- a/app/models/ruling_weather_setting.rb +++ b/app/models/ruling_weather_setting.rb @@ -4,7 +4,7 @@ class RulingWeatherSetting include Mongoid::Document include Mongoid::Timestamps - weather_api_url = "https://opendata.cwa.gov.tw".freeze + WEATHER_API_URL = "https://opendata.cwa.gov.tw".freeze field :time_offset, type: String, default: "+8" field :location, type: String, default: "" @@ -41,7 +41,7 @@ class RulingWeatherSetting time_now = DateTime.now.new_offset(self.time_offset) today = time_now.strftime("%Y-%m-%d") custom_dataid = custom_dataid || self.dataid - url = "#{weather_api_url}/api/v1/rest/datastore/#{custom_dataid}.json" + url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json" startt = "#{today}T00:00:00" endt = "#{today}T23:59:59" custom_location = custom_location || self.location @@ -113,7 +113,7 @@ class RulingWeatherSetting if timeout_flag rain = cache["rain"].to_f rescue 0.0 else - url2 = "#{weather_api_url}/api/v1/rest/datastore/O-A0002-001.json" + url2 = "#{WEATHER_API_URL}/api/v1/rest/datastore/O-A0002-001.json" begin res2 = net_http_get_response(URI.parse("#{url2}?#{data2.to_query}")) content2 = JSON.parse(res2.body) @@ -150,7 +150,7 @@ class RulingWeatherSetting time_now = DateTime.now.utc.new_offset(self.time_offset) today = time_now.strftime("%Y-%m-%d") custom_dataid = custom_dataid || self.dataid - url = "#{weather_api_url}/api/v1/rest/datastore/#{custom_dataid}.json" + url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json" startt = "#{today}T00:00:00" endt = "#{today}T23:59:59" custom_location = custom_location || self.location