Class: Blather::Stanza
- Inherits:
-
XMPPNode
- Object
- Nokogiri::XML::Node
- XMPPNode
- Blather::Stanza
- Defined in:
- lib/blather/stanza.rb,
lib/blather/stanza/x.rb,
lib/blather/stanza/iq.rb,
lib/blather/stanza/disco.rb,
lib/blather/stanza/pubsub.rb,
lib/blather/stanza/message.rb,
lib/blather/stanza/iq/query.rb,
lib/blather/stanza/iq/vcard.rb,
lib/blather/stanza/presence.rb,
lib/blather/stanza/iq/roster.rb,
lib/blather/stanza/iq/command.rb,
lib/blather/stanza/pubsub/event.rb,
lib/blather/stanza/pubsub/items.rb,
lib/blather/stanza/pubsub_owner.rb,
lib/blather/stanza/pubsub/create.rb,
lib/blather/stanza/pubsub/errors.rb,
lib/blather/stanza/pubsub/publish.rb,
lib/blather/stanza/pubsub/retract.rb,
lib/blather/stanza/presence/status.rb,
lib/blather/stanza/disco/disco_info.rb,
lib/blather/stanza/pubsub/subscribe.rb,
lib/blather/stanza/disco/disco_items.rb,
lib/blather/stanza/pubsub/unsubscribe.rb,
lib/blather/stanza/pubsub_owner/purge.rb,
lib/blather/stanza/pubsub/affiliations.rb,
lib/blather/stanza/pubsub/subscription.rb,
lib/blather/stanza/pubsub_owner/delete.rb,
lib/blather/stanza/pubsub/subscriptions.rb,
lib/blather/stanza/presence/subscription.rb
Overview
# Base XMPP Stanza
All stanzas inherit this class. It provides a set of methods and helpers common to all XMPP Stanzas
Defined Under Namespace
Classes: Disco, DiscoInfo, DiscoItems, Iq, Message, Presence, PubSub, PubSubErrors, PubSubItem, PubSubOwner, X
Constant Summary collapse
- @@last_id =
0
- @@handler_list =
[]
Constants inherited from XMPPNode
Class Method Summary collapse
-
.handler_list ⇒ Array<Symbol>
The handler stack for the current stanza class.
-
.next_id ⇒ String
Helper method that creates a unique ID for stanzas.
-
.register(handler, name = nil, ns = nil) ⇒ Object
Registers a callback onto the callback stack.
Instance Method Summary collapse
-
#as_error(name, type, text = nil, extras = []) ⇒ Blather::StanzaError
Create an error stanza from the current stanza.
-
#error? ⇒ true, false
Check if the stanza is an error stanza.
-
#from ⇒ Blather::JID?
Get the stanza’s from.
-
#from=(from) ⇒ Object
Set the stanza’s from field.
-
#id ⇒ String?
Get the stanza’s ID.
-
#id=(id) ⇒ Object
Set the stanza’s ID.
-
#reply ⇒ Blather::Stanza
Creates a copy with to and from swapped.
-
#reply! ⇒ self
Swaps from and to.
-
#to ⇒ Blather::JID?
Get the stanza’s to.
-
#to=(to) ⇒ Object
Set the stanza’s to field.
-
#type ⇒ Symbol?
Get the stanza’s type.
-
#type=(type) ⇒ Object
Set the stanza’s type.
Methods inherited from XMPPNode
class_from_registration, #content_from, import, #inherit, #inherit_attrs, #inspect, #namespace=, #namespace_href, new, #nokogiri_namespace=, #read_attr, #read_content, #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
.handler_list ⇒ Array<Symbol>
The handler stack for the current stanza class
36 37 38 |
# File 'lib/blather/stanza.rb', line 36 def self.handler_list @@handler_list end |
.next_id ⇒ String
Helper method that creates a unique ID for stanzas
43 44 45 46 |
# File 'lib/blather/stanza.rb', line 43 def self.next_id @@last_id += 1 'blather%04x' % @@last_id end |
.register(handler, name = nil, ns = nil) ⇒ Object
Registers a callback onto the callback stack
24 25 26 27 28 29 30 31 |
# File 'lib/blather/stanza.rb', line 24 def self.register(handler, name = nil, ns = nil) @@handler_list << handler self.handler_hierarchy ||= [:stanza] self.handler_hierarchy.unshift handler name = name || self.registered_name || handler super name, ns end |
Instance Method Details
#as_error(name, type, text = nil, extras = []) ⇒ Blather::StanzaError
Create an error stanza from the current stanza
the error
135 136 137 |
# File 'lib/blather/stanza.rb', line 135 def as_error(name, type, text = nil, extras = []) StanzaError.new self, name, type, text, extras end |
#error? ⇒ true, false
Check if the stanza is an error stanza
51 52 53 |
# File 'lib/blather/stanza.rb', line 51 def error? self.type == :error end |
#from ⇒ Blather::JID?
Get the stanza’s from
101 102 103 |
# File 'lib/blather/stanza.rb', line 101 def from JID.new(self[:from]) if self[:from] end |
#from=(from) ⇒ Object
Set the stanza’s from field
108 109 110 |
# File 'lib/blather/stanza.rb', line 108 def from=(from) write_attr :from, from end |
#id ⇒ String?
Get the stanza’s ID
73 74 75 |
# File 'lib/blather/stanza.rb', line 73 def id read_attr :id end |
#id=(id) ⇒ Object
Set the stanza’s ID
80 81 82 |
# File 'lib/blather/stanza.rb', line 80 def id=(id) write_attr :id, id end |
#reply ⇒ Blather::Stanza
Creates a copy with to and from swapped
58 59 60 |
# File 'lib/blather/stanza.rb', line 58 def reply self.dup.reply! end |
#reply! ⇒ self
Swaps from and to
65 66 67 68 |
# File 'lib/blather/stanza.rb', line 65 def reply! self.to, self.from = self.from, self.to self end |
#to ⇒ Blather::JID?
Get the stanza’s to
87 88 89 |
# File 'lib/blather/stanza.rb', line 87 def to JID.new(self[:to]) if self[:to] end |
#to=(to) ⇒ Object
Set the stanza’s to field
94 95 96 |
# File 'lib/blather/stanza.rb', line 94 def to=(to) write_attr :to, to end |
#type ⇒ Symbol?
Get the stanza’s type
115 116 117 |
# File 'lib/blather/stanza.rb', line 115 def type read_attr :type, :to_sym end |
#type=(type) ⇒ Object
Set the stanza’s type
122 123 124 |
# File 'lib/blather/stanza.rb', line 122 def type=(type) write_attr :type, type end |