Class: Cumulus::CLI

Inherits:
Thor
  • Object
show all
Includes:
Cloudability
Defined in:
lib/cumulus.rb

Instance Method Summary collapse

Instance Method Details

#billingObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cumulus.rb', line 46

def billing
  c = Client.new(auth_token: token)
  count = options[:count] || 10
  by = options[:by] || 'period'

  if options[:period]
    reports = c.billing_report(by: by, period: options[:period])
  else
    reports = c.billing_report(by: by)
  end

  reports = reports[0..count].reverse

  reports.sort_by!{ |r| r.spend }.reverse! # sort by spend
  rows = []

  reports.each do |report|
    dimention = dimention_to_attribute(by)
    rows << [report[dimention], '$' + number_with_delimiter(report.spend).to_s]
  end

  puts Terminal::Table.new(headings: [by.capitalize, 'Spend'], rows: rows)
end

#budgetsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cumulus.rb', line 13

def budgets
  budgets = Client.new(auth_token: token).budgets

  budgets.select!{|b| b.type.downcase == options[:type] } if options[:type]

  rows = []
  budgets.each do |budget|
    if budget.is_active
      rows << [c_to_d(budget.predicted_monthly_spend.cents),
        '$' + number_with_delimiter(budget.threshold.to_i).to_s,
        budget.type, budget.subject]
    end
  end

  puts Terminal::Table.new(headings: ['Predicted spend', 'Budget threshold', 'Type', 'Subject'], rows: rows)
end

#credentialsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/cumulus.rb', line 31

def credentials
  credentials = Client.new(auth_token: token).credentials
  rows = []

  credentials.each do |cred|
    rows << [cred.vendor_key, cred.nickname]
  end

  puts Terminal::Table.new(headings: ['Vendor key', 'Nickname'], rows: rows)
end

#invitesObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cumulus.rb', line 73

def invites
  invites = Client.new(auth_token: token).organization_invitations

  invites.select!{|i| i.organization_role.label.downcase == options[:role] } if options[:role]
  invites.select!{|i| i.state.downcase == options[:state] } if options[:state]

  rows = []
  invites.each do |invite|
    rows << [invite.user.full_name, invite.user.email, invite.organization_role.label, invite.state]
  end

  puts Terminal::Table.new(headings: ['Name', 'Email', 'Role', 'State'], rows: rows)
end

#set_tokenObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cumulus.rb', line 89

def set_token
  n = Netrc.read

  if options[:token]
    n.new_item_prefix = "# Added by the Cumulus gem\n"
    n["app.cloudability.com"] = options[:token], options[:token]
    n.save
    puts "Your token has been saved."
  else
    puts "Please enter your Cloudability API token and hit enter: "
    token = STDIN.gets.chomp
    n.new_item_prefix = "# Added by the Cumulus gem\n"
    n["app.cloudability.com"] = token, token
    n.save
    puts "Your token has been saved."
  end
end