class HerokuSan::API

Public Class Methods

new(options = {}) click to toggle source
# File lib/heroku_san/api.rb, line 5
def initialize(options = {})
  @options = options
end

Public Instance Methods

method_missing(name, *args) click to toggle source
# File lib/heroku_san/api.rb, line 23
def method_missing(name, *args)
  heroku_api.send(name, *args)
rescue Heroku::API::Errors::ErrorWithResponse => error
  status = error.response.headers["Status"]
  msg = JSON.parse(error.response.body)['error'] rescue '???'
  error.set_backtrace([])
  $stderr.puts "\nHeroku API ERROR: #{status} (#{msg})\n\n"
  raise error
end
sh(app, *command) click to toggle source
# File lib/heroku_san/api.rb, line 9
def sh(app, *command)
  preflight_check_for_cli

  cmd = (command + ['--app', app, "--exit-code"]).compact

  show_command = cmd.join(' ')
  $stderr.puts show_command if @debug

  ok = Bundler.with_clean_env { system "heroku", *cmd }

  status = $?
  ok or fail "Command failed with status (#{status.exitstatus}): [heroku #{show_command}]"
end

Private Instance Methods

auth_token() click to toggle source
# File lib/heroku_san/api.rb, line 42
def auth_token
  ENV['HEROKU_API_KEY'] || Bundler.with_clean_env { `heroku auth:token`.chomp }
rescue Errno::ENOENT
  nil
end
heroku_api() click to toggle source
# File lib/heroku_san/api.rb, line 35
def heroku_api
  @heroku_api ||= begin
    @options[:api_key] ||= auth_token
    Heroku::API.new(@options)
  end
end
preflight_check_for_cli() click to toggle source
# File lib/heroku_san/api.rb, line 48
def preflight_check_for_cli
  raise "The Heroku Toolbelt is required for this action. http://toolbelt.heroku.com" if Bundler.with_clean_env { system('heroku version') == nil }
end