|
NAMEAnyEvent::XMPP::Ext::VCard - VCards (XEP-0054 & XEP-0084) SYNOPSIS use AnyEvent::XMPP::Ext::VCard;
my $vcard = AnyEvent::XMPP::Ext::VCard->new;
$con->reg_cb (
stream_ready => sub { $vcard->hook_on ($con) }
);
$vcard->retrieve ($con, 'elmex@jabber.org', sub {
my ($jid, $vcard, $error) = @_;
if ($error) {
warn "couldn't get vcard for elmex@jabber.org: " . $error->string . "\n";
} else {
print "vCard nick for elmex@jabber.org: ".$vcard->{NICKNAME}."\n";
print "Avatar hash for elmex@jabber.org: ".$vcard->{_avatar_hash}."\n";
}
});
$vcard->store ($con, undef, { NICKNAME => 'net-xmpp2' }, sub {
my ($error) = @_;
if ($error) {
warn "upload failed: " . $error->string . "\n";
} else {
print "upload successful\n";
}
});
$disco->enable_feature ($vcard->disco_feature);
DESCRIPTIONThis extension handles setting and retrieval of the VCard and the VCard based avatars. For example see the test suite of AnyEvent::XMPP. METHODS
VCARD STRUCTUREAs there are currently no nice DOM implementations in Perl and I strongly dislike the DOM API in general this module has a simple Perl datastructure without cycles to represent the vCard. First an example: A fetched vCard hash may look like this: {
'URL' => ['http://www.ta-sa.org/'],
'ORG' => [{
'ORGNAME' => 'nethype GmbH'
}],
'N' => [{
'FAMILY' => 'Redeker'
}],
'EMAIL' => ['elmex@ta-sa.org'],
'BDAY' => ['1984-06-01'],
'FN' => ['Robin'],
'ADR' => [
{
HOME => undef,
'COUNTRY' => 'Germany'
},
{
WORK => undef,
COUNTRY => 'Germany',
LOCALITY => 'Karlsruhe'
}
],
'NICKNAME' => ['elmex'],
'ROLE' => ['Programmer']
}
The keys represent the toplevel element of a vCard, the values are always array references containig one or more values for the key. If the value is a hash reference again it's value will not be an array reference but either undef or plain values. The values of the toplevel keys are all array references because fields like "ADR" may occur multiple times. Consult XEP-0054 for an explanation what these fields mean or contain. There are special fields in this structure for handling avatars: "_avatar" contains the binary data for the avatar image. "_avatar_hash" contains the sha1 hexencoded hash of the binary image data. "_avatar_type" contains the mime type of the avatar. If you want to store the vcard you only have to set "_avatar" and "_avatar_type" if you want to store an avatar. EVENTSThe vcard extension will emit these events: TODOImplement caching, the cache stuff is just a storage hash at the moment. Or maybe drop it completly and let the application handle caching.
AUTHORRobin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" COPYRIGHT & LICENSECopyright 2007, 2008 Robin Redeker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|