Merge pull request #20 from necrodome/master

WeatherAgent should take the Wunderground API key as an option

Andrew Cantino 12 years ago
parent
commit
15b03fc40c
2 changed files with 11 additions and 4 deletions
  1. 9 4
      app/models/agents/weather_agent.rb
  2. 2 0
      spec/fixtures/agents.yml

+ 9 - 4
app/models/agents/weather_agent.rb

@@ -7,7 +7,7 @@ module Agents
7 7
     description <<-MD
8 8
       The WeatherAgent creates an event for the following day's weather at `zipcode`.
9 9
 
10
-      You must setup an API key for Wunderground in order to use this Agent.
10
+      You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent.
11 11
     MD
12 12
 
13 13
     event_description <<-MD
@@ -44,15 +44,20 @@ module Agents
44 44
     end
45 45
 
46 46
     def wunderground
47
-      Wunderground.new("your-api-key")
47
+      Wunderground.new(options[:api_key])
48 48
     end
49 49
 
50 50
     def default_options
51
-      { :zipcode => "94103" }
51
+      {
52
+        :api_key => "",
53
+        :zipcode => "94103"
54
+      }
55
+
52 56
     end
53 57
 
54 58
     def validate_options
55 59
       errors.add(:base, "zipcode is required") unless options[:zipcode].present?
60
+      errors.add(:base, "api_key is required") unless options[:api_key].present?
56 61
     end
57 62
 
58 63
     def check
@@ -67,4 +72,4 @@ module Agents
67 72
       Time.zone.at(day["date"]["epoch"].to_i).to_date == Time.zone.now.tomorrow.to_date
68 73
     end
69 74
   end
70
-end
75
+end

+ 2 - 0
spec/fixtures/agents.yml

@@ -37,6 +37,7 @@ bob_weather_agent:
37 37
                  :zipcode => 94102,
38 38
                  :lat => 37.779329,
39 39
                  :lng => -122.41915,
40
+                 :api_key => 'test'
40 41
                }.to_yaml.inspect %>
41 42
 
42 43
 jane_weather_agent:
@@ -48,6 +49,7 @@ jane_weather_agent:
48 49
                  :zipcode => 94103,
49 50
                  :lat => 37.779329,
50 51
                  :lng => -122.41915,
52
+                 :api_key => 'test'
51 53
                }.to_yaml.inspect %>
52 54
 
53 55
 jane_rain_notifier_agent: