Skip to content

Commit

Permalink
Merge pull request huginn#23 from cantino/check_key
Browse files Browse the repository at this point in the history
Add some sanity checks to the WeatherAgent
  • Loading branch information
cantino committed Mar 24, 2013
2 parents 06deb20 + 4ac5001 commit 8726a9a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/models/agents/weather_agent.rb
Expand Up @@ -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
Expand Down

0 comments on commit 8726a9a

Please sign in to comment.