Class: Blather::Stanza::Presence::Subscription

Inherits:
Blather::Stanza::Presence show all
Defined in:
lib/blather/stanza/presence/subscription.rb

Overview

# Subscription Stanza

[RFC 3921 Section 8 - Integration of Roster Items and Presence Subscriptions](xmpp.org/rfcs/rfc3921.html#rfc.section.8)

Blather handles subscription request/response through this class. It provides a set of helper methods to quickly transform the stanza into a response.

Constant Summary

Constants inherited from Blather::Stanza::Presence

VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Blather::Stanza::Presence

#error?, import, #probe?, #subscribe?, #subscribed?, #type=, #unavailable?, #unsubscribe?, #unsubscribed?

Methods inherited from Blather::Stanza

#as_error, #error?, #from, #from=, handler_list, #id, #id=, next_id, register, #reply, #reply!, #to, #type, #type=

Methods inherited from XMPPNode

class_from_registration, #content_from, import, #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(to = nil, type = nil) ⇒ Object

Create a new Subscription stanza

Parameters:

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

    the JID to subscribe to

  • type (Symbol, nil) (defaults to: nil)

    the subscription type



21
22
23
24
25
26
# File 'lib/blather/stanza/presence/subscription.rb', line 21

def self.new(to = nil, type = nil)
  node = super()
  node.to = to
  node.type = type
  node
end

Instance Method Details

#approve!self

Transform the stanza into an approve stanza makes approving requests simple

Examples:

approve an incoming request

subscription(:request?) { |s| write_to_stream s.approve! }

Returns:

  • (self)


47
48
49
50
# File 'lib/blather/stanza/presence/subscription.rb', line 47

def approve!
  self.type = :subscribed
  reply_if_needed!
end

#cancel!self

Transform the stanza into a cancel stanza makes canceling simple

Returns:

  • (self)


76
77
78
79
# File 'lib/blather/stanza/presence/subscription.rb', line 76

def cancel!
  self.type = :unsubscribed
  reply_if_needed!
end

#inherit(node) ⇒ Object



29
30
31
32
# File 'lib/blather/stanza/presence/subscription.rb', line 29

def inherit(node)
  inherit_attrs node.attributes
  self
end

#refuse!self

Transform the stanza into a refuse stanza makes refusing requests simple

Examples:

refuse an incoming request

subscription(:request?) { |s| write_to_stream s.refuse! }

Returns:

  • (self)


58
59
60
61
# File 'lib/blather/stanza/presence/subscription.rb', line 58

def refuse!
  self.type = :unsubscribed
  reply_if_needed!
end

#request!self

Transform the stanza into a request stanza makes requests simple

Returns:

  • (self)


85
86
87
88
# File 'lib/blather/stanza/presence/subscription.rb', line 85

def request!
  self.type = :subscribe
  reply_if_needed!
end

#request?true, false

Check if the stanza is a request

Returns:

  • (true, false)


93
94
95
# File 'lib/blather/stanza/presence/subscription.rb', line 93

def request?
  self.type == :subscribe
end

#to=(to) ⇒ Object

Set the to value on the stanza

Parameters:



37
38
39
# File 'lib/blather/stanza/presence/subscription.rb', line 37

def to=(to)
  super JID.new(to).stripped
end

#unsubscribe!self

Transform the stanza into an unsubscribe stanza makes unsubscribing simple

Returns:

  • (self)


67
68
69
70
# File 'lib/blather/stanza/presence/subscription.rb', line 67

def unsubscribe!
  self.type = :unsubscribe
  reply_if_needed!
end