Class: Jabber::Vcard::Helper
- Inherits:
-
Object
- Object
- Jabber::Vcard::Helper
- Defined in:
- lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb
Overview
The Vcard helper retrieves vCards
Direct Known Subclasses
Class Method Summary collapse
-
.get(stream, jid = nil) ⇒ Object
Quickly initialize a Vcard helper and get a vCard.
-
.set(stream, iqvcard) ⇒ Object
Quickly initialize a Vcard helper and set your vCard.
Instance Method Summary collapse
-
#get(jid = nil) ⇒ Object
Retrieve vCard of an entity.
-
#initialize(stream) ⇒ Helper
constructor
Initialize a new Vcard helper.
-
#set(iqvcard) ⇒ Object
Set your own vCard (Clients only).
Constructor Details
#initialize(stream) ⇒ Helper
Initialize a new Vcard helper
14 15 16 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb', line 14 def initialize(stream) @stream = stream end |
Class Method Details
.get(stream, jid = nil) ⇒ Object
Quickly initialize a Vcard helper and get a vCard. See Vcard#get
72 73 74 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb', line 72 def self.get(stream, jid=nil) new(stream).get(jid) end |
.set(stream, iqvcard) ⇒ Object
Quickly initialize a Vcard helper and set your vCard. See Vcard#set
79 80 81 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb', line 79 def self.set(stream, iqvcard) new(stream).set(iqvcard) end |
Instance Method Details
#get(jid = nil) ⇒ Object
Retrieve vCard of an entity
Raises exception upon retrieval error, please catch that! (The exception is ServerError and is raisen by Stream#send_with_id.
Usage of Threads is suggested here as vCards can be very big (see /iq/vCard/PHOTO/BINVAL
).
- jid
- Jabber::JID
-
or nil (should be stripped, nil for the client’s own vCard)
- result
- Jabber::IqVcard
-
or nil (nil results may be handled as empty vCards)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb', line 30 def get(jid=nil) res = nil request = Iq.new(:get, jid) request.from = @stream.jid # Enable components to use this request.add(IqVcard.new) @stream.send_with_id(request) { |answer| # No check for sender or queryns needed (see send_with_id) if answer.type == :result res = answer.vcard true else false end } res end |
#set(iqvcard) ⇒ Object
Set your own vCard (Clients only)
Raises exception when setting fails
Usage of Threads suggested here, too. The function waits for approval from the server.
- iqvcard
- Jabber::IqVcard
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/vcard/helper/vcard.rb', line 56 def set(iqvcard) iq = Iq.new(:set) iq.add(iqvcard) @stream.send_with_id(iq) { |answer| if answer.type == :result true else false end } end |