Class Jabber::Iq
In: lib/xmpp4r/iq.rb
Parent: XMPPStanza

IQ: Information/Query (see RFC3920 - 9.2.3

A class used to build/parse IQ requests/responses

Methods

Public Class methods

Build a new <iq/> stanza

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

[Source]

    # File lib/xmpp4r/iq.rb, line 28
28:     def initialize(type = nil, to = nil)
29:       super()
30: 
31:       if not to.nil?
32:         set_to(to)
33:       end
34:       if not type.nil?
35:         set_type(type)
36:       end
37:     end

Create a new jabber:iq:auth set Stanza.

[Source]

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

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

[Source]

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

Create a new jabber:iq:roster get Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 192
192:     def Iq.new_browseget
193:       iq = Iq::new(:get)
194:       query = IqQuery::new
195:       query.add_namespace('jabber:iq:browse')
196:       iq.add(query)
197:       iq
198:     end

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

[Source]

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

Create a new jabber:iq:roster set Stanza.

[Source]

     # File lib/xmpp4r/iq.rb, line 202
202:     def Iq.new_rosterset
203:       iq = Iq::new(:set)
204:       query = IqQuery::new
205:       query.add_namespace('jabber:iq:roster')
206:       iq.add(query)
207:       iq
208:     end

Public Instance methods

Returns the iq‘s <command/> child, or nil

resulte:[IqCommand]

[Source]

     # File lib/xmpp4r/iq.rb, line 124
124:     def command
125:       first_element("command")
126:     end

Returns the iq‘s <pubsub/> child, or nil

result:[IqVcard]

[Source]

     # File lib/xmpp4r/iq.rb, line 117
117:     def pubsub
118:       first_element('pubsub')
119:     end

Returns the iq‘s query child, or nil

result:[IqQuery]

[Source]

    # File lib/xmpp4r/iq.rb, line 82
82:     def query 
83:       first_element('query')
84:     end

Delete old elements named newquery.name

newquery:[REXML::Element] will be added

[Source]

    # File lib/xmpp4r/iq.rb, line 90
90:     def query=(newquery)
91:       delete_elements(newquery.name)
92:       add(newquery)
93:     end

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

result:[String]

[Source]

     # File lib/xmpp4r/iq.rb, line 98
 98:     def queryns
 99:       e = first_element('query')
100:       if e
101:         return e.namespace
102:       else
103:         return nil
104:       end
105:     end

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

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/iq.rb, line 74
74:     def set_type(v)
75:       self.type = v
76:       self
77:     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 48
48:     def type
49:       case super
50:         when 'get' then :get
51:         when 'set' then :set
52:         when 'result' then :result
53:         when 'error' then :error
54:         else nil
55:       end
56:     end

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

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/iq.rb, line 61
61:     def type=(v)
62:       case v
63:         when :get then super('get')
64:         when :set then super('set')
65:         when :result then super('result')
66:         when :error then super('error')
67:         else super(nil)
68:       end
69:     end

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

result:[IqVcard]

[Source]

     # File lib/xmpp4r/iq.rb, line 110
110:     def vcard
111:       first_element('vCard')
112:     end

[Validate]