Class: Punchblock::Command::Reject

Inherits:
Punchblock::CommandNode show all
Includes:
HasHeaders
Defined in:
lib/punchblock/command/reject.rb

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from RayoNode

#call_id, #client, #component_id, #connection, #domain, #mixer_name, #original_component

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasHeaders

#headers, #headers=, #headers_hash

Methods inherited from Punchblock::CommandNode

#initialize, #response, #response=, #write_attr

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, register, #source

Constructor Details

This class inherits a constructor from Punchblock::CommandNode

Class Method Details

.new(options = {}) ⇒ Command::Reject

Create an Rayo reject message

Examples:

Reject.new(:reason => :busy).to_xml

returns:
    <reject xmlns="urn:xmpp:rayo:1"><busy/></reject

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :reason (Symbol)

    for rejecting the call. Can be any one of VALID_REASONS. Defaults to :decline

  • :headers (Array[Header], Hash, Optional)

    SIP headers to attach to the call. Can be either a hash of key-value pairs, or an array of Header objects.

Returns:



27
28
29
30
31
32
33
34
35
36
# File 'lib/punchblock/command/reject.rb', line 27

def self.new(options = {})
  super().tap do |new_node|
    case options
    when Nokogiri::XML::Node
      new_node.inherit options
    when Hash
      options.each_pair { |k,v| new_node.send :"#{k}=", v }
    end
  end
end

Instance Method Details

#inspect_attributesObject

:nodoc:



60
61
62
# File 'lib/punchblock/command/reject.rb', line 60

def inspect_attributes # :nodoc:
  [:reason] + super
end

#reasonSymbol

Returns the reason type for rejecting a call.

Returns:

  • (Symbol)

    the reason type for rejecting a call



41
42
43
# File 'lib/punchblock/command/reject.rb', line 41

def reason
  children.select { |c| c.is_a? Nokogiri::XML::Element }.first.name.to_sym
end

#reason=(reject_reason) ⇒ Object

Set the reason for rejecting the call

Parameters:

  • reject_reason (Symbol)

    Can be any one of :busy, :dclined or :error.



52
53
54
55
56
57
58
# File 'lib/punchblock/command/reject.rb', line 52

def reason=(reject_reason)
  if reject_reason && !VALID_REASONS.include?(reject_reason.to_sym)
    raise ArgumentError, "Invalid Reason (#{reject_reason}), use: #{VALID_REASONS*' '}"
  end
  children.each &:remove
  self << RayoNode.new(reject_reason)
end