Class: Jabber::PubSub::NodeBrowser

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp4r/pubsub/helper/nodebrowser.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ NodeBrowser

Initialize a new NodeBrowser new(stream,pubsubservice)

stream
Jabber::Stream


14
15
16
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 14

def initialize(stream)
  @stream = stream
end

Instance Method Details

#category(jid, node) ⇒ Object

get category of node

jid
Jabber::JID
node
String


122
123
124
125
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 122

def category(jid,node)
  info = get_info(jid,node)
  return info['category']
end

#get_info(jid, node) ⇒ Object Also known as: get_metadata

get disco info for a node

jid
Jabber::JID
node
String
return
Hash
with possible keys type
String
,category
String],features:: [Array
of feature, nodeinformation
Jabber::XData

check www.xmpp.org/extensions/xep-0060.html#entity for more infos



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 86

def get_info(jid,node)
  iq = Iq.new(:get,jid)
  iq.from = @stream.jid
  discoinfo = Discovery::IqQueryDiscoInfo.new
  discoinfo.node = node
  iq.add(discoinfo)
  info = {}
  @stream.send_with_id(iq) do |answer|
    identity = answer.query.identity
    info['type'] = identity.type
    info['category'] = identity.category
    info['features'] = answer.query.features
    answer.query.each_element('x') { |x|
      info['nodeinformation'] = x
    }
  end
  info
end

#items(jid, node) ⇒ Object

Retrieve the items from a node Throws an ServerError when receiving <iq type='error'/>

jid
Jabber::JID

Target entity (set only domain!)

node
String
return
Array

of [Hash] with keys ‘name’ => [String] and ‘jid’ => [Jabber::JID]



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 64

def items(jid,node)
  iq = Iq.new(:get,jid)
  iq.from = @stream.jid
  discoitems = Discovery::IqQueryDiscoItems.new
  discoitems.node = node
  iq.add(discoitems)
  items = []
  err = nil
  @stream.send_with_id(iq) do |answer|
    answer.query.each_element('item') { |item|
      items.push( {'jid' => item.jid,'name' => item.iname } )
    }
  end
  items
end

#nodes(jid) ⇒ Object

Retrieve the nodes Throws an ServerError when receiving <iq type='error'/>

jid
JID

Target entity (set only domain!)

return
Array

of [String] or [nil]



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 24

def nodes(jid)
  iq = Iq.new(:get,jid)
  iq.from = @stream.jid
  iq.add(Discovery::IqQueryDiscoItems.new)
  nodes = []
  @stream.send_with_id(iq) do |answer|
    answer.query.each_element('item') { |item|
      nodes.push(item.node)
    }
  end
  nodes
end

#nodes_names(jid) ⇒ Object

Retrieve the nodes with names Throws a ServerError when receiving <iq type='error'/>

jid
Jabber::JID

Target entity (set only domain!)

return
Array

of [Hash] with keys ‘node’ => [String] and ‘name’ => [String] or [nil]



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 43

def nodes_names(jid)
  iq = Iq.new(:get,jid)
  iq.from = @stream.jid
  iq.add(Discovery::IqQueryDiscoItems.new)
  nodes = []
  @stream.send_with_id(iq) do |answer|
    answer.query.each_element('item') do |item|
      nodes.push( {'node' => item.node,'name' => item.iname } )
    end
  end
  nodes
end

#type(jid, node) ⇒ Object

get type of node

jid
Jabber::JID
node
String


112
113
114
115
# File 'lib/xmpp4r/pubsub/helper/nodebrowser.rb', line 112

def type(jid,node)
  info = get_info(jid,node)
  return info['type']
end