Class: HerokuSan::API
- Inherits:
-
Object
- Object
- HerokuSan::API
- Defined in:
- lib/heroku_san/api.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #method_missing(name, *args) ⇒ Object
- #sh(app, *command) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
5 6 7 8 9 |
# File 'lib/heroku_san/api.rb', line 5 def initialize( = {}) = [:api_key] ||= auth_token @heroku_api = Heroku::API.new() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/heroku_san/api.rb', line 25 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 |
Instance Method Details
#sh(app, *command) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/heroku_san/api.rb', line 11 def sh(app, *command) preflight_check_for_cli cmd = (command + ['--app', app]).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 |