Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check if the key is setup

  • Loading branch information...
commit 994a2e4dfe6a8eafe26c2bf4d646220c3df688a1 1 parent 15b03fc
@cantino authored
Showing with 12 additions and 6 deletions.
  1. +12 −6 app/models/agents/weather_agent.rb
View
18 app/models/agents/weather_agent.rb
@@ -44,12 +44,16 @@ 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"
}
@@ -57,13 +61,15 @@ def default_options
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
Please sign in to comment.
Something went wrong with that request. Please try again.