Class: Dog::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/dog/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Connection

Returns a new instance of Connection.



3
4
5
# File 'lib/dog/connection.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#jidObject



7
8
9
# File 'lib/dog/connection.rb', line 7

def jid
  @client.jid
end

#join(room_name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/dog/connection.rb', line 11

def join(room_name)
  room = "#{room_name}@conference.#{jid.domain}"
  service = jid.node

  join_stanza = Blather::Stanza::Presence::MUC.new
  join_stanza.to = "#{room}/#{service}"

  @client.write(join_stanza)
end

#say(to, text) ⇒ Object



21
22
23
# File 'lib/dog/connection.rb', line 21

def say(to, text)
  @client.write(Blather::Stanza::Message.new(to, text, :chat))
end

#say_to_chat(room_name, text) ⇒ Object



25
26
27
28
# File 'lib/dog/connection.rb', line 25

def say_to_chat(room_name, text)
  to = Blather::JID.new(room_name, "conference.#{jid.domain}")
  @client.write(Blather::Stanza::Message.new(to, text, :groupchat))
end