harry’s memorandum

おれおれメモ

RubyでGoogle Talk

色々できるみたい。

$ sudo gem install xmpp4r
Successfully installed xmpp4r-0.5
1 gem installed
Installing ri documentation for xmpp4r-0.5...
Installing RDoc documentation for xmpp4r-0.5...
#!/usr/bin/ruby

require 'rubygems'
require 'xmpp4r'
require 'kconv'

class JabberMsg
  def initialize(user, pass)
    @user = user
    @pass = pass
    @client = auth
  end

  def auth
    c = Jabber::Client.new(Jabber::JID.new(@user))
    c.connect('talk.google.com',5222)
    begin
      c.auth(@pass)
    rescue => e
      p e.methods
      exit
    end
    return c
  end

  def sendmsg(friend, msg)
    talk = Jabber::Message.new(friend, msg)
    @client.send(talk)
  end
end

user  = 'example@gmail.com'
pass  = 'password'
friend = "example+friend@gmail.com"

jabber = JabberMsg.new(user, pass)
jabber.sendmsg(friend,"てすと".toutf8)