Class: Jabber::Iq

Inherits:
XMPPStanza show all
Defined in:
lib/xmpp4r/iq.rb

Overview

IQ: Information/Query (see RFC3920 - 9.2.3

A class used to build/parse IQ requests/responses

Direct Known Subclasses

Command::IqCommand

Constant Summary collapse

@@element_classes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPStanza

answer, #answer, #error, #from, #from=, #id, #id=, #normalize, #set_from, #set_id, #set_to, #to, #to=

Methods inherited from XMPPElement

class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=

Methods inherited from REXML::Element

#==, #delete_elements, #each_elements, #first_element, #first_element_content, #first_element_text, #import, import, #replace_element_content, #replace_element_text, #typed_add

Constructor Details

#initialize(type = nil, to = nil) ⇒ Iq

Build a new <iq/> stanza

type
Symbol

or nil, see Iq#type

to
JID

Recipient



28
29
30
31
32
33
34
35
36
37
# File 'lib/xmpp4r/iq.rb', line 28

def initialize(type = nil, to = nil)
  super()

  if not to.nil?
    set_to(to)
  end
  if not type.nil?
    set_type(type)
  end
end

Class Method Details

.new_authset(jid, password) ⇒ Object

Create a new jabber:iq:auth set Stanza.



140
141
142
143
144
145
146
147
148
149
# File 'lib/xmpp4r/iq.rb', line 140

def Iq.new_authset(jid, password)
  iq = Iq.new(:set)
  query = IqQuery.new
  query.add_namespace('jabber:iq:auth')
  query.add(REXML::Element.new('username').add_text(jid.node))
  query.add(REXML::Element.new('password').add_text(password))
  query.add(REXML::Element.new('resource').add_text(jid.resource)) if not jid.resource.nil?
  iq.add(query)
  iq
end

.new_authset_digest(jid, session_id, password) ⇒ Object

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



153
154
155
156
157
158
159
160
161
162
# File 'lib/xmpp4r/iq.rb', line 153

def Iq.new_authset_digest(jid, session_id, password)
  iq = Iq.new(:set)
  query = IqQuery.new
  query.add_namespace('jabber:iq:auth')
  query.add(REXML::Element.new('username').add_text(jid.node))
  query.add(REXML::Element.new('digest').add_text(Digest::SHA1.hexdigest(session_id + password)))
  query.add(REXML::Element.new('resource').add_text(jid.resource)) if not jid.resource.nil?
  iq.add(query)
  iq
end

.new_browsegetObject

Create a new jabber:iq:roster get Stanza.



203
204
205
206
207
208
209
# File 'lib/xmpp4r/iq.rb', line 203

def Iq.new_browseget
  iq = Iq.new(:get)
  query = IqQuery.new
  query.add_namespace('jabber:iq:browse')
  iq.add(query)
  iq
end

.new_query(type = nil, to = nil) ⇒ Object

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



131
132
133
134
135
136
# File 'lib/xmpp4r/iq.rb', line 131

def Iq.new_query(type = nil, to = nil)
  iq = Iq.new(type, to)
  query = IqQuery.new
  iq.add(query)
  iq
end

.new_register(username = nil, password = nil) ⇒ Object

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)



168
169
170
171
172
173
174
175
176
# File 'lib/xmpp4r/iq.rb', line 168

def Iq.new_register(username=nil, password=nil)
  iq = Iq.new(:set)
  query = IqQuery.new
  query.add_namespace('jabber:iq:register')
  query.add(REXML::Element.new('username').add_text(username)) if username
  query.add(REXML::Element.new('password').add_text(password)) if password
  iq.add(query)
  iq
end

.new_registergetObject

Create a new jabber:iq:register get stanza for retrieval of accepted registration information



181
182
183
184
185
186
187
# File 'lib/xmpp4r/iq.rb', line 181

def Iq.new_registerget
  iq = Iq.new(:get)
  query = IqQuery.new
  query.add_namespace('jabber:iq:register')
  iq.add(query)
  iq
end

.new_rostergetObject

Create a new jabber:iq:roster get Stanza.

IqQueryRoster is unused here because possibly not require’d



193
194
195
196
197
198
199
# File 'lib/xmpp4r/iq.rb', line 193

def Iq.new_rosterget
  iq = Iq.new(:get)
  query = IqQuery.new
  query.add_namespace('jabber:iq:roster')
  iq.add(query)
  iq
end

.new_rostersetObject

Create a new jabber:iq:roster set Stanza.



213
214
215
216
217
218
219
# File 'lib/xmpp4r/iq.rb', line 213

def Iq.new_rosterset
  iq = Iq.new(:set)
  query = IqQuery.new
  query.add_namespace('jabber:iq:roster')
  iq.add(query)
  iq
end

Instance Method Details

#commandObject

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

resulte
IqCommand


124
125
126
# File 'lib/xmpp4r/iq.rb', line 124

def command
  first_element("command")
end

#pubsubObject

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

result
IqVcard


117
118
119
# File 'lib/xmpp4r/iq.rb', line 117

def pubsub
  first_element('pubsub')
end

#queryObject

Returns the iq’s query child, or nil

result
IqQuery


82
83
84
# File 'lib/xmpp4r/iq.rb', line 82

def query
  first_element('query')
end

#query=(newquery) ⇒ Object

Delete old elements named newquery.name

newquery
REXML::Element

will be added



90
91
92
93
# File 'lib/xmpp4r/iq.rb', line 90

def query=(newquery)
  delete_elements(newquery.name)
  add(newquery)
end

#querynsObject

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

result
String


98
99
100
101
102
103
104
105
# File 'lib/xmpp4r/iq.rb', line 98

def queryns
  e = first_element('query')
  if e
    return e.namespace
  else
    return nil
  end
end

#set_type(v) ⇒ Object

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

v
Symbol

or nil



74
75
76
77
# File 'lib/xmpp4r/iq.rb', line 74

def set_type(v)
  self.type = v
  self
end

#typeObject

Get the type of the Iq stanza

The following values are allowed:

  • :get

  • :set

  • :result

  • :error

result
Symbol

or nil



48
49
50
51
52
53
54
55
56
# File 'lib/xmpp4r/iq.rb', line 48

def type
  case super
    when 'get' then :get
    when 'set' then :set
    when 'result' then :result
    when 'error' then :error
    else nil
  end
end

#type=(v) ⇒ Object

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

v
Symbol

or nil



61
62
63
64
65
66
67
68
69
# File 'lib/xmpp4r/iq.rb', line 61

def type=(v)
  case v
    when :get then super('get')
    when :set then super('set')
    when :result then super('result')
    when :error then super('error')
    else super(nil)
  end
end

#vcardObject

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

result
IqVcard


110
111
112
# File 'lib/xmpp4r/iq.rb', line 110

def vcard
  first_element('vCard')
end