Generate custom progress meters for ActionKit pages with Sinatra + IMGKit
This app generates progress meters via a customized HTML template, converts them to .png files, and uploads these files to Amazon S3.
Every time a progress meter is requested, the app will immediately redirect to a page's most recently archived S3 image, and if necessary, update the image via a background process.
The URL of the progress meter image for any given ActionKit page includes an MD5 hash of the page's ID & created_at timestamp, and a secret salt. This prevents anyone with an internet connection from easily determining the number of actions or donation totals for any ActionKit page hosted by your organization.
- ruby
- sinatra
- wkhtmltoimage
- Amazon S3
$ gem install imgkit
$ sudo imgkit --install-wkhtmltoimage
$ bundle install
# replace the example MySQL credentials in the .env file with your ActionKit MySQL credentials:
$ mv .env.example .env
$ ruby app.rb
$ heroku apps create
$ git push heroku master
# set up your MySQL connection, S3 credentials and other environment variables, if you're not checking the .env file into version control:
$ heroku config:set USERNAME='username' PASSWORD='password' HOST='example.client-db.actionkit.com' DATABASE='ak_example' ACCESS_KEY_ID='s3_access_key' SECRET_ACCESS_KEY='secret_access_key' BUCKET_NAME='actionkit-progress-meter.example.com' PROVIDER='AWS'
page_id
is the page_id of the ActionKit page to pull progress from.
md5_hash
is the string returned by Digest::MD5.new.update("#{ENV['SALT']}#{@results['created_at']}#{@sanitized_page_id}").to_s
goal_type
is the type of goal ("actions" or "dollars").
goal
is the numerical goal for the page.
To quickly look up the URL of a page's progress meter with the valid MD5 hash, simply visit http://actionkit-progress-meter.herokuapp.com/lookup (Password-protected via Basic HTTP Authentication. Credentials may be set by editing the .env file.)