Class: Blather::Stanza::PubSub::Subscription
- Inherits:
-
Blather::Stanza::PubSub
- Object
- Nokogiri::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
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=, next_id, register, #reply, #reply!, #to, #to=, #type, #type=
Methods inherited from XMPPNode
class_from_registration, #content_from, import, #inherit, #inherit_attrs, #inspect, #namespace=, #namespace_href, #nokogiri_namespace=, #read_attr, #read_content, register, #remove_child, #remove_children, #set_content_for, #to_stanza, #write_attr
Methods inherited from Nokogiri::XML::Node
#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath
Class Method Details
.new(type = :result, host = nil, node = nil, jid = nil, subid = nil, subscription = nil) ⇒ Object
Create a new subscription request node
23 24 25 26 27 28 29 30 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 23 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
63 64 65 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 63 def jid JID.new(subscription_node[:jid]) end |
#jid=(jid) ⇒ Object
Set the JID of the subscriber
70 71 72 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 70 def jid=(jid) subscription_node[:jid] = jid end |
#node ⇒ String
Get the name of the subscription node
77 78 79 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 77 def node subscription_node[:node] end |
#node=(node) ⇒ Object
Set the name of the subscription node
84 85 86 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 84 def node=(node) subscription_node[:node] = node end |
#none? ⇒ Boolean
Check if the type is none
35 36 37 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 35 def none? self.subscription == :none end |
#pending? ⇒ Boolean
Check if the type is pending
42 43 44 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 42 def pending? self.subscription == :pending end |
#subid ⇒ String
Get the ID of the subscription
91 92 93 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 91 def subid subscription_node[:subid] end |
#subid=(subid) ⇒ Object
Set the ID of the subscription
98 99 100 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 98 def subid=(subid) subscription_node[:subid] = subid end |
#subscribed? ⇒ Boolean
Check if the type is subscribed
49 50 51 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 49 def subscribed? self.subscription == :subscribed end |
#subscription ⇒ VALID_TYPES?
Get the subscription type
105 106 107 108 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 105 def subscription s = subscription_node[:subscription] s.to_sym if s end |
#subscription=(subscription) ⇒ Object
Set the subscription type
113 114 115 116 117 118 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 113 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
123 124 125 126 127 128 129 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 123 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
56 57 58 |
# File 'lib/blather/stanza/pubsub/subscription.rb', line 56 def unconfigured? self.subscription == :unconfigured end |