Skip to content

Instantly share code, notes, and snippets.

@snaka
Created March 31, 2009 13:52
Show Gist options
  • Save snaka/88200 to your computer and use it in GitHub Desktop.
Save snaka/88200 to your computer and use it in GitHub Desktop.
GNTP test program for ruby
#!/usr/bin/ruby
# GNTP test program for ruby
#
require 'socket'
def send_and_recieve msg
msg.gsub!(/\n/, "\r\n")
print msg
sock = TCPSocket.open('localhost', 23053)
sock.write msg
while rcv = sock.gets
break if rcv == "\r\n"
print ">#{rcv}"
end
sock.close
end
# REGISTER
send_and_recieve <<EOF
GNTP/1.0 REGISTER NONE
Application-Name: Ruby sample
Notifications-Count: 1
Notification-Name: GrowlTest
Notification-Display-Name: GrowlTest
Notification-Enabled: True
Notification-Icon: http://www.hatena.ne.jp/users/sn/snaka72/profile.gif
EOF
# NOTIFY
send_and_recieve <<EOF
GNTP/1.0 NOTIFY NONE
Application-Name: Ruby sample
Notification-Name: GrowlTest
Notification-Title: こんにちはグロウル
Notification-Text: Growlが来た!
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment