Class: Pod::Command::Trunk::Me

Inherits:
Pod::Command::Trunk show all
Defined in:
lib/pod/command/trunk/me.rb

Direct Known Subclasses

CleanSessions

Defined Under Namespace

Classes: CleanSessions

Constant Summary

Constants inherited from Pod::Command::Trunk

BASE_URL, SCHEME_AND_HOST

Instance Method Summary collapse

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pod/command/trunk/me.rb', line 23

def run
  me = json(request_path(:get, 'sessions', auth_headers))
  owner = json(request_path(:get, "owners/#{me['email']}"))
  UI.labeled 'Name', owner['name']
  UI.labeled 'Email', owner['email']
  UI.labeled 'Since', formatted_time(owner['created_at'])

  pods = owner['pods'] || []
  pods = pods.map { |pod| pod['name'] }
  pods = 'None' unless pods.any?
  UI.labeled 'Pods', pods

  sessions = me['sessions'].map do |session|
    hash = {
      :created_at => formatted_time(session['created_at']),
      :valid_until => formatted_time(session['valid_until']),
      :created_from_ip => session['created_from_ip'],
      :description => session['description'],
    }
    if Time.parse(session['valid_until']) <= Time.now.utc
      hash[:color] = :red
    elsif session['verified']
      hash[:color] = session['current'] ? :cyan : :green
    else
      hash[:color] = :yellow
      hash[:valid_until] = 'Unverified'
    end
    hash
  end

  columns = [:created_at, :valid_until, :created_from_ip, :description].map do |key|
    find_max_size(sessions, key)
  end

  sessions = sessions.map do |session|
    created_at      = session[:created_at].ljust(columns[0])
    valid_until     = session[:valid_until].rjust(columns[1])
    created_from_ip = session[:created_from_ip].ljust(columns[2])
    description     = session[:description]
    msg = "#{created_at} - #{valid_until}. IP: #{created_from_ip}"
    msg << " Description: #{description}" if description
    msg.send(session[:color])
  end

  UI.labeled 'Sessions', sessions

rescue REST::Error => e
  raise Informative, 'There was an error fetching your info ' \
                           "from trunk: #{e.message}"
end

#validate!Object



16
17
18
19
20
21
# File 'lib/pod/command/trunk/me.rb', line 16

def validate!
  super
  unless token
    help! 'You need to register a session first.'
  end
end