Last active
December 17, 2015 19:09
-
-
Save crtr0/5657876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twilio-ruby' | |
require './creds' | |
# initialize Twilio client | |
client = Twilio::REST::Client.new(Creds.ACCOUNT_SID, Creds.AUTH_TOKEN) | |
# groups all phone numbers based on number of correct answers to trivia questions | |
pool = [ | |
[3, ["a", "b", "c"]], | |
[2, ["d", "e", "f"]], | |
[1, ["g", "h", "i"]], | |
[0, ["j", "k", "l"]]] | |
# this will be a flat array of phone numbers | |
lottery = [] | |
pool.each do |row| | |
factor = row[0] + 1 | |
row[1].each do |phonenumber| | |
# the more answers you got right, the more times your number appears in the flat array | |
lottery += [phonenumber]*factor | |
end | |
end | |
winner = lottery.sample | |
client.account.sms.messages.create(from: "xxx", to: winner, body: "You're the winner!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment