### Home Classes Methods

### In Files

- lib/xmpp4r/observable/pubsub.rb

### Parent

Object

### Namespace

- CLASS Jabber::Observable::PubSub::AlreadySet
- CLASS Jabber::Observable::PubSub::NoService

### Methods

- ::new
- #attach!
- #create_node
- #delete_node
- #get_items_from
- #has_service?
- #is_subscribed_to?
- #my_nodes
- #node_exists?
- #publish_atom_item
- #publish_item
- #publish_simple_item
- #set_service
- #subscribe_to
- #subscribed_nodes
- #subscriptions
- #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::Observable::PubSub

Jabber::Observable::PubSub - Convenience subclass to deal with PubSub

### Public Class Methods

new(observable) click to toggle source

Creates a new PubSub object

observable | points a Jabber::Observable object

    # File lib/xmpp4r/observable/pubsub.rb, line 23
    def initialize(observable)
      @observable = observable

      @helper = @service_jid = nil
      @disco = Jabber::Discovery::Helper.new(@observable.client)
      attach!
    end

### Public Instance Methods

attach!() click to toggle source

    # File lib/xmpp4r/observable/pubsub.rb, line 31
    def attach!
      begin
        domain = Jabber::JID.new(@observable.jid).domain
        @service_jid = "pubsub." + domain
        set_service(@service_jid)
      rescue
        @helper = @service_jid = nil
      end
      return has_service?
    end

create_node(node) click to toggle source

Create a PubSub node (Lots of options still have to be encoded!)

    # File lib/xmpp4r/observable/pubsub.rb, line 91
    def create_node(node)
      raise_noservice if ! has_service?
      begin
        @helper.create_node(node)
      rescue => e
        raise e
        return nil
      end
      @my_nodes << node if defined? @my_nodes
      node
    end

delete_node(node) click to toggle source

Delete a PubSub node (Lots of options still have to be encoded!)

    # File lib/xmpp4r/observable/pubsub.rb, line 149
    def delete_node(node)
      raise_noservice if ! has_service?
      begin
        @helper.delete_node(node)
      rescue => e
        raise e
        return nil
      end
      @my_nodes.delete(node) if defined? @my_nodes
      node
    end

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

Get items from a node

    # File lib/xmpp4r/observable/pubsub.rb, line 199
    def get_items_from(node, count = nil)
      raise_noservice if ! has_service?
      @helper.get_items_from(node, count)
    end

has_service?() click to toggle source

Checks if the PubSub service is set

    # File lib/xmpp4r/observable/pubsub.rb, line 51
    def has_service?
      ! @helper.nil?
    end

is_subscribed_to?(node) click to toggle source

Return true if we're subscribed to that node

    # File lib/xmpp4r/observable/pubsub.rb, line 140
    def is_subscribed_to?(node)
      ret = false
      subscriptions.each do |sub|
        ret = true if sub.node == node and sub.attributes['subscription'] == 'subscribed'
      end
      return ret
    end

my_nodes() click to toggle source

Return an array of nodes I own

    # File lib/xmpp4r/observable/pubsub.rb, line 104
    def my_nodes
      if ! defined? @my_nodes
        ret = []
        subscriptions.each do |sub|
           ret << sub.node if sub.attributes['affiliation'] == 'owner'
        end
        @my_nodes = ret
      end
      return @my_nodes
    end

node_exists?(node) click to toggle source

Return true if a given node exists

    # File lib/xmpp4r/observable/pubsub.rb, line 116
    def node_exists?(node)
      ret = []
      if ! defined? @existing_nodes or ! @existing_nodes.include?(node)
        # We'll renew @existing_nodes if we haven't got it the first time
        reply = @disco.get_items_for(@service_jid)
        reply.items.each do |item|
          ret << item.node
        end
        @existing_nodes = ret
      end
      return @existing_nodes.include?(node)
    end

publish_atom_item(node, title, body, time = Time.now) click to toggle source

Publish atom Item. This is an item with one atom entry with title, body and time.

    # File lib/xmpp4r/observable/pubsub.rb, line 179
    def publish_atom_item(node, title, body, time = Time.now)
      raise_noservice if ! has_service?

      item = Jabber::PubSub::Item.new
      entry = REXML::Element.new('entry')
      entry.add_namespace("http://www.w3.org/2005/Atom")
      mytitle = REXML::Element.new('title')
      mytitle.text = title
      entry.add(mytitle)
      mybody = REXML::Element.new('body')
      mybody.text = body
      entry.add(mybody)
      published = REXML::Element.new("published")
      published.text = time.utc.iso8601
      entry.add(published)
      item.add(entry)
      publish_item(node, item)
    end

publish_item(node, item) click to toggle source

Publish an Item. This infers an item of Jabber::PubSub::Item kind is passed

    # File lib/xmpp4r/observable/pubsub.rb, line 162
    def publish_item(node, item)
      raise_noservice if ! has_service?
      @helper.publish_item_to(node, item)
    end

publish_simple_item(node, text) click to toggle source

Publish Simple Item. This is an item with one element and some text to it.

    # File lib/xmpp4r/observable/pubsub.rb, line 168
    def publish_simple_item(node, text)
      raise_noservice if ! has_service?

      item = Jabber::PubSub::Item.new
      xml = REXML::Element.new('value')
      xml.text = text
      item.add(xml)
      publish_item(node, item)
    end

set_service(service) click to toggle source

Sets the PubSub service. Just one service is allowed. If nil, reset.

    # File lib/xmpp4r/observable/pubsub.rb, line 56
    def set_service(service)
      if service.nil?
        @helper = @service_jid = nil
      else
        raise NotConnected, "You are not connected" if ! @observable.connected?
        raise AlreadySet, "You already have a PubSub service (#{@service_jid})." if has_service?
        @helper = Jabber::PubSub::ServiceHelper.new(@observable.client, service)
        @service_jid = service

        @helper.add_event_callback do |event|
          @observable.changed(:event)
          @observable.notify_observers(:event, event)
        end
      end
    end

subscribe_to(node) click to toggle source

Subscribe to a node.

    # File lib/xmpp4r/observable/pubsub.rb, line 73
    def subscribe_to(node)
      raise_noservice if ! has_service?
      @helper.subscribe_to(node) unless is_subscribed_to?(node)
    end

subscribed_nodes() click to toggle source

Returns an array of nodes I am subscribed to

    # File lib/xmpp4r/observable/pubsub.rb, line 130
    def subscribed_nodes
      ret = []
      subscriptions.each do |sub|
        next if sub.node.nil?
        ret << sub.node if sub.attributes['subscription'] == 'subscribed' and ! my_nodes.include?(sub.node)
      end
      return ret
    end

subscriptions() click to toggle source

Return the subscriptions we have in the configured PubSub service.

    # File lib/xmpp4r/observable/pubsub.rb, line 85
    def subscriptions
      raise_noservice if ! has_service?
      @helper.get_subscriptions_from_all_nodes()
    end

unsubscribe_from(node) click to toggle source

Unsubscribe from a node.

    # File lib/xmpp4r/observable/pubsub.rb, line 79
    def unsubscribe_from(node)
      raise_noservice if ! has_service?
      @helper.unsubscribe_from(node)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.