Class: Rype::Events

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

Class Method Summary collapse

Class Method Details

.initialize_listenersObject



21
22
23
24
25
26
# File 'lib/rype/events.rb', line 21

def initialize_listeners
  mutex = Mutex.new
  Rype::Events.on(:chats_received) do |chats|          
    mutex.synchronize { Rype::Chat.chats = chats }
  end
end

.on(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rype/events.rb', line 6

def on(event)
  case event

  when :chatmessage_received
    Rype::Api.instance.on_notification("CHATMESSAGE (.*) STATUS RECEIVED") do |chatmessage_id|
      yield Chatmessage.new(chatmessage_id)
    end

  when :chats_received
    Rype::Api.instance.on_notification("CHATS (.*)") do |chatlist|
      yield chatlist.split(', ').map { |chatname| Chat.new(chatname) }
    end
  end
end