Class: Fabriq::Adapter::RypeAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/fabriq/adapter/rype_adapter.rb

Instance Method Summary collapse

Instance Method Details

#attach(&block) ⇒ Object



8
9
10
# File 'lib/fabriq/adapter/rype_adapter.rb', line 8

def attach(&block)
  ::Rype.attach
end

#available_rooms(&block) ⇒ Object



32
33
34
35
36
# File 'lib/fabriq/adapter/rype_adapter.rb', line 32

def available_rooms(&block)
  Rype::Chat.all do |chats|
    yield chats
  end
end

#load_room_information(room, &block) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/fabriq/adapter/rype_adapter.rb', line 38

def load_room_information(room, &block)
  room.topic do |topic|
    room.members do |members|
      yield({ topic: topic, id: room.chatname, members: members, raw: room })
    end
  end
end

#message_received(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fabriq/adapter/rype_adapter.rb', line 16

def message_received(&block)
  Rype.on(:chatmessage_received) do |chatmessage|
    chatmessage.chat do |chat|
      chatmessage.body do |body|
        chatmessage.from_name do |from_name|
          Thread.new { yield({ from_name: from_name, body: body, room_id: chat.chatname }) }
        end
      end
    end
  end
end

#send_message(chat, body) ⇒ Object



28
29
30
# File 'lib/fabriq/adapter/rype_adapter.rb', line 28

def send_message(chat, body)
  chat.send_message(body)
end

#waitObject



12
13
14
# File 'lib/fabriq/adapter/rype_adapter.rb', line 12

def wait
  ::Rype.thread.join
end