From 005be58d30181b1e0ca5b29cc9a8729ee0d7bcab Mon Sep 17 00:00:00 2001 From: Andrew Cantino Date: Sun, 9 Oct 2016 10:49:12 -0400 Subject: [PATCH] Update forecast_io gem and language (#1722) --- Gemfile.lock | 8 ++++---- app/models/agents/weather_agent.rb | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f7b69a29b1..360822685b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -212,7 +212,7 @@ GEM oauth (>= 0.4.1) execjs (2.6.0) extlib (0.9.16) - faraday (0.9.1) + faraday (0.9.2) multipart-post (>= 1.2, < 3) feedjira (2.0.0) faraday (~> 0.9) @@ -222,7 +222,7 @@ GEM ffi (1.9.10) font-awesome-sass (4.3.2.1) sass (~> 3.2) - forecast_io (2.0.0) + forecast_io (2.0.1) faraday hashie multi_json @@ -267,7 +267,7 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - hashie (3.4.4) + hashie (3.4.6) haversine (0.3.0) hipchat (1.2.0) httparty @@ -705,4 +705,4 @@ RUBY VERSION ruby 2.3.1p112 BUNDLED WITH - 1.12.5 + 1.13.2 diff --git a/app/models/agents/weather_agent.rb b/app/models/agents/weather_agent.rb index aaff8b2c53..5764d45401 100644 --- a/app/models/agents/weather_agent.rb +++ b/app/models/agents/weather_agent.rb @@ -14,15 +14,16 @@ class WeatherAgent < Agent You also must select `which_day` you would like to get the weather for where the number 0 is for today and 1 is for tomorrow and so on. Weather is only returned for 1 week at a time. - The weather can be provided by either Wunderground or ForecastIO. To choose which `service` to use, enter either `forecastio` or `wunderground`. + The weather can be provided by either Wunderground or Dark Sky. To choose which `service` to use, enter either `darksky` or `wunderground`. - The `location` can be a US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively. + The `location` should be: - If you plan on using ForecastIO, the `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`. + * For Wunderground: A US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively. + * For Dark Sky: `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`. You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent with Wunderground. - You must setup an [API key for Forecast](https://developer.forecast.io/) in order to use this Agent with ForecastIO. + You must setup an [API key for Dark Sky](https://darksky.net/dev/) in order to use this Agent with Dark Sky. Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent. @@ -100,7 +101,7 @@ def language end def validate_options - errors.add(:base, "service must be set to 'forecastio' or 'wunderground'") unless ["forecastio", "wunderground"].include?(weather_provider) + errors.add(:base, "service must be set to 'darksky' or 'wunderground'") unless %w[darksky forecastio wunderground].include?(weather_provider) errors.add(:base, "location is required") unless location.present? errors.add(:base, "api_key is required") unless interpolated['api_key'].present? errors.add(:base, "which_day selection is required") unless which_day.present? @@ -116,7 +117,7 @@ def wunderground end end - def forecastio + def dark_sky if key_setup? ForecastIO.api_key = interpolated['api_key'] lat, lng = location.split(',') @@ -127,8 +128,8 @@ def forecastio def model(weather_provider,which_day) if weather_provider == "wunderground" wunderground[which_day] - elsif weather_provider == "forecastio" - forecastio.each do |value| + elsif weather_provider == "darksky" || weather_provider == "forecastio" + dark_sky.each do |value| timestamp = Time.at(value.time) if (timestamp.to_date - Time.now.to_date).to_i == which_day day = {