Class: Blather::Stanza::Iq::Vcard

Inherits:
Blather::Stanza::Iq show all
Defined in:
lib/blather/stanza/iq/vcard.rb

Overview

# Vcard Stanza

[XEP-0054 vcard-temp](xmpp.org/extensions/xep-0054.html)

This is a base class for any vcard based Iq stanzas. It provides a base set of methods for working with vcard stanzas

Examples:

Retrieving One’s vCard

iq = Blather::Stanza::Iq::Vcard.new :get
client.write_with_handler iq do |response|
  puts response.vcard
end

Updating One’s vCard

iq = Blather::Stanza::Iq::Vcard.new :set
iq.vcard['NICKNAME'] = 'Romeo'
client.write_with_handler iq do |response|
  puts response
end

Viewing Another User’s vCard

iq = Blather::Stanza::Iq::Vcard.new :get, '[email protected]'
client.write_with_handler iq do |response|
  puts response.vcard
end

Defined Under Namespace

Classes: Vcard

Constant Summary

Constants inherited from Blather::Stanza::Iq

VALID_TYPES

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::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 = nil, to = nil, id = nil) ⇒ Object

Overrides the parent method to ensure a vcard node is created



39
40
41
42
43
# File 'lib/blather/stanza/iq/vcard.rb', line 39

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

Instance Method Details

#inherit(node) ⇒ Object

Overrides the parent method to ensure the current vcard node is destroyed

See Also:

  • Blather::Stanza::Iq#inherit


48
49
50
51
52
# File 'lib/blather/stanza/iq/vcard.rb', line 48

def inherit(node)
  vcard.remove
  super
  self
end

#vcardVcard::Vcard

Find or create vcard node

Returns:



57
58
59
# File 'lib/blather/stanza/iq/vcard.rb', line 57

def vcard
  Vcard.find_or_create self
end

#vcard=(info) ⇒ Vcard::Vcard

Replaces vcard node

Parameters:

  • info (Vcard::Vcard, XML::Node)

    the stanza’s new vcard node

Returns:



66
67
68
69
70
# File 'lib/blather/stanza/iq/vcard.rb', line 66

def vcard=(info)
  vcard.remove
  self << info
  Vcard.find_or_create self
end