Class: Cerberus::Publisher::Jabber

Inherits:
Base
  • Object
show all
Defined in:
lib/cerberus/publisher/jabber.rb

Class Method Summary collapse

Methods inherited from Base

formatted_message

Class Method Details

.publish(state, manager, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cerberus/publisher/jabber.rb', line 6

def self.publish(state, manager, options)
  begin
    jabber_options = options[:publisher, :jabber]
    raise "There is no recipients provided for Jabber publisher" unless jabber_options[:recipients]

    subject,body = Cerberus::Publisher::Base.formatted_message(state, manager, options)

    client = Jabber::Client::new(Jabber::JID.new(jabber_options[:jid]))
    client.connect
    client.auth(jabber_options[:password])

    jabber_options[:recipients].split(',').each do |address|
      message = Jabber::Message::new(address.strip, body).set_subject(subject)
      client.send(message)
    end
  ensure
    client.close if client
  end
end