class Forward::Command::Account
Public Instance Methods
default()
click to toggle source
# File lib/forward/command/account.rb, line 51 def default config.create_or_load subdomain = @args.first if config.accounts.empty? exit_with_message "You aren't logged into any accounts" elsif subdomain && config.accounts.has_key?(subdomain.to_sym) config.create_or_load config.set_default_account!(subdomain.to_sym) exit_with_message "#{subdomain} is now your default account" else exit_with_message "You're not logged into that account. You can login with: `forward account:login'" end rescue ConfigError => e exit_with_error(e.message) end
list()
click to toggle source
# File lib/forward/command/account.rb, line 36 def list config.create_or_load if config.accounts.empty? exit_with_message("You're not logged into any accounts. You can login with: `forward account:login'") else puts "Currently logged into:" config.accounts.keys.sort.each do |subdomain| default = config.default_account.to_sym == subdomain.to_sym puts default ? HighLine.color(" - #{subdomain} (default)", :green) : " - #{subdomain}" end exit_with_message end end
login()
click to toggle source
# File lib/forward/command/account.rb, line 4 def login config.create_or_load email = @args.first email, password = ask_for_credentials(email) logger.debug("[API] logging in user: `#{email}:#{password.gsub(/./, 'x')}'") client do API::User.authenticate(email, password) do |subdomain, token| config.add_account(subdomain, token) exit_with_message "`#{subdomain}' is now logged in and set to the default account" end end end
logout()
click to toggle source
# File lib/forward/command/account.rb, line 19 def logout config.create_or_load subdomain = @args.first if config.accounts.empty? exit_with_message "You aren't logged into any accounts" elsif subdomain config.remove_account!(subdomain) exit_with_message "You are now logged out of the '#{subdomain}' account" else message = "You must provide a subdomain to logout of an account, you're currently logged into:\n" message << config.accounts.map { |s, _| " - #{s}" }.join("\n") exit_with_message message end end