class Tilia::CardDav::Card
The Card
object represents a single Card
from an addressbook
Attributes
Array with information about the containing addressbook
@var array
Array with information about this Card
@var array
CardDAV backend
@var BackendBackendInterface
Public Class Methods
Constructor
@param BackendBackendInterface carddav_backend
@param array address_book_info
@param array card_data
# File lib/tilia/card_dav/card.rb, line 32 def initialize(carddav_backend, address_book_info, card_data) @carddav_backend = carddav_backend @address_book_info = address_book_info @card_data = card_data end
Public Instance Methods
Returns a list of ACE's for this node.
Each ACE has the following properties:
* 'privilege', a string such as {DAV:}read or {DAV:}write. These are currently the only supported privileges * 'principal', a url to the principal who owns the node * 'protected' (optional), indicating that this ACE is not allowed to be updated.
@return array
# File lib/tilia/card_dav/card.rb, line 150 def acl # An alternative acl may be specified through the cardData array. return @card_data['acl'] if @card_data.key?('acl') [ { 'privilege' => '{DAV:}read', 'principal' => @address_book_info['principaluri'], 'protected' => true }, { 'privilege' => '{DAV:}write', 'principal' => @address_book_info['principaluri'], 'protected' => true } ] end
Updates the ACL
This method will receive a list of new ACE's.
@param array acl @return void
# File lib/tilia/card_dav/card.rb, line 174 def acl=(_acl) fail Dav::Exception::MethodNotAllowed, 'Changing ACL is not yet supported' end
Returns the mime content-type
@return string
# File lib/tilia/card_dav/card.rb, line 83 def content_type 'text/vcard; charset=utf-8' end
Deletes the card
@return void
# File lib/tilia/card_dav/card.rb, line 76 def delete @carddav_backend.delete_card(@address_book_info['id'], @card_data['uri']) end
Returns an ETag for this object
@return string
# File lib/tilia/card_dav/card.rb, line 90 def etag if @card_data.key?('etag') return @card_data['etag'] else data = get if data.is_a?(String) return "\"#{Digest::MD5.hexdigest(data)}\"" else # We refuse to calculate the md5 if it's a stream. return nil end end end
Returns the VCard-formatted object
@return string
# File lib/tilia/card_dav/card.rb, line 48 def get # Pre-populating 'carddata' is optional. If we don't yet have it # already, we fetch it from the backend. @card_data = @carddav_backend.card(@address_book_info['id'], @card_data['uri']) unless @card_data.key?('carddata') @card_data['carddata'] end
Returns a group principal
This must be a url to a principal, or null if there's no owner
@return string|null
# File lib/tilia/card_dav/card.rb, line 136 def group nil end
Returns the last modification date as a unix timestamp
@return int
# File lib/tilia/card_dav/card.rb, line 107 def last_modified @card_data.key?('lastmodified') ? @card_data['lastmodified'] : nil end
Returns the uri for this object
@return string
# File lib/tilia/card_dav/card.rb, line 41 def name @card_data['uri'] end
Returns the owner principal
This must be a url to a principal, or null if there's no owner
@return string|null
# File lib/tilia/card_dav/card.rb, line 127 def owner @address_book_info['principaluri'] end
Updates the VCard-formatted object
@param string card_data
@return string|null
# File lib/tilia/card_dav/card.rb, line 60 def put(card_data) card_data = card_data.read unless card_data.is_a?(String) # Converting to UTF-8, if needed card_data = Dav::StringUtil.ensure_utf8(card_data) etag = @carddav_backend.update_card(@address_book_info['id'], @card_data['uri'], card_data) @card_data['carddata'] = card_data @card_data['etag'] = etag etag end
Returns the size of this object in bytes
@return int
# File lib/tilia/card_dav/card.rb, line 114 def size if @card_data.key?('size') return @card_data['size'] else return get.size end end
Returns the list of supported privileges for this node.
The returned data structure is a list of nested privileges. See SabreDAVACLPlugin::getDefaultSupportedPrivilegeSet for a simple standard structure.
If null is returned from this method, the default privilege set is used, which is fine for most common usecases.
@return array|null
# File lib/tilia/card_dav/card.rb, line 188 def supported_privilege_set nil end