Skip to content

Commit

Permalink
Get the API key from Heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Oct 25, 2010
1 parent 91e4117 commit c8b92a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hoptoad_notifier/version.rb
@@ -1,3 +1,3 @@
module HoptoadNotifier module HoptoadNotifier
VERSION = "2.3.10".freeze VERSION = "2.3.11".freeze
end end
21 changes: 21 additions & 0 deletions lib/rails/generators/hoptoad/hoptoad_generator.rb
Expand Up @@ -14,6 +14,7 @@ def install
ensure_plugin_is_not_present ensure_plugin_is_not_present
append_capistrano_hook append_capistrano_hook
generate_initializer unless api_key_configured? generate_initializer unless api_key_configured?
determine_api_key if heroku?
test_hoptoad test_hoptoad
end end


Expand Down Expand Up @@ -55,6 +56,26 @@ def generate_initializer
template 'initializer.rb', 'config/initializers/hoptoad.rb' template 'initializer.rb', 'config/initializers/hoptoad.rb'
end 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? def api_key_configured?
File.exists?('config/initializers/hoptoad.rb') File.exists?('config/initializers/hoptoad.rb')
end end
Expand Down

0 comments on commit c8b92a7

Please sign in to comment.