### Home Classes Methods

### In Files

- lib/xmpp4r/pubsub/helper/servicehelper.rb

### Parent

Object

### Methods

- ::new
- #add_event_callback
- #create_collection_node
- #create_node
- #delete_item_from
- #delete_node
- #get_affiliations
- #get_config_from
- #get_items_from
- #get_options_from
- #get_subids_for
- #get_subscribers_from
- #get_subscriptions_from
- #get_subscriptions_from_all_nodes
- #publish_item_to
- #publish_item_with_id_to
- #purge_items_from
- #set_affiliations
- #set_config_for
- #set_options_for
- #subscribe_to
- #to_s
- #unsubscribe_from

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::PubSub::ServiceHelper

A Helper representing a PubSub Service

### Public Class Methods

new(stream, pubsubjid) click to toggle source

Creates a new representation of a pubsub service

stream

Jabber::Stream

pubsubjid

String

  or [Jabber::JID]

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 61
    def initialize(stream, pubsubjid)
      @stream = stream
      @pubsubjid = pubsubjid
      @event_cbs = CallbackList.new
      @stream.add_message_callback(200,self) { |message|
        handle_message(message)
      }
    end

### Public Instance Methods

add_event_callback(prio = 200, ref = nil, &block) click to toggle source

Register callbacks for incoming events (i.e. Message stanzas containing) PubSub notifications

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 457
    def add_event_callback(prio = 200, ref = nil, &block)
      @event_cbs.add(prio, ref, block)
    end

create_collection_node(node = nil, configure = Jabber::PubSub::NodeConfig.new) click to toggle source

Create a new collection node on the pubsub service

node

String

  the node name - otherwise you get an automatically generated one (in most cases)

configure

Jabber::PubSub::NodeConfig

  if you want to configure your node (default nil)

return

String

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 291
    def create_collection_node(node = nil, configure = Jabber::PubSub::NodeConfig.new)
      if configure.options['pubsub#node_type'] && configure.options['pubsub#node_type'] != 'collection'
        raise Jabber::ArgumentError, "Invalid node_type specified in node configuration. Either do not specify one, or use 'collection'"
      end
      configure.options = configure.options.merge({'pubsub#node_type' => 'collection'})
      create_node(node, configure)
    end

create_node(node = nil, configure = Jabber::PubSub::NodeConfig.new) click to toggle source

Create a new node on the pubsub service

node

String

  the node name - otherwise you get a automatically generated one (in most cases)

configure

Jabber::PubSub::NodeConfig

  if you want to configure your node (default nil)

return

String

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 267
    def create_node(node = nil, configure = Jabber::PubSub::NodeConfig.new)
      rnode = nil
      iq = basic_pubsub_query(:set)
      iq.pubsub.add(REXML::Element.new('create')).attributes['node'] = node
      if configure
        if configure.kind_of?(Jabber::PubSub::NodeConfig)
          iq.pubsub.add(configure)
        end
      end

      @stream.send_with_id(iq) do |reply|
        if reply.kind_of?(Jabber::Iq) and reply.type == :result
          rnode = node
        end
      end

      rnode
    end

delete_item_from(node, item_id) click to toggle source

deletes an item from a persistent node

node

String

item_id

String

  or [Array] of [String]

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 230
    def delete_item_from(node, item_id)
      iq = basic_pubsub_query(:set)
      retract = iq.pubsub.add(Jabber::PubSub::Retract.new)
      retract.node = node

      if item_id.kind_of? Array
        item_id.each { |id|
          xmlitem = Jabber::PubSub::Item.new
          xmlitem.id = id
          retract.add(xmlitem)
        }
      else
        xmlitem = Jabber::PubSub::Item.new
        xmlitem.id = item_id
        retract.add(xmlitem)
      end

      @stream.send_with_id(iq)
    end

delete_node(node) click to toggle source

Delete a pubsub node

node

String

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 328
    def delete_node(node)
      iq = basic_pubsub_query(:set,true)
      iq.pubsub.add(REXML::Element.new('delete')).attributes['node'] = node
      @stream.send_with_id(iq)
    end

get_affiliations(node = nil) click to toggle source

shows the affiliations on a pubsub service

node

String

return

Hash

  of { node => symbol }

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 352
    def get_affiliations(node = nil)
      iq = basic_pubsub_query(:get)
      affiliations = iq.pubsub.add(REXML::Element.new('affiliations'))
      affiliations.attributes['node'] = node
      res = nil
      @stream.send_with_id(iq) { |reply|
        if reply.pubsub.first_element('affiliations')
          res = {}
          reply.pubsub.first_element('affiliations').each_element('affiliation') do |affiliation|
            # TODO: This should be handled by an affiliation element class
            aff = case affiliation.attributes['affiliation']
                    when 'owner' then :owner
                    when 'publisher' then :publisher
                    when 'none' then :none
                    when 'outcast' then :outcast
                    else nil
                  end
            res[affiliation.attributes['node']] = aff
          end
        end
        true
      }
      res
    end

get_config_from(node) click to toggle source

get configuration from a node

node

String

return

Jabber::PubSub::Configure

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 303
    def get_config_from(node)
      iq = basic_pubsub_query(:get, true)
      iq.pubsub.add(Jabber::PubSub::OwnerNodeConfig.new(node))
      ret = nil
      @stream.send_with_id(iq) do |reply|
        ret = reply.pubsub.first_element('configure')
      end
      ret
    end

get_items_from(node, count=nil, subid=nil) click to toggle source

gets all items from a pubsub node

node

String

count

Fixnum

subid

String

return

Hash

  { id => [Jabber::PubSub::Item] }

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 159
    def get_items_from(node, count=nil, subid=nil)
      if subid.nil?
        # Hm... no subid passed. Let's see if we can provide one.
        subids = get_subids_for(node)
        if ! subids.empty?
          # If more than one, sorry. We'll just respect the first.
          subid = subids[0]
        end
      end
      iq = basic_pubsub_query(:get)
      items = Jabber::PubSub::Items.new
      items.max_items = count
      items.subid = subid unless subid.nil?  # if subid is still nil, we haven't any... why bother?
      items.node = node
      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')
          res = {}
          reply.pubsub.first_element('items').each_element('item') do |item|
            res[item.attributes['id']] = item.children.first if item.children.first
          end
        end
        true
      }
      res
    end

get_options_from(node, jid, subid = nil) click to toggle source

get options from a subscription

node

String

jid

Jabber::JID

  or [String]

subid

String

  or nil

return

Jabber::PubSub::OwnerConfigure

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 419
    def get_options_from(node, jid, subid = nil)
      iq = basic_pubsub_query(:get)
      iq.pubsub.add(Jabber::PubSub::SubscriptionConfig.new(node, jid.kind_of?(String) ? Jabber::JID.new(jid).strip: jid.strip, subid))
      ret = nil
      @stream.send_with_id(iq) do |reply|
        ret = reply.pubsub.first_element('options')
      end
      ret
    end

get_subids_for(node) click to toggle source

get subids for a passed node

return

Array

  of subids

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 92
    def get_subids_for(node)
      ret = []
      get_subscriptions_from_all_nodes.each do |subscription|
        if subscription.node == node
          ret << subscription.subid
        end
      end
      return ret
    end

get_subscribers_from(node) click to toggle source

shows all jids of subscribers of a node

node

String

return

Array

  of [String]

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 404
    def get_subscribers_from(node)
      res = []
      get_subscriptions_from(node).each { |sub|
        res << sub.jid
      }
      res
    end

get_subscriptions_from(node) click to toggle source

shows all subscriptions on the given node

node

String

return

Array

  of [Jabber::Pubsub::Subscription]

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 381
    def get_subscriptions_from(node)
      iq = basic_pubsub_query(:get)
      entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
      entities.attributes['node'] = node
      res = nil
      @stream.send_with_id(iq) { |reply|
        if reply.pubsub.first_element('subscriptions')
          res = []
          if reply.pubsub.first_element('subscriptions').attributes['node'] == node
            reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription|
            res << PubSub::Subscription.import(subscription)
            }
          end
        end
        true
      }
      res
    end

get_subscriptions_from_all_nodes() click to toggle source

get all subscriptions on a pubsub component

return

Hash

  of [PubSub::Subscription]

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 73
    def get_subscriptions_from_all_nodes
      iq = basic_pubsub_query(:get)
      entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
      res = nil
      @stream.send_with_id(iq) { |reply|
        if reply.pubsub.first_element('subscriptions')
          res = []
          reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription|
            res << Jabber::PubSub::Subscription.import(subscription)
          }
        end
      }

      res
    end

publish_item_to(node,item) click to toggle source

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?

node

String

item

Jabber::PubSub::Item

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 193
    def publish_item_to(node,item)
      iq = basic_pubsub_query(:set)
      publish = iq.pubsub.add(REXML::Element.new('publish'))
      publish.attributes['node'] = node

      if item.kind_of?(Jabber::PubSub::Item)
        publish.add(item)
        @stream.send_with_id(iq)
      end
    end

publish_item_with_id_to(node,item,id) click to toggle source

node

String

item

REXML::Element

id

String

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 209
    def publish_item_with_id_to(node,item,id)
      iq = basic_pubsub_query(:set)
      publish = iq.pubsub.add(REXML::Element.new('publish'))
      publish.attributes['node'] = node

      if item.kind_of?(REXML::Element)
        xmlitem = Jabber::PubSub::Item.new
        xmlitem.id = id
        xmlitem.import(item)
        publish.add(xmlitem)
      else
        raise "given item is not a proper xml document or Jabber::PubSub::Item"
      end
      @stream.send_with_id(iq)
    end

purge_items_from(node) click to toggle source

purges all items on a persistent node

node

String

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 254
    def purge_items_from(node)
      iq = basic_pubsub_query(:set, true)
      purge = REXML::Element.new('purge')
      purge.attributes['node'] = node
      iq.pubsub.add(purge)
      @stream.send_with_id(iq)
    end

set_affiliations(node, jid, role = 'publisher') click to toggle source

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 334
    def set_affiliations(node, jid, role = 'publisher')
      iq = basic_pubsub_query(:set, true)
      affiliations = iq.pubsub.add(REXML::Element.new('affiliations'))
      affiliations.attributes['node'] = node
      affiliation = affiliations.add(REXML::Element.new('affiliation'))
      affiliation.attributes['jid'] = jid.to_s
      affiliation.attributes['affiliation'] = role.to_s
      res = nil
      @stream.send_with_id(iq) { |reply|
        true
      }
      res
    end

set_config_for(node, config) click to toggle source

set configuration for a node

node

String

options

Jabber::PubSub::NodeConfig

return | true on success

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 318
    def set_config_for(node, config)
      iq = basic_pubsub_query(:set, true)
      iq.pubsub.add(config)
      @stream.send_with_id(iq)
    end

set_options_for(node, jid, options, subid = nil) click to toggle source

set options for a subscription

node

String

jid

Jabber::JID

  or [String]

options | [Jabber::PubSub::SubscriptionConfig} specifying configuration options

subid

String

  or nil

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 436
    def set_options_for(node, jid, options, subid = nil)
      iq = basic_pubsub_query(:set)
      iq.pubsub.add(Jabber::PubSub::SubscriptionConfig.new(node, jid.kind_of?(String) ? Jabber::JID.new(jid).strip: jid.strip, options, subid))
      ret = false
      @stream.send_with_id(iq) do  |reply|
        ret = ( reply.type == :result )
      end

      ret
    end

subscribe_to(node) click to toggle source

subscribe to a node

node

String

return

Hash

  of { attributename => value }

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 106
    def subscribe_to(node)
      iq = basic_pubsub_query(:set)
      sub = REXML::Element.new('subscribe')
      sub.attributes['node'] = node
      sub.attributes['jid'] = @stream.jid.strip.to_s
      iq.pubsub.add(sub)
      res = nil
      @stream.send_with_id(iq) do |reply|
        pubsubanswer = reply.pubsub
        if pubsubanswer.first_element('subscription')
          res = PubSub::Subscription.import(pubsubanswer.first_element('subscription'))
        end
      end # @stream.send_with_id(iq)
      res
    end

to_s() click to toggle source

String representation

result

String

  The PubSub service's JID

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 450
    def to_s
      @pubsubjid.to_s
    end

unsubscribe_from(node, subid=nil) click to toggle source

Unsubscribe from a node with an optional subscription id

May raise ServerError

node

String

subid

String

  or nil (not supported)

return | true

    # File lib/xmpp4r/pubsub/helper/servicehelper.rb, line 129
    def unsubscribe_from(node, subid=nil)
      ret = []
      if subid.nil?
        subids = get_subids_for(node)
      else
        subids = [ subid ]
      end
      subids << nil if subids.empty?
      subids.each do |sid|
        iq = basic_pubsub_query(:set)
        unsub = PubSub::Unsubscribe.new
        unsub.node = node
        unsub.jid = @stream.jid.strip
        unsub.subid = sid
        iq.pubsub.add(unsub)
        res = false
        @stream.send_with_id(iq) { |reply|
          res = reply.kind_of?(Jabber::Iq) and reply.type == :result
        } # @stream.send_with_id(iq)
        ret << res
      end
      ret
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.