class Kybus::Bot::Adapter::Debug
This adapter is intended to be used on unit tests and development.
Public Class Methods
new(configs)
click to toggle source
It receives a hash with the configurations:
-
name: the name of the channel
-
channels a key value, where the key is a name and the value the list of the messages in the channel.
-
echo: a flag to enable debug messages.
# File lib/kybus/bot/adapters/debug.rb, line 86 def initialize(configs) @channels = {} configs['channels'].each do |name, messages| @channels[name] = Channel.new(messages, name, configs['echo']) end end
Public Instance Methods
channel(name)
click to toggle source
removes prefix from channel id
# File lib/kybus/bot/adapters/debug.rb, line 110 def channel(name) @channels[name.gsub('debug_message__', '')] end
echo=(toogle)
click to toggle source
changes echo config
# File lib/kybus/bot/adapters/debug.rb, line 135 def echo=(toogle) @channels.each { |_, channel| channel.echo = toogle } end
read_message()
click to toggle source
Interface for receiving message
# File lib/kybus/bot/adapters/debug.rb, line 94 def read_message # take the first message from the first open message, # then rotate the array loop do raise NoMoreMessageException if @channels.values.all?(&:empty?) msg = @channels.values.find(&:open?) return msg.read_message if msg # :nocov: # sleep(1) # :nocov: # end end
send_audio(channel_name, audio_url)
click to toggle source
interface for sending uadio
# File lib/kybus/bot/adapters/debug.rb, line 125 def send_audio(channel_name, audio_url) channel(channel_name).answer("AUDIO: #{audio_url}") end
send_image(channel_name, image_url)
click to toggle source
interface for sending image
# File lib/kybus/bot/adapters/debug.rb, line 130 def send_image(channel_name, image_url) channel(channel_name).answer("IMG: #{image_url}") end
send_message(channel_name, contents)
click to toggle source
interface for sending messages
# File lib/kybus/bot/adapters/debug.rb, line 115 def send_message(channel_name, contents) channel(channel_name).answer(contents) end
send_video(channel_name, video_url)
click to toggle source
interface for sending video
# File lib/kybus/bot/adapters/debug.rb, line 120 def send_video(channel_name, video_url) channel(channel_name).answer("VIDEO: #{video_url}") end