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

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

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=, #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

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



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

#jidBlather::JID

Get the JID of the subscriber

Returns:



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

Parameters:



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

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

#nodeString

Get the name of the subscription node

Returns:

  • (String)


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

Parameters:

  • node (String)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

def pending?
  self.subscription == :pending
end

#subidString

Get the ID of the subscription

Returns:

  • (String)


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

Parameters:

  • subid (String)


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

Returns:

  • (Boolean)


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

def subscribed?
  self.subscription == :subscribed
end

#subscriptionVALID_TYPES?

Get the subscription type

Returns:



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

Parameters:



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

Get or create the actual subscription node

Returns:



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

Returns:

  • (Boolean)


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

def unconfigured?
  self.subscription == :unconfigured
end