Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chat client for dogs
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
@arches

This comment has been minimized.

Show comment
Hide comment
Owner

arches commented Mar 21, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment