Class: Lita::Handlers::Spendo

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/spendo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#billing_historyObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/lita/handlers/spendo.rb', line 67

def billing_history
  if @billing_history.nil?
    params = {
      aws_account_id: config.,
      dynamodb_table: config.dynamodb_table
    }
    @billing_history = BillingHistory.new(params)
  end
  @billing_history
end

Instance Method Details

#show(response) ⇒ Object



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
# File 'lib/lita/handlers/spendo.rb', line 37

def show(response)
  data = billing_history.latest

            = data['Account']
  current_fees     = data['TotalFees'].to_f
  expected_fees    = data['ExpectedFees'].to_f
  alert_level      = data['AlertLevel'].to_i
  categorized_fees = data['FeesByCategory']

  message = "The current fees alert threshold has been reached.\n"
  message << "\nAccount: #{}"
  message << "\nCurrent fees: $#{current_fees}"
  message << "\nExpected monthly fees: $#{expected_fees}" # TODO
  message << "\nFee level is at #{alert_level * 25}% of expected"
  message << "\n\n Fee Category Breakdown\n\n"

  categorized_fees.each_pair do |k,v|
    value = v.to_f
    next if value == 0.0
    message << "#{k.ljust(20)}: $#{sprintf('%8.2f', value.round(2))}\n"
  end

  url = config.base_image_url + "/#{alert_level}.jpg"

  response.reply message
  response.reply url
end