Permalink
Browse files

Get the API key from Heroku

  • Loading branch information...
1 parent 91e4117 commit c8b92a794af146e59137a2611cbe7711f31fc544 @jyurek jyurek committed Oct 25, 2010
Showing with 22 additions and 1 deletion.
  1. +1 −1 lib/hoptoad_notifier/version.rb
  2. +21 −0 lib/rails/generators/hoptoad/hoptoad_generator.rb
@@ -1,3 +1,3 @@
module HoptoadNotifier
- VERSION = "2.3.10".freeze
+ VERSION = "2.3.11".freeze
end
@@ -14,6 +14,7 @@ def install
ensure_plugin_is_not_present
append_capistrano_hook
generate_initializer unless api_key_configured?
+ determine_api_key if heroku?
test_hoptoad
end
@@ -55,6 +56,26 @@ def generate_initializer
template 'initializer.rb', 'config/initializers/hoptoad.rb'
end
+ def determine_api_key
+ puts "Attempting to determine your API Key from Heroku..."
+ ENV['HOPTOAD_API_KEY'] = `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
+ if ENV['HOPTOAD_API_KEY'].blank?
+ puts "... Failed."
+ puts "WARNING: We were unable to detect the Hoptoad API Key from your Heroku environment."
+ puts "Your Heroku application environment may not be configured correctly."
+ exit 1
+ else
+ puts "... Done."
+ puts "Heroku's Hoptoad API Key is '#{ENV['HOPTOAD_API_KEY']}'"
+ end
+ end
+
+ def heroku?
+ options[:heroku] ||
+ system("grep HOPTOAD_API_KEY config/initializers/hoptoad.rb") ||
+ system("grep HOPTOAD_API_KEY config/environment.rb")
+ end
+
def api_key_configured?
File.exists?('config/initializers/hoptoad.rb')
end

0 comments on commit c8b92a7

Please sign in to comment.