Class: Cumulus::CLI
Instance Method Summary collapse
Instance Method Details
#billing ⇒ Object
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 = [:count] || 10 by = [:by] || 'period' if [:period] reports = c.billing_report(by: by, period: [: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 |
#budgets ⇒ Object
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 == [:type] } if [: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 |
#credentials ⇒ Object
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 |
#invites ⇒ Object
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 == [:role] } if [:role] invites.select!{|i| i.state.downcase == [:state] } if [: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_token ⇒ Object
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 [:token] n.new_item_prefix = "# Added by the Cumulus gem\n" n["app.cloudability.com"] = [:token], [: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 |