class Tilia::CalDav::CalendarObject

The CalendarObject represents a single VEVENT or VTODO within a Calendar.

Public Class Methods

new(caldav_backend, calendar_info, object_data) click to toggle source

Constructor

The following properties may be passed within object_data:

* calendarid - This must refer to a calendarid from a caldavBackend
* uri - A unique uri. Only the 'basename' must be passed.
* calendardata (optional) - The iCalendar data
* etag - (optional) The etag for this object, MUST be encloded with
         double-quotes.
* size - (optional) The size of the data in bytes.
* lastmodified - (optional) format as a unix timestamp.
* acl - (optional) Use this to override the default ACL for the node.

@param BackendBackendInterface caldav_backend @param array calendar_info @param array object_data

# File lib/tilia/cal_dav/calendar_object.rb, line 42
def initialize(caldav_backend, calendar_info, object_data)
  @caldav_backend = caldav_backend

  fail ArgumentError, 'The objectData argument must contain an \'uri\' property' unless object_data.key?('uri')

  @calendar_info = calendar_info
  @object_data = object_data
end

Public Instance Methods

acl() click to toggle source

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/cal_dav/calendar_object.rb, line 160
def acl
  # An alternative acl may be specified in the object data.
  return @object_data['acl'] if @object_data.key?('acl')

  # The default ACL
  [
    {
      'privilege' => '{DAV:}read',
      'principal' => @calendar_info['principaluri'],
      'protected' => true
    },
    {
      'privilege' => '{DAV:}write',
      'principal' => @calendar_info['principaluri'],
      'protected' => true
    },
    {
      'privilege' => '{DAV:}read',
      'principal' => @calendar_info['principaluri'] + '/calendar-proxy-write',
      'protected' => true
    },
    {
      'privilege' => '{DAV:}write',
      'principal' => @calendar_info['principaluri'] + '/calendar-proxy-write',
      'protected' => true
    },
    {
      'privilege' => '{DAV:}read',
      'principal' => @calendar_info['principaluri'] + '/calendar-proxy-read',
      'protected' => true
    }
  ]
end
acl=(_acl) click to toggle source

Updates the ACL

This method will receive a list of new ACE's.

@param array acl @return void

# File lib/tilia/cal_dav/calendar_object.rb, line 200
def acl=(_acl)
  fail Dav::Exception::MethodNotAllowed, 'Changing ACL is not yet supported'
end
content_type() click to toggle source

Returns the mime content-type

@return string

# File lib/tilia/cal_dav/calendar_object.rb, line 95
def content_type
  mime = 'text/calendar; charset=utf-8'
  mime += '; component=' + @object_data['component'] unless @object_data['component'].blank?
  mime
end
delete() click to toggle source

Deletes the calendar object

@return void

# File lib/tilia/cal_dav/calendar_object.rb, line 88
def delete
  @caldav_backend.delete_calendar_object(@calendar_info['id'], @object_data['uri'])
end
etag() click to toggle source

Returns an ETag for this object.

The ETag is an arbitrary string, but MUST be surrounded by double-quotes.

@return string

# File lib/tilia/cal_dav/calendar_object.rb, line 106
def etag
  if @object_data.key?('etag')
    return @object_data['etag']
  else
    return "\"#{Digest::MD5.hexdigest(get)}\""
  end
end
get() click to toggle source

Returns the ICalendar-formatted object

@return string

# File lib/tilia/cal_dav/calendar_object.rb, line 61
def get
  # Pre-populating the 'calendardata' is optional, if we don't have it
  # already we fetch it from the backend.
  unless @object_data.key?('calendardata')
    @object_data = @caldav_backend.calendar_object(@calendar_info['id'], @object_data['uri'])
  end

  @object_data['calendardata']
end
group() click to toggle source

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/cal_dav/calendar_object.rb, line 146
def group
  nil
end
last_modified() click to toggle source

Returns the last modification date as a unix timestamp

@return int

# File lib/tilia/cal_dav/calendar_object.rb, line 117
def last_modified
  @object_data['lastmodified']
end
name() click to toggle source

Returns the uri for this object

@return string

# File lib/tilia/cal_dav/calendar_object.rb, line 54
def name
  @object_data['uri']
end
owner() click to toggle source

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/cal_dav/calendar_object.rb, line 137
def owner
  @calendar_info['principaluri']
end
put(calendar_data) click to toggle source

Updates the ICalendar-formatted object

@param string|resource calendar_data @return string

# File lib/tilia/cal_dav/calendar_object.rb, line 75
def put(calendar_data)
  calendar_data = calendar_data.read unless calendar_data.is_a?(String)

  etag = @caldav_backend.update_calendar_object(@calendar_info['id'], @object_data['uri'], calendar_data)
  @object_data['calendardata'] = calendar_data
  @object_data['etag'] = etag

  etag
end
size() click to toggle source

Returns the size of this object in bytes

@return int

# File lib/tilia/cal_dav/calendar_object.rb, line 124
def size
  if @object_data.key?('size')
    return @object_data['size']
  else
    return get.size
  end
end
supported_privilege_set() click to toggle source

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/cal_dav/calendar_object.rb, line 214
def supported_privilege_set
  nil
end