class Blather::Stanza::PubSub::Subscription

# PubSub Subscription Stanza

[XEP-0060 Section 8.8 Manage Subscriptions](xmpp.org/extensions/xep-0060.html#owner-subscriptions)

@handler :pubsub_subscription

Constants

VALID_TYPES

@private

Public Class Methods

new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil) click to toggle source

Create a new subscription request node

@param [Blather::Stanza::Iq::VALID_TYPES] type the IQ type @param [String] host the host to send the request to @param [String] node the node to look for requests on @param [Blather::JID, to_s] jid the JID of the subscriber @param [String] subid the subscription ID @param [VALID_TYPES] subscription the subscription type

Calls superclass method Blather::Stanza::PubSub::new
# File lib/blather/stanza/pubsub/subscription.rb, line 24
def self.new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil)
  new_node = super(type, host)
  new_node.node = node
  new_node.jid = jid
  new_node.subid = subid
  new_node.subscription = subscription
  new_node
end

Public Instance Methods

jid() click to toggle source

Get the JID of the subscriber

@return [Blather::JID]

# File lib/blather/stanza/pubsub/subscription.rb, line 64
def jid
  JID.new(subscription_node[:jid])
end
jid=(jid) click to toggle source

Set the JID of the subscriber

@param [Blather::JID, to_s] jid

# File lib/blather/stanza/pubsub/subscription.rb, line 71
def jid=(jid)
  subscription_node[:jid] = jid
end
node() click to toggle source

Get the name of the subscription node

@return [String]

# File lib/blather/stanza/pubsub/subscription.rb, line 78
def node
  subscription_node[:node]
end
node=(node) click to toggle source

Set the name of the subscription node

@param [String] node

# File lib/blather/stanza/pubsub/subscription.rb, line 85
def node=(node)
  subscription_node[:node] = node
end
none?() click to toggle source

Check if the type is none

@return [Boolean]

# File lib/blather/stanza/pubsub/subscription.rb, line 36
def none?
  self.subscription == :none
end
pending?() click to toggle source

Check if the type is pending

@return [Boolean]

# File lib/blather/stanza/pubsub/subscription.rb, line 43
def pending?
  self.subscription == :pending
end
subid() click to toggle source

Get the ID of the subscription

@return [String]

# File lib/blather/stanza/pubsub/subscription.rb, line 92
def subid
  subscription_node[:subid]
end
subid=(subid) click to toggle source

Set the ID of the subscription

@param [String] subid

# File lib/blather/stanza/pubsub/subscription.rb, line 99
def subid=(subid)
  subscription_node[:subid] = subid
end
subscribed?() click to toggle source

Check if the type is subscribed

@return [Boolean]

# File lib/blather/stanza/pubsub/subscription.rb, line 50
def subscribed?
  self.subscription == :subscribed
end
subscription() click to toggle source

Get the subscription type

@return [VALID_TYPES, nil]

# File lib/blather/stanza/pubsub/subscription.rb, line 106
def subscription
  s = subscription_node[:subscription]
  s.to_sym if s
end
subscription=(subscription) click to toggle source

Set the subscription type

@param [VALID_TYPES, nil] subscription

# File lib/blather/stanza/pubsub/subscription.rb, line 114
def subscription=(subscription)
  if subscription && !VALID_TYPES.include?(subscription.to_sym)
    raise ArgumentError, "Invalid Type (#{type}), use: #{VALID_TYPES*' '}"
  end
  subscription_node[:subscription] = subscription
end
subscription_node() click to toggle source

Get or create the actual subscription node

@return [Blather::XMPPNode]

# File lib/blather/stanza/pubsub/subscription.rb, line 124
def subscription_node
  unless subscription = pubsub.find_first('ns:subscription', :ns => self.class.registered_ns)
    self.pubsub << (subscription = XMPPNode.new('subscription', self.document))
    subscription.namespace = self.pubsub.namespace
  end
  subscription
end
unconfigured?() click to toggle source

Check if the type is unconfigured

@return [Boolean]

# File lib/blather/stanza/pubsub/subscription.rb, line 57
def unconfigured?
  self.subscription == :unconfigured
end