Sha256: 327707c77419ba8027d267af65170a69834648fb474c537d632e21fad6e4e169

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://home.gna.org/xmpp4r/

require 'xmpp4r/entity_time/iq'

module Jabber::EntityTime
  ##
  # XEP 202 Entity Time implementation
  #
  # @see http://xmpp.org/extensions/xep-0202.html
  #
  # @example
  # <iq type='get'
  #     from='romeo@montague.net/orchard'
  #     to='juliet@capulet.com/balcony'
  #     id='time_1'>
  #   <time xmlns='urn:xmpp:time'/>
  # </iq>
  #
  class Responder

    CALLBACK_PRIORITY = 180

    ##
    # +to_s+ allows the responder to be added to another responder as a feature
    def to_s
      NS_TIME
    end

    def initialize(stream)
      @stream = stream

      stream.add_iq_callback(CALLBACK_PRIORITY, self) do |iq|
        iq_callback(iq)
      end
    end # /initialize

    def iq_callback(iq)
      if iq.type == :get &&
          iq.first_element('time') &&
          iq.first_element('time').namespace === NS_TIME

        answer = iq.answer(false)
        answer.type = :result
        answer.add(IqTime.new(Time.now))

        @stream.send(answer)

        return true
      end

      false
    end

  end # /Responder
end # /Jabber::EntityTime

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
xmpp4r-0.5.5 lib/xmpp4r/entity_time/responder.rb
gmcmillan-xmpp4r-0.6.2 lib/xmpp4r/entity_time/responder.rb
gmcmillan-xmpp4r-0.6.1 lib/xmpp4r/entity_time/responder.rb
gmcmillan-xmpp4r-0.6 lib/xmpp4r/entity_time/responder.rb
gmcmillan-xmpp4r-0.5 lib/xmpp4r/entity_time/responder.rb
mad-p-xmpp4r-0.6.3 lib/xmpp4r/entity_time/responder.rb
mad-p-xmpp4r-0.6.2 lib/xmpp4r/entity_time/responder.rb
mad-p-xmpp4r-0.6.1 lib/xmpp4r/entity_time/responder.rb
mad-p-xmpp4r-0.6.0 lib/xmpp4r/entity_time/responder.rb