Class: Jabber::PubSub::NodeHelper

Inherits:
ServiceHelper show all
Defined in:
lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ServiceHelper

#add_event_callback, #create_collection_node, #get_config_from, #get_items_from, #get_options_from, #get_subscribers_from, #get_subscriptions_from, #get_subscriptions_from_all_nodes, #publish_item_to, #publish_item_with_id_to, #purge_items_from, #set_config_for, #set_options_for, #subscribe_to, #to_s, #unsubscribe_from

Constructor Details

#initialize(stream, jid, nodename = nil, create_if_not_exist = true) ⇒ NodeHelper

creates a new node new(client,service,nodename)

stream
Jabber::Stream
jid
String

(jid of the pubsub service)

nodename
String


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 27

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 not 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

Instance Attribute Details

#jidObject (readonly)

Returns the value of attribute jid.



19
20
21
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 19

def jid
  @jid
end

#my_subscriptionsObject (readonly)

Returns the value of attribute my_subscriptions.



20
21
22
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 20

def my_subscriptions
  @my_subscriptions
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 18

def name
  @name
end

#nodenameObject (readonly)

Returns the value of attribute nodename.



17
18
19
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 17

def nodename
  @nodename
end

Instance Method Details

#create_node(configuration = Jabber::PubSub::NodeConfig.new) ⇒ Object

creates the node create(configuration=nil)

configuration
Jabber::XData


46
47
48
49
50
51
52
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 46

def create_node(configuration = Jabber::PubSub::NodeConfig.new)
  unless node_exist?
    super(@nodename,configuration)
  else
    false
  end
end

#delete_nodeObject

deletes the node delete



74
75
76
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 74

def delete_node
  delete(@nodename)
end

#do_subscribeObject

subscribe to this node do_subscribe



125
126
127
128
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 125

def do_subscribe
  subscribe_to(@nodename)
  get_subscriptions
end

#do_unsubscribe(subid) ⇒ Object

unsubscribe from this node do_unsubscribe(subid = nil)

subid
String


134
135
136
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 134

def do_unsubscribe(subid)
  unsubscribe(@nodename,subid)
end

#get_affiliationsObject

get all node affiliations get_affiliations



104
105
106
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 104

def get_affiliations
  affiliations
end

#get_all_itemsObject

gets all items from the node get_all_items



89
90
91
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 89

def get_all_items
  items(@nodename)
end

#get_configuration(subid = nil) ⇒ Object

get the configuration of the node get_configuration(configuration=nil)

configuration
Jabber::XData


58
59
60
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 58

def get_configuration(subid = nil)
  get_options(@nodename, subid)
end

#get_items(count) ⇒ Object

get a count of items get_items(count)

count
Fixnum


97
98
99
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 97

def get_items(count)
  items(@nodename,count)
end

#get_subscribersObject

get all subscribers subscribed on this node get_subscribers



118
119
120
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 118

def get_subscribers
  @subscriptions = subscribers(@nodename)
end

#get_subscriptionsObject

get all subscriptions on this node get_subscriptions



111
112
113
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 111

def get_subscriptions
  get_subscriptions_from(@nodename)
end

#publish_content(items) ⇒ Object

publishing content on this node publish_content(items)

items
REXML::Element


82
83
84
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 82

def publish_content(items)
  publish_item_to(@nodename,items)
end

#purge_itemsObject

purge all items from this node purge_items



141
142
143
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 141

def purge_items
  purge(@nodename)
end

#set_configuration(configuration, subid = nil) ⇒ Object

set the configuration of the node set_configuration(configuration=nil)

configuration
Jabber::XData
subid
String

default is nil



67
68
69
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb', line 67

def set_configuration(configuration,subid = nil)
  set_options(@nodename, configuration, subid)
end