Class: Jabber::EntityTime::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp4r/entity_time/responder.rb

Overview

XEP 202 Entity Time implementation

<iq type='get'

  from='[email protected]/orchard'
  to='[email protected]/balcony'
  id='time_1'>
<time xmlns='urn:xmpp:time'/>

</iq>

Constant Summary collapse

CALLBACK_PRIORITY =
180

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Responder

Returns a new instance of Responder


31
32
33
34
35
36
37
# File 'lib/xmpp4r/entity_time/responder.rb', line 31

def initialize(stream)
  @stream = stream

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

Instance Method Details

#iq_callback(iq) ⇒ Object

/initialize


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/xmpp4r/entity_time/responder.rb', line 39

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

#to_sObject

to_s allows the responder to be added to another responder as a feature


27
28
29
# File 'lib/xmpp4r/entity_time/responder.rb', line 27

def to_s
  NS_TIME
end