Class: WebGit::Heroku

Inherits:
Object
  • Object
show all
Defined in:
lib/web_git/heroku.rb

Class Method Summary collapse

Class Method Details

.authenticate(email, password) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/web_git/heroku.rb', line 6

def self.authenticate(email, password)
  raise ArgumentError.new("Email and password cannot be blank.") if email.blank? || password.blank?
  script = File.join( File.dirname(__FILE__), '/../scripts/heroku_login.exp')

  command = "#{script} #{email} #{password}"
  rout, wout = IO.pipe
  pid = Process.spawn(command, :out => wout)

  begin
    status = Timeout.timeout(30) do
      _, status = Process.wait2(pid)
      wout.close
    end
    stdout = rout.readlines.join("\n")
    rout.close
    message = stdout.match(/Error.*\./).to_s
    raise WebGit::AuthenticationError.new(message) if stdout.include?("Error")

  rescue Timeout::Error
    Process.kill('TERM', script_pid)
    raise Timeout::Error.new("Sign in took longer than 30 seconds.")
  end
end

.whoamiObject



30
31
32
# File 'lib/web_git/heroku.rb', line 30

def self.whoami
  `heroku whoami`.chomp
end