Class: UnsubscribeQueryStanza

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

Instance Method Summary collapse

Methods inherited from IqQueryStanza

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

Constructor Details

#initialize(params) ⇒ UnsubscribeQueryStanza

Returns a new instance of UnsubscribeQueryStanza

Raises:

  • (NoFeedToSubscribe)


3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/stanzas/unsubscribe_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)
  params[:nodes].each do |node|
    add_node(node)
  end
  @pubsub["xmlns"] = "http://jabber.org/protocol/pubsub"
  @iq.add_child(@pubsub)
end

Instance Method Details

#add_node(node) ⇒ Object



16
17
18
19
20
21
# File 'lib/stanzas/unsubscribe_query_stanza.rb', line 16

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

#nodesObject



23
24
25
# File 'lib/stanzas/unsubscribe_query_stanza.rb', line 23

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