Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #20 from necrodome/master

WeatherAgent should take the Wunderground API key as an option
  • Loading branch information...
commit 15b03fc40ca420fcc3f3b9dd1f341d6493d5bca4 2 parents 1b81a4d + 38ac850
@cantino authored
Showing with 11 additions and 4 deletions.
  1. +9 −4 app/models/agents/weather_agent.rb
  2. +2 −0  spec/fixtures/agents.yml
View
13 app/models/agents/weather_agent.rb
@@ -7,7 +7,7 @@ class WeatherAgent < Agent
description <<-MD
The WeatherAgent creates an event for the following day's weather at `zipcode`.
- You must setup an API key for Wunderground in order to use this Agent.
+ You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent.
MD
event_description <<-MD
@@ -44,15 +44,20 @@ def working?
end
def wunderground
- Wunderground.new("your-api-key")
+ Wunderground.new(options[:api_key])
end
def default_options
- { :zipcode => "94103" }
+ {
+ :api_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?
end
def check
@@ -67,4 +72,4 @@ def is_tomorrow?(day)
Time.zone.at(day["date"]["epoch"].to_i).to_date == Time.zone.now.tomorrow.to_date
end
end
-end
+end
View
2  spec/fixtures/agents.yml
@@ -37,6 +37,7 @@ bob_weather_agent:
:zipcode => 94102,
:lat => 37.779329,
:lng => -122.41915,
+ :api_key => 'test'
}.to_yaml.inspect %>
jane_weather_agent:
@@ -48,6 +49,7 @@ jane_weather_agent:
:zipcode => 94103,
:lat => 37.779329,
:lng => -122.41915,
+ :api_key => 'test'
}.to_yaml.inspect %>
jane_rain_notifier_agent:
Please sign in to comment.
Something went wrong with that request. Please try again.