A Grape/Goliath API for tracking votes. With simple math captcha!
- Vote is created.
- API asks a simple math question (What's 2+2?).
- If user answers correctly. Vote is counted in poll.
Very simple rate limiting by IP address.
See a live demo: Mathy-Poll on Heroku
Screenshot:
Clone the repo:
git clone https://github.com/mscoutermarsh/Mathy-Poll.git
cd Mathy-Poll
Install gems:
bundle install
Setup the database:
rake db:setup
Start the server!
ruby server.rb -vs
Deploy to Heroku:
Create a new app.
heroku apps:create APPNAMEHERE
Run migrations
heroku run rake db:migrate RACK_ENV=production
Check out your new poll on heroku!
yourappname.herokuapp.com
http POST 0.0.0.0:9000/vote/1
This will return the vote id and the math question:
{
"id": 7,
"question": "What's 13+3?"
}
Now to confirm your vote... answer the question by POSTing to /vote/confirm/:id/:answer.
http POST 0.0.0.0:9000/vote/confirm/7/16
If your math is correct, the vote will be confirmed.
{
"message": "Thanks for voting!"
}
To see how many votes there are for contestant #1.
http GET 0.0.0.0:9000/votes/1
And it will return:
{
"votes": 4
}
Goliath/Grape handles high loads really well. This has been tested at 200-300 requests per second on a single Heroku dyno.
1 Dyno:
Transactions: 12715 hits
Availability: 99.99 %
Elapsed time: 59.85 secs
Data transferred: 0.13 MB
Response time: 0.44 secs
Transaction rate: 212.45 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 94.16
Successful transactions: 12715
Failed transactions: 1
Longest transaction: 11.56
Shortest transaction: 0.08
- Twitter @mscccc
- mikecoutermarsh.com
- Based off of: Grape-Goliath-Example