Skip to content

Instantly share code, notes, and snippets.

@crtr0
Last active December 17, 2015 19:09
Show Gist options
  • Save crtr0/5657876 to your computer and use it in GitHub Desktop.
Save crtr0/5657876 to your computer and use it in GitHub Desktop.
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