Sha256: 91fa3b26f021745028851372f5d493b0227835a13251c4e3899e864ef2729b2d

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8

module Punchblock
  class Event
    class Complete < Event
      register :complete, :ext

      attribute :reason

      attribute :recording

      attribute :fax
      attribute :fax_metadata, Hash, default: {}

      def inherit(xml_node)
        if reason_node = xml_node.at_xpath('*')
          self.reason = RayoNode.from_xml(reason_node).tap do |reason|
            reason.target_call_id = target_call_id
            reason.component_id = component_id
          end
        end

        if recording_node = xml_node.at_xpath('//ns:recording', ns: RAYO_NAMESPACES[:record_complete])
          self.recording = RayoNode.from_xml(recording_node).tap do |recording|
            recording.target_call_id = target_call_id
            recording.component_id = component_id
          end
        end

        if fax_node = xml_node.at_xpath('//ns:fax', ns: RAYO_NAMESPACES[:fax_complete])
          self.fax = RayoNode.from_xml(fax_node).tap do |fax|
            fax.target_call_id = target_call_id
            fax.component_id = component_id
          end
        end

        xml_node.xpath('//ns:metadata', ns: RAYO_NAMESPACES[:fax_complete]).each do |md|
          fax_metadata[md['name']] = md['value']
        end

        super
      end

      class Reason < Event
        attribute :name, Symbol, default: ->(node,_) { node.class.registered_name.to_sym }

        def inherit(xml_node)
          self.name = xml_node.name.to_sym
          super
        end
      end

      class Stop < Reason
        register :stop, :ext_complete
      end

      class Hangup < Reason
        register :hangup, :ext_complete
      end

      class Error < Reason
        register :error, :ext_complete

        attribute :details

        def inherit(xml_node)
          self.details = xml_node.text.strip
          super
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/event/complete.rb
punchblock-2.7.3 lib/punchblock/event/complete.rb
punchblock-2.7.2 lib/punchblock/event/complete.rb
punchblock-2.7.1 lib/punchblock/event/complete.rb
punchblock-2.7.0 lib/punchblock/event/complete.rb
punchblock-2.6.0 lib/punchblock/event/complete.rb
punchblock-2.5.3 lib/punchblock/event/complete.rb
punchblock-2.5.2 lib/punchblock/event/complete.rb
punchblock-2.5.1 lib/punchblock/event/complete.rb
punchblock-2.5.0 lib/punchblock/event/complete.rb
punchblock-2.4.2 lib/punchblock/event/complete.rb
punchblock-2.4.0 lib/punchblock/event/complete.rb
punchblock-2.3.1 lib/punchblock/event/complete.rb
punchblock-2.3.0 lib/punchblock/event/complete.rb
punchblock-2.2.2 lib/punchblock/event/complete.rb
punchblock-2.2.1 lib/punchblock/event/complete.rb