class Mocloud::Commands::Login
Public Instance Methods
description()
click to toggle source
# File lib/mocloud/commands/login.rb, line 14 def description "Log in to Mobingi" end
run()
click to toggle source
# File lib/mocloud/commands/login.rb, line 18 def run opts = Trollop::options do banner <<-ENDOFHELP Usage: mobingi login [options]" Login to your Mobingi account. You need to login to be able to create, delete, inspect and modify your stacks. ENDOFHELP opt :endpoint, "Set API Endpoint", :default => "api.mobingi.com" end print "Username (email): " username = STDIN.gets.chomp password = Mocloud::Utils.get_password puts "" api = Mocloud::API.new res = api.get_unauthed(opts[:endpoint], "/v1/login", :username => username, :password => password) Mocloud::Utils.handle_error(res, "Login failed") puts "Successfully logged in!" creds = Mocloud::Utils::Credentials.new userinfo = JSON.parse(res[:body]) userinfo["username"] = username userinfo["endpoint"] = opts[:endpoint] creds.write_credentials(userinfo) end