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

Constants inherited from RayoNode

RayoNode::InvalidNodeError

Instance Attribute Summary

Attributes inherited from RayoNode

#client, #component_id, #connection, #domain, #original_component, #target_call_id, #target_mixer_name

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 a Rayo reject command

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:



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

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:



63
64
65
# File 'lib/punchblock/command/reject.rb', line 63

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



43
44
45
46
# File 'lib/punchblock/command/reject.rb', line 43

def reason
  node = reason_node
  node ? node.name.to_sym : nil
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.



55
56
57
58
59
60
61
# File 'lib/punchblock/command/reject.rb', line 55

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) if reject_reason
end