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

Constructor Details

#initializeWire

Returns a new instance of Wire.



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

def initialize
  @available = nil
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bot_mob/wire.rb', line 41

def available?
  !!@available
end

#listenObject

## wire.listen

The listen method takes a block to perform when a message is received over the wire. The message published to the wire is parsed JSON provided to the calling block.



30
31
32
33
34
35
36
37
38
# File 'lib/bot_mob/wire.rb', line 30

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

## wire.publish

The publish method takes a given message, converts it to JSON and pushes the json over the wire on the wire.notifications channel. This is primarily used for passing successful authentication to the running BotMob Application.



20
21
22
23
# File 'lib/bot_mob/wire.rb', line 20

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