Class: JabberTee::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber-tee/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jabber-tee/client.rb', line 11

def initialize(config)
  @config = config
  @client = Jabber::Client.new(Jabber::JID.new("#{config.username}/#{config.nick}"))
  client.connect
  client.auth(config.password)

  if config.in_room?
    @muc = Jabber::MUC::SimpleMUCClient.new(client)
    @muc.join(Jabber::JID.new("#{config.room}/#{config.nick}"))
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/jabber-tee/client.rb', line 9

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/jabber-tee/client.rb', line 9

def config
  @config
end

Instance Method Details

#pump!Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jabber-tee/client.rb', line 23

def pump!
  if $stdin.tty?
    $STDERR.puts "Unable to pipe jabber-tee from a TTY"
    exit(1)
  else
    $stdin.each do |line|
      line.chomp!
      say(line)
      puts line
    end
  end
end

#say(message) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/jabber-tee/client.rb', line 36

def say(message)
  if config.in_room?
    @muc.say(message)
  else
    msg = Jabber::Message.new(config.to, message)
    msg.type = :chat
    client.send(msg)
  end
end