1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://xmpp4r.github.io
#
# For documentation of the return values please see [Jabber::PubSub::ServiceHelper]
# This class is only a wrapper around [Jabber::PubSub::ServiceHelper]
#
require 'xmpp4r/pubsub/helper/servicehelper'
require 'xmpp4r/pubsub/helper/nodebrowser'
module Jabber
module PubSub
class NodeHelper < ServiceHelper
attr_reader :nodename
attr_reader :name
attr_reader :jid
attr_reader :my_subscriptions
##
# creates a new node
# new(client,service,nodename)
# stream:: [Jabber::Stream]
# jid:: [String] (jid of the pubsub service)
# nodename:: [String]
def initialize(stream, jid, nodename = nil, create_if_not_exist = true)
super(stream,jid)
@nodename = nodename
@jid = jid
@stream = stream
if create_if_not_exist and !node_exist?
# if no nodename is given a instant node will created
# (if the service supports instant nodes)
@nodename = create_node
else
get_subscriptions
end
end
##
# creates the node
# create(configuration=nil)
# configuration:: [Jabber::XData]
def create_node(configuration = Jabber::PubSub::NodeConfig.new)
unless node_exist?
super(@nodename,configuration)
else
false
end
end
##
# get the configuration of the node
# get_configuration(configuration=nil)
# configuration:: [Jabber::XData]
def get_configuration(subid = nil)
get_options(@nodename, subid)
end
##
# set the configuration of the node
# set_configuration(configuration=nil)
# configuration:: [Jabber::XData]
# subid:: [String] default is nil
def set_configuration(configuration,subid = nil)
set_options(@nodename, configuration, subid)
end
##
# deletes the node
# delete
def delete_node
delete(@nodename)
end
##
# publishing content on this node
# publish_content(items)
# items:: [REXML::Element]
def publish_content(items)
publish_item_to(@nodename,items)
end
##
# gets all items from the node
# get_all_items
def get_all_items
get_items_from(@nodename)
end
##
# get a count of items
# get_items(count)
# count:: [Fixnum]
def get_items(count)
get_items_from(@nodename,count)
end
##
# get all node affiliations
# get_affiliations
def get_affiliations
affiliations
end
##
# get all subscriptions on this node
# get_subscriptions
def get_subscriptions
get_subscriptions_from(@nodename)
end
##
# get all subscribers subscribed on this node
# get_subscribers
def get_subscribers
@subscriptions = subscribers(@nodename)
end
##
# subscribe to this node
# do_subscribe
def do_subscribe
subscribe_to(@nodename)
get_subscriptions
end
##
# unsubscribe from this node
# do_unsubscribe(subid = nil)
# subid:: [String]
def do_unsubscribe(subid)
unsubscribe(@nodename,subid)
end
##
# purge all items from this node
# purge_items
def purge_items
purge(@nodename)
end
private
def node_exist?
nodebrowser = PubSub::NodeBrowser.new(@stream)
nodebrowser.nodes(@jid).include?(@nodename)
end
def disco_info
end
end #class
end #module
end #module
|