Permalink
Browse files

Merge pull request #23 from cantino/check_key

Add some sanity checks to the WeatherAgent
  • Loading branch information...
2 parents 15b03fc + 994a2e4 commit 9c827a5e0c6583e9befbe016f906d1889bd9834d @cantino committed Mar 24, 2013
Showing with 12 additions and 6 deletions.
  1. +12 −6 app/models/agents/weather_agent.rb
@@ -44,26 +44,32 @@ def working?
end
def wunderground
- Wunderground.new(options[:api_key])
+ Wunderground.new(options[:api_key]) if key_setup?
+ end
+
+ def key_setup?
+ options[:api_key] && options[:api_key] != "your-key"
end
def default_options
{
- :api_key => "",
+ :api_key => "your-key",
:zipcode => "94103"
}
end
def validate_options
errors.add(:base, "zipcode is required") unless options[:zipcode].present?
- errors.add(:base, "api_key is required") unless options[:api_key].present?
+ errors.add(:base, "api_key is required") unless key_setup?
end
def check
- wunderground.forecast_for(options[:zipcode])["forecast"]["simpleforecast"]["forecastday"].each do |day|
- if is_tomorrow?(day)
- create_event :payload => day.merge(:zipcode => options[:zipcode])
+ if key_setup?
+ wunderground.forecast_for(options[:zipcode])["forecast"]["simpleforecast"]["forecastday"].each do |day|
+ if is_tomorrow?(day)
+ create_event :payload => day.merge(:zipcode => options[:zipcode])
+ end
end
end
end

0 comments on commit 9c827a5

Please sign in to comment.