class Tilia::CalDav::Subscriptions::Subscription

Subscription Node

This node represents a subscription.

Public Class Methods

new(caldav_backend, subscription_info) click to toggle source

Constructor

@param SubscriptionSupport caldav_backend @param array calendar_info

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 27
def initialize(caldav_backend, subscription_info)
  @caldav_backend = caldav_backend
  @subscription_info = subscription_info

  required = [
    'id',
    'uri',
    'principaluri',
    'source'
  ]

  required.each do |r|
    fail ArgumentError, "The #{r} field is required when creating a subscription node" unless subscription_info.key?(r)
  end
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/subscriptions/subscription.rb, line 149
def acl
  [
    {
      'privilege' => '{DAV:}read',
      'principal' => owner,
      'protected' => true
    },
    {
      'privilege' => '{DAV:}write',
      'principal' => owner,
      'protected' => true
    },
    {
      'privilege' => '{DAV:}read',
      'principal' => owner + '/calendar-proxy-write',
      'protected' => true
    },
    {
      'privilege' => '{DAV:}write',
      'principal' => owner + '/calendar-proxy-write',
      'protected' => true
    },
    {
      'privilege' => '{DAV:}read',
      'principal' => owner + '/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/subscriptions/subscription.rb, line 185
def acl=(_acl)
  fail Dav::Exception::MethodNotAllowed, 'Changing ACL is not yet supported'
end
children() click to toggle source

Returns an array with all the child nodes

@return DAVINode[]

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 70
def children
  []
end
delete() click to toggle source

Deletes the current node

@return void

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 63
def delete
  @caldav_backend.delete_subscription(@subscription_info['id'])
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/subscriptions/subscription.rb, line 135
def group
  nil
end
last_modified() click to toggle source

Returns the last modification time

@return int

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 55
def last_modified
  return @subscription_info['lastmodified'] if @subscription_info.key?('lastmodified')
  nil
end
name() click to toggle source

Returns the name of the node.

This is used to generate the url.

@return string

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 48
def name
  @subscription_info['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/subscriptions/subscription.rb, line 126
def owner
  @subscription_info['principaluri']
end
prop_patch(prop_patch) click to toggle source

Updates properties on this node.

This method received a PropPatch object, which contains all the information about the update.

To update specific properties, call the 'handle' method on this object. Read the PropPatch documentation for more information.

@param PropPatch prop_patch @return void

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 84
def prop_patch(prop_patch)
  @caldav_backend.update_subscription(
    @subscription_info['id'],
    prop_patch
  )
end
properties(properties) click to toggle source

Returns a list of properties for this nodes.

The properties list is a list of propertynames the client requested, encoded in clark-notation {xmlnamespace}tagname.

If the array is empty, it means 'all properties' were requested.

Note that it's fine to liberally give properties back, instead of conforming to the list of requested properties. The Server class will filter out the extra.

@param array properties @return void

# File lib/tilia/cal_dav/subscriptions/subscription.rb, line 104
def properties(properties)
  r = {}

  properties.each do |prop|
    case prop
    when '{http://calendarserver.org/ns/}source'
      r[prop] = Dav::Xml::Property:: Href.new(@subscription_info['source'], false)
    else
      if @subscription_info.key?(prop)
        r[prop] = @subscription_info[prop]
      end
    end
  end

  r
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/subscriptions/subscription.rb, line 199
def supported_privilege_set
  nil
end