Class: Blather::Stanza::PubSub::Subscription
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Niceogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Iq
- Blather::Stanza::PubSub
- Blather::Stanza::PubSub::Subscription
- Defined in:
- lib/blather/stanza/pubsub/subscription.rb
Overview
# PubSub Subscription Stanza
[XEP-0060 Section 8.8 Manage Subscriptions](xmpp.org/extensions/xep-0060.html#owner-subscriptions)
Constant Summary collapse
- VALID_TYPES =
[:none, :pending, :subscribed, :unconfigured]
Constants inherited from XMPPNode
Instance Attribute Summary
Attributes inherited from Blather::Stanza
Class Method Summary collapse
-
.new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil) ⇒ Object
Create a new subscription request node.
Instance Method Summary collapse
-
#jid ⇒ Blather::JID
Get the JID of the subscriber.
-
#jid=(jid) ⇒ Object
Set the JID of the subscriber.
-
#node ⇒ String
Get the name of the subscription node.
-
#node=(node) ⇒ Object
Set the name of the subscription node.
-
#none? ⇒ Boolean
Check if the type is none.
-
#pending? ⇒ Boolean
Check if the type is pending.
-
#subid ⇒ String
Get the ID of the subscription.
-
#subid=(subid) ⇒ Object
Set the ID of the subscription.
-
#subscribed? ⇒ Boolean
Check if the type is subscribed.
-
#subscription ⇒ VALID_TYPES?
Get the subscription type.
-
#subscription=(subscription) ⇒ Object
Set the subscription type.
-
#subscription_node ⇒ Blather::XMPPNode
Get or create the actual subscription node.
-
#unconfigured? ⇒ Boolean
Check if the type is unconfigured.
Methods inherited from Blather::Stanza::PubSub
Methods inherited from Iq
#error?, #get?, import, #reply!, #result?, #set?, #type=
Methods inherited from Blather::Stanza
#as_error, #error?, #from, #from=, handler_list, #id, #id=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza
Constructor Details
This class inherits a constructor from Blather::Stanza
Class Method Details
.new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil) ⇒ Object
Create a new subscription request node
24 25 26 27 28 29 30 31 |
# 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 |
Instance Method Details
#jid ⇒ Blather::JID
Get the JID of the subscriber
64 65 66 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 64 def jid JID.new(subscription_node[:jid]) end |
#jid=(jid) ⇒ Object
Set the JID of the subscriber
71 72 73 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 71 def jid=(jid) subscription_node[:jid] = jid end |
#node ⇒ String
Get the name of the subscription node
78 79 80 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 78 def node subscription_node[:node] end |
#node=(node) ⇒ Object
Set the name of the subscription node
85 86 87 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 85 def node=(node) subscription_node[:node] = node end |
#none? ⇒ Boolean
Check if the type is none
36 37 38 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 36 def none? self.subscription == :none end |
#pending? ⇒ Boolean
Check if the type is pending
43 44 45 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 43 def pending? self.subscription == :pending end |
#subid ⇒ String
Get the ID of the subscription
92 93 94 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 92 def subid subscription_node[:subid] end |
#subid=(subid) ⇒ Object
Set the ID of the subscription
99 100 101 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 99 def subid=(subid) subscription_node[:subid] = subid end |
#subscribed? ⇒ Boolean
Check if the type is subscribed
50 51 52 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 50 def subscribed? self.subscription == :subscribed end |
#subscription ⇒ VALID_TYPES?
Get the subscription type
106 107 108 109 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 106 def subscription s = subscription_node[:subscription] s.to_sym if s end |
#subscription=(subscription) ⇒ Object
Set the subscription type
114 115 116 117 118 119 |
# 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 ⇒ Blather::XMPPNode
Get or create the actual subscription node
124 125 126 127 128 129 130 |
# 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? ⇒ Boolean
Check if the type is unconfigured
57 58 59 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 57 def unconfigured? self.subscription == :unconfigured end |