Class: BotMob::Wire

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

Overview

## BotMob::Wire

The Wire class is a connection to the Web Server. It receives notifications from authenticated installs over RabbitMQ

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:



23
24
25
# File 'lib/bot_mob/wire.rb', line 23

def available?
  @available
end

#listenObject



13
14
15
16
17
18
19
20
21
# File 'lib/bot_mob/wire.rb', line 13

def listen
  return if !block_given? || queue.nil?

  queue.subscribe do |_info, _props, body|
    yield(JSON.parse(body))
  end
rescue Bunny::PreconditionFailed => e
  BotMob.logger.info "#{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
end

#publish(message = {}) ⇒ Object



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

def publish(message = {})
  BotMob.logger.info "Publishing #{message} to wire.notifications"
  queue.publish(message.to_json, routing_key: queue.name)
end