Skip to content

Instantly share code, notes, and snippets.

@ismailmechbal
Forked from VanessaHenderson/mandrill.rb
Created January 17, 2016 21:22
Show Gist options
  • Save ismailmechbal/c2cbf10ae1b106092148 to your computer and use it in GitHub Desktop.
Save ismailmechbal/c2cbf10ae1b106092148 to your computer and use it in GitHub Desktop.

This is a widget that will get the number of mandrill mail sent today and the number sent yesterday is stored. The first iteration will not show the previous days mail count.

This widget requires a Mandrill API key. It should be put in mandrill.rb in place of 'YOUR_API_KEY'

To display it on your dashboard use the following code

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="mandrilltodaysent" data-view="Number" data-title="Emails Sent Today"></div>
</li>

The Number widget provided by Dashing is used to display the widget.

require 'mandrill'
require 'json'
mandrill = Mandrill::API.new 'YOUR_API_KEY'
yesterday_number = 0
todays_number = 0
clock = Time.new
day = clock.day
SCHEDULER.every '15m', :first_in => 0 do |job|
if day != clock.day
#Checks to see if the day has rolled over
yesterday_number= todays_number
end
result = mandrill.users.info
todays_number = result["stats"]["today"]["sent"]
send_event('mandrilltodaysent', { current: todays_number, last: yesterday_number })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment