Class: Tilia::CalDav::Xml::Filter::CalendarData

Inherits:
Object
  • Object
show all
Includes:
Xml::XmlDeserializable
Defined in:
lib/tilia/cal_dav/xml/filter/calendar_data.rb

Overview

CalendarData parser.

This class parses the urn:ietf:params:xml:ns:caldavcalendar-data XML element, as defined in:

tools.ietf.org/html/rfc4791#section-9.6

This element is used in three distinct places in the caldav spec, but in this case, this element class only implements the calendar-data element as it appears in a DAV:prop element, in a calendar-query or calendar-multiget REPORT request.

Class Method Summary collapse

Class Method Details

.xml_deserialize(reader) ⇒ Object

The deserialize method is called during xml parsing.

This method is called statictly, this is because in theory this method may be used as a type of constructor, or factory method.

Often you want to return an instance of the current class, but you are free to return other data as well.

You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop.

If you just want to skip parsing for this element altogether, you can just call reader.next

reader.parse_inner_tree will parse the entire sub-tree, and advance to the next element.

Parameters:

  • Reader

    reader

Returns:

  • mixed



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tilia/cal_dav/xml/filter/calendar_data.rb', line 38

def self.xml_deserialize(reader)
  result = {
    'contentType' => reader['content-type'] || 'text/calendar',
    'version'     => reader['version'] || '2.0'
  }

  elems = reader.parse_inner_tree || []
  elems.each do |elem|
    case elem['name']
    when "{#{Plugin::NS_CALDAV}}expand"
      result['expand'] = {
        'start' => elem['attributes'].key?('start') ? VObject::DateTimeParser.parse_date_time(elem['attributes']['start']) : nil,
        'end'   => elem['attributes'].key?('end') ? VObject::DateTimeParser.parse_date_time(elem['attributes']['end']) : nil
      }

      fail Dav::Exception::BadRequest, 'The "start" and "end" attributes are required when expanding calendar-data' unless result['expand']['start'] && result['expand']['end']
      fail Dav::Exception::BadRequest, 'The end-date must be larger than the start-date when expanding calendar-data' if result['expand']['end'] <= result['expand']['start']
    end
  end

  result
end