Created
September 26, 2013 15:55
-
-
Save blairanderson/6716184 to your computer and use it in GitHub Desktop.
@quickleft #hackfest code for MakeyMakey to Twilio
This file contains 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
# encoding: utf-8 | |
require 'rubygems' # not necessary with ruby 1.9 but included for completeness | |
require 'twilio-ruby' | |
# put your own credentials here | |
account_sid = 'ABCABCABCABCABCABCABCABCABCABCABC'#GET YOUR OWN TOKENS FROM TWILIO | |
auth_token = 'ABCABCABCABCABCABCABCABCABCABCABC' #GET YOUR OWN TOKENS FROM TWILIO | |
# set up a client to talk to the Twilio REST API | |
@client = Twilio::REST::Client.new account_sid, auth_token | |
def text(message = 'BOOM') | |
@client.account.messages.create( | |
:from => '+18885551212', #GET YOUR OWN NUMBER FROM TWILIO | |
:to => '+13335251234', #VERIFY YOUR PHONE NUMBER TO TWILIO | |
:body => message) | |
end | |
@previous_level = :empty | |
def handle_input(input) | |
if @previous_level == input | |
else | |
@previous_level = input | |
new_input(input) | |
end | |
end | |
def new_input(input) | |
case input | |
when 'w' | |
text('The glass is full!') | |
when 's' | |
text('The glass is half full') | |
when 'a' | |
text('The glass is almost empty') | |
else | |
text("some DIRT") | |
end | |
end | |
begin | |
system("stty raw -echo") | |
loop do | |
handle_input STDIN.getc | |
end | |
ensure | |
system("stty -raw echo") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment