Created
March 17, 2012 19:24
-
-
Save arches/2064504 to your computer and use it in GitHub Desktop.
Chat client for dogs
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
require 'iron_mq' | |
# IronMQ credentials | |
token = asdf | |
project_id = asdf | |
# each chatter needs their own queue | |
@fido = IronMQ::Client.new('token' => token, 'project_id' => project_id, :queue_name => "fido") | |
@red_rover = IronMQ::Client.new('token' => token, 'project_id' => project_id, :queue_name => "red_rover") | |
puts "What is your name?" | |
fido = (STDIN.gets.strip == "fido") | |
me = fido ? "fido" : 'red rover' | |
him = fido ? "red rover" : "fido" | |
puts "Ok, your name is #{me}" | |
reader_client = fido ? @red_rover : @fido | |
writer_client = fido ? @fido : @red_rover | |
reader = Thread.new do | |
while true | |
msg = reader_client.messages.get() | |
if msg | |
p "#{him}: #{msg.body.strip}" | |
msg.delete | |
end | |
sleep(1) | |
end | |
end | |
while true | |
outgoing = STDIN.gets | |
#break if outgoing.strip == "quit" | |
# write my messages | |
writer_client.messages.post(outgoing) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ht @joemsak