Class: AgentXmpp::Xmpp::IqCommand

Inherits:
Element show all
Defined in:
lib/agent_xmpp/xmpp/iq_command.rb

Overview


Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#<<, class_for_name_xmlns, #clone, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=, xmpp_attribute, xmpp_child

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add

Constructor Details

#initialize(node = nil, action = nil) ⇒ IqCommand

.….….….….….….….….….….….….….….….….….….….….….….….….….



41
42
43
44
45
# File 'lib/agent_xmpp/xmpp/iq_command.rb', line 41

def initialize(node=nil, action=nil)
  super()
  self.node = node if node
  self.action = action if action
end

Class Method Details

.send_command(args, &blk) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/agent_xmpp/xmpp/iq_command.rb', line 21

def send_command(args, &blk)
  iq = Xmpp::Iq.new(args[:iq_type] || :set, args[:to])
  iq.id = args[:id] unless args[:id].nil?
  iq.command = new(args[:node])
  iq.command.action = args[:action] unless args[:action].nil? 
  iq.command.status = args[:status] unless args[:status].nil? 
  iq.command.sessionid = args[:sessionid] unless args[:sessionid].nil?
  iq.command << args[:payload] unless args[:payload].nil?
  if blk
    Send(iq) do |r|  
      AgentXmpp.logger.info "RECEIVED RESPONSE: #{r.type} from #{r.from}"
      blk.call(r.type, (r.type.eql?(:result) and r.command and r.command.x) ? r.command.x.to_native : nil)
    end
  else; Send(iq); end               
end