Skip to content

Instantly share code, notes, and snippets.

@Mamadou888
Forked from verdi327/gist:9177121
Created February 26, 2014 05:36
Show Gist options
  • Save Mamadou888/9224073 to your computer and use it in GitHub Desktop.
Save Mamadou888/9224073 to your computer and use it in GitHub Desktop.
#The contents of the message_reader.rb
require "httparty"
def get_new_messages(last_message_id)
url = "http://messengr.herokuapp.com/messages.json"
return HTTParty.get(url, :query => {:last_message_id => last_message_id})
end
last_message_id = 970
begin
messages = get_new_messages(last_message_id)
if messages.size > 0
last_message_id = messages.last["id"]
end
messages.each do |message|
puts "#{message['user']} say: #{message['text']}"
end
sleep 5
end while (true)
#contents of the message_writer.rb
require "httparty"
USER = "michael"
def send_new_message(message)
data = {:user => USER, :text => message}
url = "http://messengr.herokuapp.com/messages.json"
response = HTTParty.post(url, {:query => data })
if response.has_key?("error")
"ERROR: #{response['error']}"
else
response
end
end
begin
print "What's your message: "
message = gets.chomp
if message != "quit"
puts send_new_message(message)
end
end while ( message != "quit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment