Class: Blather::Stanza::PubSub::Subscription

Inherits:
Blather::Stanza::PubSub show all
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

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Blather::Stanza::PubSub

import, #inherit, #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

Parameters:

  • type (Blather::Stanza::Iq::VALID_TYPES) (defaults to: :result)

    the IQ type

  • host (String) (defaults to: nil)

    the host to send the request to

  • node (String) (defaults to: nil)

    the node to look for requests on

  • jid (Blather::JID, #to_s) (defaults to: nil)

    the JID of the subscriber

  • subid (String) (defaults to: nil)

    the subscription ID

  • subscription (VALID_TYPES) (defaults to: nil)

    the subscription type



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

#jidBlather::JID

Get the JID of the subscriber

Returns:



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

Parameters:



70
71
72
# File 'lib/blather/stanza/pubsub/subscription.rb', line 70

def jid=(jid)
  subscription_node[:jid] = jid
end

#nodeString

Get the name of the subscription node

Returns:

  • (String)


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

Parameters:

  • node (String)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


42
43
44
# File 'lib/blather/stanza/pubsub/subscription.rb', line 42

def pending?
  self.subscription == :pending
end

#subidString

Get the ID of the subscription

Returns:

  • (String)


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

Parameters:

  • subid (String)


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

Returns:

  • (Boolean)


49
50
51
# File 'lib/blather/stanza/pubsub/subscription.rb', line 49

def subscribed?
  self.subscription == :subscribed
end

#subscriptionVALID_TYPES?

Get the subscription type

Returns:



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

Parameters:



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_nodeBlather::XMPPNode

Get or create the actual subscription node

Returns:



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

Returns:

  • (Boolean)


56
57
58
# File 'lib/blather/stanza/pubsub/subscription.rb', line 56

def unconfigured?
  self.subscription == :unconfigured
end