Class Jabber::RosterItem
In: lib/xmpp4r/iq/query/roster.rb
Parent: REXML::Element
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

Class containing the <item/> elements of the roster

The ‘name’ attribute has been renamed to ‘iname’ here as ‘name’ is already used by REXML::Element for the element’s name. It’s still name=’…’ in XML.

Methods

ask   ask=   groups   groups=   import   iname   iname=   jid   jid=   new   subscription   subscription=  

Public Class methods

Create new RosterItem from REXML::Element

item:[REXML::Element] source element to copy attributes and children from

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 125
125:     def RosterItem.import(item)
126:       RosterItem::new.import(item)
127:     end

Construct a new roster item

jid:[JID] Jabber ID
iname:[String] Name in the roster
subscription:[String] Type of subscription (see RosterItem#subscription=)
ask:[String] or [Nil] Can be "ask"

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 114
114:     def initialize(jid=nil, iname=nil, subscription=nil, ask=nil)
115:       super('item')
116:       self.jid = jid
117:       self.iname = iname
118:       self.subscription = subscription
119:       self.ask = ask
120:     end

Public Instance methods

Get if asking for subscription

result:[Symbol] nil or :subscribe

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 196
196:     def ask
197:       case attributes['ask']
198:         when 'subscribe' then :subscribe
199:         else nil
200:       end
201:     end

Set if asking for subscription

val:[Symbol] nil or :subscribe

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 206
206:     def ask=(val)
207:       case val
208:         when :subscribe then attributes['ask'] = 'subscribe'
209:         else attributes['ask'] = nil
210:       end
211:     end

Get groups the item belongs to

result:[Array] of [String] The groups

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 216
216:     def groups
217:       result = []
218:       each_element('group') { |group|
219:         result.push(group.text)
220:       }
221:       result
222:     end

Set groups the item belongs to, deletes old groups first.

See JEP 0083 for nested groups

ary:[Array] New groups, duplicate values will be removed

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 230
230:     def groups=(ary)
231:       # Delete old group elements
232:       delete_elements('group')
233: 
234:       # Add new group elements
235:       ary.uniq.each { |group|
236:         add_element('group').text = group
237:       }
238:     end

Get name of roster item

names can be set by the roster’s owner himself

return:[String]

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 134
134:     def iname
135:       attributes['name']
136:     end

Set name of roster item

val:[String] Name for this item

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 141
141:     def iname=(val)
142:       attributes['name'] = val
143:     end

Get JID of roster item Resource of the JID will not be stripped

return:[JID]

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 149
149:     def jid
150:       JID::new(attributes['jid'])
151:     end

Set JID of roster item

val:[JID] or nil

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 156
156:     def jid=(val)
157:       attributes['jid'] = val.nil? ? nil : val.to_s
158:     end

Get subscription type of roster item

result:[Symbol] or [Nil] The following values are valid according to RFC3921:
  • :both
  • :from
  • :none
  • :remove
  • :to

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 168
168:     def subscription
169:       case attributes['subscription']
170:         when 'both' then :both
171:         when 'from' then :from
172:         when 'none' then :none
173:         when 'remove' then :remove
174:         when 'to' then :to
175:         else nil
176:       end
177:     end

Set subscription type of roster item

val:[Symbol] or [Nil] See subscription for possible Symbols

[Source]

     # File lib/xmpp4r/iq/query/roster.rb, line 182
182:     def subscription=(val)
183:       case val
184:         when :both then attributes['subscription'] = 'both'
185:         when :from then attributes['subscription'] = 'from'
186:         when :none then attributes['subscription'] = 'none'
187:         when :remove then attributes['subscription'] = 'remove'
188:         when :to then attributes['subscription'] = 'to'
189:         else attributes['subscription'] = nil
190:       end
191:     end

[Validate]