Class: Whistle::Switchbox

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password, subscribers) ⇒ Switchbox

Returns a new instance of Switchbox.



8
9
10
11
# File 'lib/switchbox.rb', line 8

def initialize(user,password,subscribers)
  @user, @password, @subscribers = user, password, subscribers
  @jabber = Jabber::Simple.new(@user, @password)
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/switchbox.rb', line 6

def user
  @user
end

Instance Method Details

#deliver(messages) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/switchbox.rb', line 13

def deliver(messages)
  @subscribers.each do |to| 
    Array(messages).each do |body| 
      format_and_send :to => to, :body => body  
    end
  end
end

#inform(message) ⇒ Object

Sends message to primary (first) subscriber only



22
23
24
25
26
# File 'lib/switchbox.rb', line 22

def inform(message)
  if (primary = @subscribers.first)
    format_and_send :to => @subscribers.first, :body => message
  end
end