Class: Jabber::Iq

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

command new new_authset new_authset_digest new_browseget new_query new_register new_registerget new_rosterget new_rosterset pubsub query query= queryns set_type type type= vcard

### Public Class methods

new(type = nil, to = nil)

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

new_authset(jid, password)

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

new_authset_digest(jid, session_id, password)

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

new_browseget()

Create a new jabber:iq:roster get Stanza.

[Source]

         # File lib/xmpp4r/iq.rb, line 203
    203:     def Iq.new_browseget
    204:       iq = Iq.new(:get)
    205:       query = IqQuery.new
    206:       query.add_namespace('jabber:iq:browse')
    207:       iq.add(query)
    208:       iq
    209:     end

new_query(type = nil, to = nil)

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

new_register(username=nil, password=nil)

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

new_registerget()

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

[Source]

         # File lib/xmpp4r/iq.rb, line 181
    181:     def Iq.new_registerget
    182:       iq = Iq.new(:get)
    183:       query = IqQuery.new
    184:       query.add_namespace('jabber:iq:register')
    185:       iq.add(query)
    186:       iq
    187:     end

new_rosterget()

Create a new jabber:iq:roster get Stanza.

IqQueryRoster is unused here because possibly not require‘d

[Source]

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

new_rosterset()

Create a new jabber:iq:roster set Stanza.

[Source]

         # File lib/xmpp4r/iq.rb, line 213
    213:     def Iq.new_rosterset
    214:       iq = Iq.new(:set)
    215:       query = IqQuery.new
    216:       query.add_namespace('jabber:iq:roster')
    217:       iq.add(query)
    218:       iq
    219:     end

### Public Instance methods

command()

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

pubsub()

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

query()

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

query=(newquery)

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

queryns()

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_type(v)

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

type()

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

type=(v)

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

vcard()

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]