Sha256: 831c3c4ec4b0e0ad9328e6a43f93439c04dc0f2a77504f3e2d96608baf2583d5

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

require 'adhearsion/rayo/command_node'
require 'adhearsion/has_headers'

module Adhearsion
  module Rayo
    module Command
      class Reject < CommandNode
        register :reject, :core

        include HasHeaders

        VALID_REASONS = [:busy, :decline, :error].freeze

        # @return [Symbol] the reason type for rejecting a call. One of :busy, :dclined or :error.
        # @raises ArgumentError if reject_reason is not one of the allowed reasons
        attribute :reason, Symbol
        def reason=(reject_reason)
          if reject_reason && !VALID_REASONS.include?(reject_reason.to_sym)
            raise ArgumentError, "Invalid Reason (#{reject_reason}), use: #{VALID_REASONS*' '}"
          end
          super
        end

        def inherit(xml_node)
          if first_child = xml_node.at_xpath('*')
            self.reason = first_child.name
          end
          super
        end

        def rayo_children(root)
          root.send reason if reason
          super
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-3.0.0.rc1 lib/adhearsion/rayo/command/reject.rb
adhearsion-3.0.0.beta2 lib/adhearsion/rayo/command/reject.rb
adhearsion-3.0.0.beta1 lib/adhearsion/rayo/command/reject.rb