WeatherAgent should take the Wunderground API key as an option.

Selem Delul преди 12 години
родител
ревизия
33cd371bfc
променени са 1 файла, в които са добавени 8 реда и са изтрити 3 реда
  1. 8 3
      app/models/agents/weather_agent.rb

+ 8 - 3
app/models/agents/weather_agent.rb

@@ -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