Class: AgentXmpp::Xmpp::IqRoster

Inherits:
IqQuery show all
Defined in:
lib/agent_xmpp/xmpp/iq_roster.rb

Overview


Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#<<, class_for_name_xmlns, #clone, import, #initialize, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=, xmpp_attribute, xmpp_child

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add

Constructor Details

This class inherits a constructor from AgentXmpp::Xmpp::Element

Class Method Details

.get(pipe) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



18
19
20
21
22
23
24
25
26
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 18

def get(pipe)
  Send(new_rosterget) do |r|
    if r.type == :result and r.kind_of?(Xmpp::Iq)
      pipe.broadcast_to_delegates(:on_roster_result, pipe, r)
    elsif r.type.eql?(:error)
      raise AgentXmppError, "roster request failed"
    end
  end
end

.remove(pipe, roster_item_jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 44

def remove(pipe, roster_item_jid)
  request = new_rosterset
  request.query.add(Xmpp::RosterItem.new(roster_item_jid, nil, :remove))
  Send(request) do |r|
    if r.type == :result and r.kind_of?(Xmpp::Iq)
      pipe.broadcast_to_delegates(:on_remove_roster_item_result, pipe, roster_item_jid)
    elsif r.type.eql?(:error)
      pipe.broadcast_to_delegates(:on_remove_roster_item_error, pipe, roster_item_jid)
    end
  end
end

.update(pipe, roster_item_jid, groups = nil) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 29

def update(pipe, roster_item_jid, groups=nil)
  request = new_rosterset
  item = Xmpp::RosterItem.new(roster_item_jid)
  item.groups = groups unless groups.nil?
  request.query.add(item)
  Send(request) do |r|
    if r.type == :result and r.kind_of?(Xmpp::Iq)
      pipe.broadcast_to_delegates(:on_update_roster_item_result, pipe, roster_item_jid)
    elsif r.type.eql?(:error)
      pipe.broadcast_to_delegates(:on_update_roster_item_error, pipe, roster_item_jid)
    end
  end
end

Instance Method Details

#[](jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



85
86
87
88
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 85

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

#each(&block) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



80
81
82
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 80

def each(&block)
  each_element {|item| yield(item) if item.kind_of?(RosterItem)}
end

#inspectObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



104
105
106
107
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 104

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

#receive_iq(iq, filter = true) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



98
99
100
101
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 98

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

#to_aObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



91
92
93
94
95
# File 'lib/agent_xmpp/xmpp/iq_roster.rb', line 91

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