1 2 #!/usr/bin/ruby 3 4 require 'rubygems' 5 require 'socket' 6 require 'open-uri' 7 require 'xmpp4r-simple' 8 9 server = TCPServer.new('127.0.0.1', 9090) 10 messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password") 11 12 while (session = server.accept) 13 request = session.gets 14 project = request[/(\w+)\?msg=(.*) HTTP\/1.1/,1] 15 msg = URI.unescape($2) 16 17 puts request 18 session.print "HTTP/1.1 200/OK\rContent-type: text/html\r\n\r\n" 19 session.print "<html><head><title>Response from Jeeves</title></head>\r\n" 20 session.print "<body>" 21 22 if project != '' and msg != '' then 23 case project 24 when 'identica' 25 messenger.deliver("update@identi.ca", msg) 26 else 27 puts "Project #{project} wasn't found on this server" 28 end 29 end 30 session.print URI.unescape(request) 31 32 session.print "</body></html>" 33 session.close 34 end
To post the message you would type your message within the browser URL e.g. http://127.0.0.1:9090/identica?msg=just%20testing%20xmpp4r-simple%20from%20tcpserver1