Skip to content

Commit

Permalink
Merge pull request #20 from necrodome/master
Browse files Browse the repository at this point in the history
WeatherAgent should take the Wunderground API key as an option
  • Loading branch information
cantino committed Mar 22, 2013
2 parents 1b81a4d + 38ac850 commit 15b03fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/models/agents/weather_agent.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions spec/fixtures/agents.yml
Expand Up @@ -37,6 +37,7 @@ bob_weather_agent:
:zipcode => 94102,
:lat => 37.779329,
:lng => -122.41915,
:api_key => 'test'
}.to_yaml.inspect %>

jane_weather_agent:
Expand All @@ -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:
Expand Down

0 comments on commit 15b03fc

Please sign in to comment.