Class: Jabber::Version::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/responder.rb

Overview

A class to answer version requests using IqQueryVersion

If you don’t need the flexibility of dynamic responses with the callback you can register with add_version_callback, take a look at SimpleResponder

Direct Known Subclasses

SimpleResponder

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Responder

Initialize a new version responder

Registers it’s callback (prio = 180, ref = self)

stream
Stream

Where to register callback handlers



22
23
24
25
26
27
28
29
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/responder.rb', line 22

def initialize(stream)
  @stream = stream
  @versioncbs = CallbackList.new

  stream.add_iq_callback(180, self) { |iq|
    iq_callback(iq)
  }
end

Instance Method Details

#add_version_callback(priority = 0, ref = nil, &block) ⇒ Object

Add a callback for Iq stanzas with IqQueryVersion

First argument passed to block is the Iq stanza, second argument is a block, which can be called with software name, version and os

Example:

my_version_helper.add_version_callback { |iq,block|
  block.call('Cool client', '6.0', 'Cool OS')
}


42
43
44
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/responder.rb', line 42

def add_version_callback(priority = 0, ref = nil, &block)
  @versioncbs.add(priority, ref, block)
end

#iq_callback(iq) ⇒ Object

<iq/> callback handler to answer Software Version queries (registered by constructor and used internally only)

Used internally



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/responder.rb', line 51

def iq_callback(iq)
  if iq.type == :get
    if iq.query.kind_of?(IqQueryVersion)
      replyblock = lambda { |name,version,os|
        answer = iq.answer
        answer.type = :result
        answer.query.set_iname(name).set_version(version).set_os(os)

        @stream.send(answer)
        true
      }
      @versioncbs.process(iq, replyblock)
    else
      false
    end
  else
    false
  end
end