Class Jabber::Iq
In: lib/xmpp4r/iq.rb
Parent: XMLStanza
X XDelay XMuc XRoster XMucUser REXML::Element XRosterItem IqQuery XMLStanza IqVcard DiscoIdentity XMucUserItem DiscoItem Error RosterItem DiscoFeature IqQueryRoster IqQueryVersion IqQueryDiscoItems IqQueryDiscoInfo Message Presence Iq Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure RosterItem Stream StreamParser Roster Vcard Version lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/iq/query/roster.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/iq/query/version.rb lib/xmpp4r/connection.rb lib/xmpp4r/x/mucuseritem.rb lib/xmpp4r/x/roster.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/iq/query.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/x/delay.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x/muc.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/iq/vcard.rb lib/xmpp4r/iq/query/discoinfo.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/message.rb lib/xmpp4r/iq/query/discoitems.rb lib/xmpp4r/presence.rb lib/xmpp4r/helpers/roster.rb lib/xmpp4r/helpers/vcard.rb lib/xmpp4r/helpers/version.rb Helpers Jabber Module: Jabber

IQ: Information/Query (see RFC3920 - 9.2.3

A class used to build/parse IQ requests/responses

Methods

Public Class methods

Add a class by name. Elements with this name will be automatically converted to the specific class. Used for <query/>, <vCard>, <pubsub> etc.

name:[String] Element name
elementclass:[Class] Target class

[Source]

     # File lib/xmpp4r/iq.rb, line 213
213:     def Iq.add_elementclass(name, elementclass)
214:       @@element_classes[name] = elementclass
215:     end

Create a new iq from a stanza, copies all attributes and children from xmlstanza

xmlstanza:[REXML::Element] Source stanza
return:[Iq] New stanza

[Source]

     # File lib/xmpp4r/iq.rb, line 112
112:     def Iq.import(xmlstanza)
113:       Iq::new.import(xmlstanza)
114:     end

Build a new <iq/> stanza

type:[Symbol] or nil, see Iq#type
to:[JID] Recipient

[Source]

    # File lib/xmpp4r/iq.rb, line 22
22:     def initialize(type = nil, to = nil)
23:       super("iq")
24:       if not to.nil?
25:         set_to(to)
26:       end 
27:       if not type.nil?
28:         set_type(type)
29:       end 
30:     end

Create a new jabber:iq:auth set Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 141
141:     def Iq.new_authset(jid, password)
142:       iq = Iq::new(:set)
143:       query = IqQuery::new
144:       query.add_namespace('jabber:iq:auth')
145:       query.add(REXML::Element::new('username').add_text(jid.node))
146:       query.add(REXML::Element::new('password').add_text(password))
147:       query.add(REXML::Element::new('resource').add_text(jid.resource)) if not jid.resource.nil?
148:       iq.add(query)
149:       iq
150:     end

Create a new jabber:iq:auth set Stanza for Digest authentication

[Source]

     # File lib/xmpp4r/iq.rb, line 154
154:     def Iq.new_authset_digest(jid, session_id, password)
155:       iq = Iq::new(:set)
156:       query = IqQuery::new
157:       query.add_namespace('jabber:iq:auth')
158:       query.add(REXML::Element::new('username').add_text(jid.node))
159:       query.add(REXML::Element::new('digest').add_text(Digest::SHA1.new(session_id + password).hexdigest))
160:       query.add(REXML::Element::new('resource').add_text(jid.resource)) if not jid.resource.nil?
161:       iq.add(query)
162:       iq
163:     end

Create a new jabber:iq:roster get Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 179
179:     def Iq.new_browseget
180:       iq = Iq::new(:get)
181:       query = IqQuery::new
182:       query.add_namespace('jabber:iq:browse')
183:       iq.add(query)
184:       iq
185:     end

Create a new Iq stanza with an unspecified query child (<query/> has no namespace)

[Source]

     # File lib/xmpp4r/iq.rb, line 132
132:     def Iq.new_query(type = nil, to = nil)
133:       iq = Iq::new(type, to)
134:       query = IqQuery::new
135:       iq.add(query)
136:       iq
137:     end

Create a new jabber:iq:roster get Stanza.

IqQueryRoster is unused here because possibly not require’d

[Source]

     # File lib/xmpp4r/iq.rb, line 169
169:     def Iq.new_rosterget
170:       iq = Iq::new(:get)
171:       query = IqQuery::new
172:       query.add_namespace('jabber:iq:roster')
173:       iq.add(query)
174:       iq
175:     end

Create a new jabber:iq:roster set Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 189
189:     def Iq.new_rosterset
190:       iq = Iq::new(:set)
191:       query = IqQuery::new
192:       query.add_namespace('jabber:iq:roster')
193:       iq.add(query)
194:       iq
195:     end

Create a new Iq stanza with a vCard child

type:[String] or "get" if omitted

[Source]

     # File lib/xmpp4r/iq.rb, line 200
200:     def Iq.new_vcard(type = :get, to = nil)
201:       iq = Iq::new(type, to)
202:       iq.add(IqVcard::new)
203:       iq
204:     end

Public Instance methods

Returns the iq’s query child, or nil

result:[IqQuery]

[Source]

    # File lib/xmpp4r/iq.rb, line 75
75:     def query 
76:       first_element('query')
77:     end

Delete old elements named newquery.name

newquery:[REXML::Element] will be added

[Source]

    # File lib/xmpp4r/iq.rb, line 83
83:     def query=(newquery)
84:       delete_elements(newquery.name)
85:       add(newquery)
86:     end

Returns the iq’s query’s namespace, or nil

result:[String]

[Source]

    # File lib/xmpp4r/iq.rb, line 91
91:     def queryns 
92:       e = first_element('query')
93:       if e
94:         return e.namespace
95:       else
96:         return nil
97:       end
98:     end

Set the type of the Iq stanza (chaining-friendly)

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/iq.rb, line 67
67:     def set_type(v)
68:       self.type = v
69:       self
70:     end

Get the type of the Iq stanza

The following values are allowed:

  • :get
  • :set
  • :result
  • :error
result:[Symbol] or nil

[Source]

    # File lib/xmpp4r/iq.rb, line 41
41:     def type
42:       case super
43:         when 'get' then :get
44:         when 'set' then :set
45:         when 'result' then :result
46:         when 'error' then :error
47:         else nil
48:       end
49:     end

Set the type of the Iq stanza (see Iq#type)

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/iq.rb, line 54
54:     def type=(v)
55:       case v
56:         when :get then super('get')
57:         when :set then super('set')
58:         when :result then super('result')
59:         when :error then super('error')
60:         else super(nil)
61:       end
62:     end

Add an element to the Iq stanza

element:[REXML::Element] Element to add.

Will be automatically converted (imported) to a class registered with add_elementclass

[Source]

     # File lib/xmpp4r/iq.rb, line 121
121:     def typed_add(element)
122:       if element.kind_of?(REXML::Element) && @@element_classes.has_key?(element.name)
123:         super(@@element_classes[element.name]::import(element))
124:       else
125:         super(element)
126:       end
127:     end

Returns the iq’s <vCard/> child, or nil

result:[IqVcard]

[Source]

     # File lib/xmpp4r/iq.rb, line 103
103:     def vcard 
104:       first_element('vCard')
105:     end

[Validate]