> -----Original Message----- > From: Michal Rokos [mailto:rokosm / klokan.sh.cvut.cz] > Sent: Tuesday, January 22, 2002 5:32 AM > To: ruby-talk ML; undisclosed-recipients: > Subject: Re: [ANN] Jabber4R 0.1.0 > > > Hello Rich! > > Jabber support is great! > Thanks > Rich Kilmer <rich / infoether.com> wrote: > > require "jabber4r/jabber4r" > > > > session = Jabber::Session.bind_digest("myaccount / jabber.com/laptop", > > "password") > > session.new_chat_message("Rich_Kilmer / jabber.com").set_body("Hey").send > > session.release. > > Would be this API better? > > require "jabber4r/jabber4r" > include Jabber > > s = Session.bind_digest("myaccount / jabber.com/laptop", "pass") > m = Message.new("Rich_Kilmer / jabber.com", "HEY!") The problem is the message needs to have access to the Session, which contains a reference to the current Connection object. You could (right now) create a message through: require "jabber4r/jabber4r" include Jabber s = Session.bind_digest("myaccount / jabber.com/laptop", "pass") m = Protocol::Message.new("Rich_Kilmer / jabber.com", Protocol::Message::NORMAL) # Note 1: The Message is in the Protocol module, but could be # put into the Jabber namespace if it was necessary. # Note 2: The second param on the message is its type: # NORMAL, CHAT, GROUPCHAT, etc m.set_body("body & soul") # or # m.body="body & soul" # Note: there are accessors for body, subject, etc (body=)... # the set_body/subject method escapes the data (& => &, etc) m.session=s # you need this...as mentioned before m.send # Note: there is an optional boolean on send that if set for # true blocks waiting for a reply message. Also, you need to # set a thread id if its a chat message and you want to keep # the chat messages in a threaded conversation. I could add # the .send(message, boolean=false) method to Session to # accomplish the same thing. ---- Its for these reasons that I created the factory methods on session to construct the messages of certain types... s.new_message(to) #=> NORMAL message s.new_chat_message(to) #=> new_message(to, type=CHAT) ...and set their attributes (thread, session, etc) accordingly. I wanted to keep the API simple, which is why the factories are there. Do you think the other approach is better? -Rich