Class: Jabber::Roster::IqQueryRoster

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

Overview

Class for handling roster updates

You must do ‘client.send(Iq.new_rosterget)’ or else you will have nothing to put in receive_iq()

You must require ‘xmpp4r/rosterquery’ to use this class as its functionality is not needed for a working XMPP implementation. This will make [IqQuery] convert all Queries with namespace ‘jabber:iq:roster’ to [IqQueryRoster]

This <query/> contains multiple <item/> children. See RosterItem.

Instance Method Summary collapse

Methods inherited from XMPPElement

class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, #initialize, 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

This class inherits a constructor from Jabber::XMPPElement

Instance Method Details

#[](jid) ⇒ Object

Get roster item by JID

jid
JID

or [Nil]

result
RosterItem


38
39
40
41
42
43
# File 'lib/xmpp4r/roster/iq/roster.rb', line 38

def [](jid)
  each { |item|
    return(item) if item.jid == jid
  }
  nil
end

#each(&block) ⇒ Object

Iterate through all items

&block

Yield for every [RosterItem]



27
28
29
30
31
32
# File 'lib/xmpp4r/roster/iq/roster.rb', line 27

def each(&block)
  each_element { |item|
    # XPath won't work here as it's missing a prefix...
    yield(item) if item.kind_of?(RosterItem)
  }
end

#inspectObject

Output for “p”

JIDs of all contained [RosterItem] elements are joined with a comma

result
String


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

def inspect
  jids = to_a.collect { |item| item.jid.inspect }
  jids.join(', ')
end

#receive_iq(iq, filter = true) ⇒ Object

Update roster by <iq/> stanza (to be fed by an iq_callback)

iq
Iq

Containing new roster

filter
Boolean

If false import non-roster-like results too



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

def receive_iq(iq, filter=true)
  if filter && (((iq.type != :set) && (iq.type != :result)) || (iq.queryns != 'jabber:iq:roster'))
    return
  end

  import(iq.query)
end

#to_aObject

Get all items

result
Array

of [RosterItem]



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

def to_a
  a = []
  each { |item|
    a.push(item)
  }
  a
end