|
APIUsage
This is your launchpad for all the documentation.
System RequirementsPlease go to the SystemRequirements page for more information on that topic. Using the RubyMSN APIGetting startedWe have a little Tutorial to get you started quickly. ExamplePlease note that this example only runs well on Unix-based systems or Cygwin. cmd.exe is having problems with it. An example with a Tk GUI can be found here. require 'msn'
email = "your-user@name.org"
password = "yourpassword"
puts "Signing in... please wait."
# create a new MSN connection
msnsock = MSNConnection.new(email, password)
# connect events to their handlers
msnsock.signed_in = lambda { puts "Signed in" }
msnsock.buddy_update = lambda {|oldcontact, contact| puts "Updated #{contact.email} (status: #{oldcontact.status.name} -> #{contact.status.name})"}
msnsock.new_chat_session = lambda {|tag, session|
puts "New chat session request. Tag: #{tag}"
# chat sessions have events too!
session.message_received = lambda {|sender, message|
puts sender + " says: " + message
# just for fun ;-) The possibilities are endless...
if message[0..3].upcase == "PING"
message = message.gsub(/i/, "o").gsub(/\?/, "!")
session.say message
else
session.say message.reverse
end
}
session.session_started = lambda {
puts "Session with tag '" + tag + "' started!"
}
session.participants_updated = lambda {
puts "Participants in '#{tag}': " + session.participants.list.to_s
}
# don't forget to start the chat session!
session.start
}
# start signing in!
msnsock.start
# a very ugly coded but working basic msn chat interface (for debugging)
while true
sleep 1
puts "Syntax: contacts OR start<tab>email OR chatroom-tag<tab>message"
input = gets.chop
tag = input.split("\t")[0]
if tag == "start"
puts "Enter a tag so you can refer to the room: "
msnsock.start_chat(gets.chop, input.split("\t")[1])
elsif tag == "contacts"
msnsock.contactlists["FL"].list.each {|email, contact|
puts email + ": " + contact.status.name if contact.status.name != "Offline"
}
else
message = input.split("\t")[1]
msnsock.chatsessions[tag].say(message)
end
end
|
Sign in to add a comment