Skip to content

Instantly share code, notes, and snippets.

@arches
Created March 17, 2012 19:24
Show Gist options
  • Save arches/2064504 to your computer and use it in GitHub Desktop.
Save arches/2064504 to your computer and use it in GitHub Desktop.
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
Copy link
Author

arches commented Mar 21, 2012

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