Problems with XMPP4R with Google Apps for your Domain account

I am having problems connecting (using the xmpp4r ruby api) to an
account on a ‘Google Apps for your Domain’ service.

I am able to connect to a standard gmail.com account (using
Jabber::Simple) fine, but when I try connecting to an account on the
alternative domain (let’s call it domain.com), I have to use the non-
simple way of doing it so I can set up the JID properly, and I get an
error.

This is the method I’m having a problem with:

11 def initialize(username)
12 @username = username
13 @email = “#{@username}@glam.ac.uk
14 @password = googlepassword (googlepassword is a method that
returns the unhashed user’s password)
15
16 jid = JID::new(@email, “talk.google.com”, “Glamlife”)
17 cl = Client::new(jid)
18 cl.connect
19 cl.auth(@password)
20 end

I get this error:

Jabber::ClientAuthenticationFailure: closed stream
from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:
118:in auth' from /Users/mark/Sites/daughter/app/models/gtalk.rb:20:in initialize’
from (irb):55:in `new’
from (irb):55
from :0

I have tried changing the cl.auth to cl.auth_nonsasl, to see if that
was the problem, and I get a different error:

IOError: closed stream
from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb:
346:in write' from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb: 346:in <<’
from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb:
346:in send_data' from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb: 344:in synchronize’
from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb:
344:in send_data' from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb: 375:in send’
from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/stream.rb:
432:in send_with_id' from /Library/Ruby/Gems/1.8/gems/xmpp4r-0.5/lib/xmpp4r/client.rb: 241:in auth_nonsasl’
from /Users/mark/Sites/daughter/app/models/gtalk.rb:19:in
initialize' from (irb):62:in new’
from (irb):62
from :0

If anyone has any idea what I’m doing wrong (I don’t really understand
all the authentication stuff!) I’d be extremely grateful for any
pointers.

Thanks,

Mark