Sha256: 950f669c57f37cfe893402aed736298714992df375fe07a7637f559e928ae581

Contents?: true

Size: 999 Bytes

Versions: 3

Compression:

Stored size: 999 Bytes

Contents

# encoding: utf-8

require 'adhearsion/rayo'

module Blather
  class Stanza
    RAYO_NODE_PATH = "(#{Adhearsion::Rayo::RAYO_NAMESPACES.keys.map { |k| "#{k}:*" }.join("|")})".freeze
    ##
    # @return [Adhearsion::Rayo::RayoNode] a child of RayoNode
    #   representing the Rayo command/event contained within the stanza
    #
    def rayo_node
      @rayo_node ||= begin
        first_child = at_xpath RAYO_NODE_PATH, Adhearsion::Rayo::RAYO_NAMESPACES
        Adhearsion::Rayo::RayoNode.from_xml first_child, nil, component_id, "xmpp:#{from}", delay_timestamp if first_child
      end
    end

    ##
    # @return [String] the call ID this stanza applies to
    #
    def call_id
      from.node
    end

    ##
    # @return [String] the command ID this stanza applies to
    #
    def component_id
      from.resource
    end

  private

    def delay_timestamp
      if delay = self.at_xpath('ns:delay', ns: 'urn:xmpp:delay')
        DateTime.parse(delay[:stamp])
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-3.0.0.rc1 lib/adhearsion/core_ext/blather/stanza.rb
adhearsion-3.0.0.beta2 lib/adhearsion/core_ext/blather/stanza.rb
adhearsion-3.0.0.beta1 lib/adhearsion/core_ext/blather/stanza.rb