Skip to content

Commit

Permalink
Added get_item_from to pubsub helper
Browse files Browse the repository at this point in the history
  • Loading branch information
BRIMIL01 committed Mar 13, 2012
1 parent 2dc321a commit 1aa31fc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/xmpp4r/pubsub/helper/servicehelper.rb
Expand Up @@ -184,6 +184,30 @@ def get_items_from(node, count=nil, subid=nil)
res
end

##
# gets an item from a pubsub node
# node:: [String]
# message_id:: [String]
# return:: [Hash] { id => [Jabber::PubSub::Item] }
def get_item_from(node, message_id)
iq = basic_pubsub_query(:get)
items = Jabber::PubSub::Items.new
items.node = node
item = Jabber::PubSub::Item.new
item.id = message_id
items.add(item)
iq.pubsub.add(items)
res = nil
@stream.send_with_id(iq) { |reply|
if reply.kind_of?(Iq) and reply.pubsub and reply.pubsub.first_element('items')
item = reply.pubsub.first_element('items').first_element('item')
return item.children.first if item.children.first
end
true
}
res
end

##
# NOTE: this method sends only one item per publish request because some services
# may not allow batch processing. Maybe this will changed in the future?
Expand Down

0 comments on commit 1aa31fc

Please sign in to comment.