Class Jabber::Iq
In: lib/xmpp4r/iq.rb
Parent: XMLStanza
XMLStanza Message Presence Iq REXML::Element X IqQuery Error StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi XRosterItem RosterItem IqFeature XMUCUserItem XMUCUserInvite Feature Identity Item XDataField XDataReported XDataTitle XDataInstructions IqVcard Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure SOCKS5Error Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryDiscoItems IqQueryDiscoInfo IBB IBBTarget IBBInitiator Responder SimpleResponder X XRoster XMUCUser XMUC XDelay XData MUCClient SimpleMUCClient Base DigestMD5 Plain FileSource StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper MUCBrowser Helper Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard 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 218
218:     def Iq.add_elementclass(name, elementclass)
219:       @@element_classes[name] = elementclass
220:     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 193
193:     def Iq.new_browseget
194:       iq = Iq::new(:get)
195:       query = IqQuery::new
196:       query.add_namespace('jabber:iq:browse')
197:       iq.add(query)
198:       iq
199:     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:register set stanza for service/server registration

username:[String] (Element will be ommited if unset)
password:[String] (Element will be ommited if unset)

[Source]

     # File lib/xmpp4r/iq.rb, line 169
169:     def Iq.new_register(username=nil, password=nil)
170:       iq = Iq::new(:set)
171:       query = IqQuery::new
172:       query.add_namespace('jabber:iq:register')
173:       query.add(REXML::Element::new('username').add_text(username)) if username
174:       query.add(REXML::Element::new('password').add_text(password)) if password
175:       iq.add(query)
176:       iq
177:     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 183
183:     def Iq.new_rosterget
184:       iq = Iq::new(:get)
185:       query = IqQuery::new
186:       query.add_namespace('jabber:iq:roster')
187:       iq.add(query)
188:       iq
189:     end

Create a new jabber:iq:roster set Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 203
203:     def Iq.new_rosterset
204:       iq = Iq::new(:set)
205:       query = IqQuery::new
206:       query.add_namespace('jabber:iq:roster')
207:       iq.add(query)
208:       iq
209:     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]