class Tenios::Blocks::Bridge

Constants

BLOCK_TYPE
BRIDGE_MODES
DESTINATION_TYPES
EXTERNAL_NUMBER
PARALLEL
SEQUENTIAL
SIP_TRUNK
SIP_USER

Public Class Methods

new(mode:, timeout: nil) { |self| ... } click to toggle source
# File lib/tenios/blocks/bridge.rb, line 24
def initialize(mode:, timeout: nil)
  @mode = mode
  @timeout = timeout
  @destinations = []

  raise "mode must be one of #{BRIDGE_MODES}" unless BRIDGE_MODES.include?(@mode)
  raise 'timeout is required' if parallel? && @timeout.nil?
  raise 'timeout is not accepted in this mode' if sequential? && !@timeout.nil?

  yield(self) if block_given?
end

Public Instance Methods

as_json(*) click to toggle source
# File lib/tenios/blocks/bridge.rb, line 51
def as_json(*)
  raise 'no destinations' if @destinations.empty?

  {
    blockType: BLOCK_TYPE,
    blockTimeout: @timeout,
    bridgeMode: @mode,
    destinations: @destinations
  }.compact
end
parallel?() click to toggle source
# File lib/tenios/blocks/bridge.rb, line 66
def parallel?
  @mode == PARALLEL
end
sequential?() click to toggle source
# File lib/tenios/blocks/bridge.rb, line 62
def sequential?
  @mode == SEQUENTIAL
end
with_destination(destination_type, destination, timeout = nil) click to toggle source
# File lib/tenios/blocks/bridge.rb, line 36
def with_destination(destination_type, destination, timeout = nil)
  raise 'timeout is required' if sequential? && timeout.nil?
  raise 'timeout is not accepted' if parallel? && !timeout.nil?
  raise "destination_type must be one of #{DESTINATION_TYPES}" unless DESTINATION_TYPES.include?(destination_type)
  raise 'destination is required' if destination.strip.empty?

  @destinations << {
    destinationType: destination_type,
    destination: destination.strip,
    timeout: timeout
  }.compact

  self
end