Module: Fabriq::Adapter

Extended by:
Adapter
Included in:
Adapter
Defined in:
lib/fabriq/adapter.rb,
lib/fabriq/adapter/rype_adapter.rb

Defined Under Namespace

Classes: RypeAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

#proxyObject

Returns the value of attribute proxy.



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

def proxy
  @proxy
end

#roomsObject

Returns the value of attribute rooms.



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

def rooms
  @rooms
end

#skype_proxy_classObject

Returns the value of attribute skype_proxy_class.



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

def skype_proxy_class
  @skype_proxy_class
end

Instance Method Details

#enqueue_outgoing_message(message) ⇒ Object



40
41
42
# File 'lib/fabriq/adapter.rb', line 40

def enqueue_outgoing_message(message)
  self.proxy.outgoing_messages << message
end

#find_skype_room_by_id(room_id) ⇒ Object



33
34
35
36
37
38
# File 'lib/fabriq/adapter.rb', line 33

def find_skype_room_by_id(room_id)
  @rooms.each do |room|
    return room if room.id == room_id
  end
  nil
end

#init_skype_proxyObject



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

def init_skype_proxy
  self.proxy = skype_proxy_class.new(self)
  self.proxy.start
end

#loadObject



14
15
16
# File 'lib/fabriq/adapter.rb', line 14

def load
  @adapter = Fabriq::Config.adapter.new
end

#message_received(&block) ⇒ Object



48
49
50
51
52
53
# File 'lib/fabriq/adapter.rb', line 48

def message_received(&block)
  self.adapter.message_received do |raw_message|
    skype_room = find_skype_room_by_id(raw_message[:room_id])
    block.call(build_skype_message(skype_room, raw_message)) if block_given?
  end
end

#run(&block) ⇒ Object



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

def run(&block)
  init_skype_proxy
  self.adapter.attach
  find_available_rooms do |rooms|
    @rooms = rooms
    block.call if block_given?
  end
  self.adapter.wait
end

#send_message(message) ⇒ Object



55
56
57
# File 'lib/fabriq/adapter.rb', line 55

def send_message(message)
  self.adapter.send_message(message.room.raw, message.body)
end

#subscribe_to_incoming_messages(&block) ⇒ Object



44
45
46
# File 'lib/fabriq/adapter.rb', line 44

def subscribe_to_incoming_messages(&block)
  self.proxy.on_incoming_message(&block)
end