Class: SubscribeQueryStanza

Inherits:
IqQueryStanza show all
Defined in:
lib/stanzas/subscribe_query_stanza.rb

Instance Method Summary (collapse)

Methods inherited from IqQueryStanza

#from, #id, #random_iq_id, #to, #to_s, #type

Constructor Details

- (SubscribeQueryStanza) initialize(params)

Returns a new instance of SubscribeQueryStanza

Raises:

  • (NoFeedToSubscribe)


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/stanzas/subscribe_query_stanza.rb', line 3

def initialize(params) 
  raise NoFeedToSubscribe if params[:nodes].nil? or params[:nodes].empty? 
  raise TooManyFeeds if params[:nodes].size > 30 
  super(params.merge({:type => :set})) 
  @pubsub = Nokogiri::XML::Node.new("pubsub", @doc) 
  @pubsub["xmlns"] = "http://jabber.org/protocol/pubsub" 
  params[:nodes].each do |node| 
    add_node(node) 
  end 
  @iq.add_child(@pubsub) 
end

Instance Method Details

- (Object) add_node(node)



15
16
17
18
19
20
# File 'lib/stanzas/subscribe_query_stanza.rb', line 15

def add_node(node)
  subscribe = Nokogiri::XML::Node.new("subscribe", @doc)
  subscribe["node"] = node
  subscribe["jid"] = from.split("/").first
  @pubsub.add_child(subscribe)
end

- (Object) nodes



22
23
24
# File 'lib/stanzas/subscribe_query_stanza.rb', line 22

def nodes
  @pubsub.children.map {|c| c["node"]}
end