Class: Morale::Commands::Account

Inherits:
Object
  • Object
show all
Extended by:
IO
Defined in:
lib/morale/commands/account.rb

Class Method Summary collapse

Methods included from IO

ask, ask_for_secret, ask_for_secret_on_windows, echo_off, echo_on, say

Class Method Details

.list(email = "", change = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/morale/commands/account.rb', line 11

def list(email="", change=false)
  accounts = Morale::Client.accounts(email) unless email.nil? || email.empty?

  begin
    accounts = Morale::Command.client.accounts if email.nil? || email.empty?

    if !accounts.nil?
      accounts.sort{|a,b| a['account']['group_name'] <=> b['account']['group_name']}.each_with_index do |record, i|
        say "#{i += 1}. #{record['account']['group_name']}#{' *' if Morale::Account.subdomain(false) == record['account']['site_address']}"
      end
      
      if change
        say "Choose an account: "
        index = ask
         = accounts[index.to_i - 1]
        
        if .nil?
          say "Invalid account."
        end
        Morale::Account.subdomain = ['account']['site_address'] unless .nil?
      end
    else
      say "There were no accounts found."
    end
  rescue Morale::Client::Unauthorized, Morale::Client::NotFound
    say "Authentication failure"
    Morale::Commands::Authorization.
    retry if Morale::Authorization.retry_login? && !change
  end
end

.select(id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/morale/commands/account.rb', line 42

def select(id)
  begin
    accounts = Morale::Command.client.accounts
    if !accounts.nil?
       = accounts[id.to_i - 1]
      if .nil?
        say "Invalid account."
      end
      Morale::Account.subdomain = ['account']['site_address'] unless .nil?
    else
      say "There were no accounts found."
    end
  rescue Morale::Client::Unauthorized, Morale::Client::NotFound
    say "Authentication failure"
    Morale::Commands::Authorization.
  end
end