Class: Tilia::CardDav::Card
- Includes:
- ICard, DavAcl::IAcl
- Defined in:
- lib/tilia/card_dav/card.rb
Overview
The Card object represents a single Card from an addressbook
Instance Method Summary collapse
-
#acl ⇒ Object
Returns a list of ACE’s for this node.
-
#acl=(_acl) ⇒ Object
Updates the ACL.
-
#content_type ⇒ Object
Returns the mime content-type.
-
#delete ⇒ Object
Deletes the card.
-
#etag ⇒ Object
Returns an ETag for this object.
-
#get ⇒ Object
Returns the VCard-formatted object.
-
#group ⇒ Object
Returns a group principal.
-
#initialize(carddav_backend, address_book_info, card_data) ⇒ Card
constructor
Constructor.
-
#last_modified ⇒ Object
Returns the last modification date as a unix timestamp.
-
#name ⇒ Object
Returns the uri for this object.
-
#owner ⇒ Object
Returns the owner principal.
-
#put(card_data) ⇒ Object
Updates the VCard-formatted object.
-
#size ⇒ Object
Returns the size of this object in bytes.
-
#supported_privilege_set ⇒ Object
Returns the list of supported privileges for this node.
Methods included from Dav::INode
Methods inherited from Dav::Node
Constructor Details
#initialize(carddav_backend, address_book_info, card_data) ⇒ Card
Constructor
32 33 34 35 36 |
# 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 |
Instance Method Details
#acl ⇒ Object
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.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# 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 |
#acl=(_acl) ⇒ Object
Updates the ACL
This method will receive a list of new ACE’s.
174 175 176 |
# File 'lib/tilia/card_dav/card.rb', line 174 def acl=(_acl) fail Dav::Exception::MethodNotAllowed, 'Changing ACL is not yet supported' end |
#content_type ⇒ Object
Returns the mime content-type
83 84 85 |
# File 'lib/tilia/card_dav/card.rb', line 83 def content_type 'text/vcard; charset=utf-8' end |
#delete ⇒ Object
Deletes the card
76 77 78 |
# File 'lib/tilia/card_dav/card.rb', line 76 def delete @carddav_backend.delete_card(@address_book_info['id'], @card_data['uri']) end |
#etag ⇒ Object
Returns an ETag for this object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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 |
#get ⇒ Object
Returns the VCard-formatted object
48 49 50 51 52 53 54 |
# 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 |
#group ⇒ Object
Returns a group principal
This must be a url to a principal, or null if there’s no owner
136 137 138 |
# File 'lib/tilia/card_dav/card.rb', line 136 def group nil end |
#last_modified ⇒ Object
Returns the last modification date as a unix timestamp
107 108 109 |
# File 'lib/tilia/card_dav/card.rb', line 107 def last_modified @card_data.key?('lastmodified') ? @card_data['lastmodified'] : nil end |
#name ⇒ Object
Returns the uri for this object
41 42 43 |
# File 'lib/tilia/card_dav/card.rb', line 41 def name @card_data['uri'] end |
#owner ⇒ Object
Returns the owner principal
This must be a url to a principal, or null if there’s no owner
127 128 129 |
# File 'lib/tilia/card_dav/card.rb', line 127 def owner @address_book_info['principaluri'] end |
#put(card_data) ⇒ Object
Updates the VCard-formatted object
60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 |
#size ⇒ Object
Returns the size of this object in bytes
114 115 116 117 118 119 120 |
# 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 |
#supported_privilege_set ⇒ Object
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.
188 189 190 |
# File 'lib/tilia/card_dav/card.rb', line 188 def supported_privilege_set nil end |