Class: Tilia::CardDav::Xml::Request::AddressBookMultiGetReport

Inherits:
Object
  • Object
show all
Includes:
Xml::XmlDeserializable
Defined in:
lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb

Overview

AddressBookMultiGetReport request parser.

This class parses the urn:ietf:params:xml:ns:carddavaddressbook-multiget REPORT, as defined in:

tools.ietf.org/html/rfc6352#section-8.7

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#content_typeObject

The mimetype of the content that should be returend. Usually text/vcard.



28
29
30
# File 'lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb', line 28

def content_type
  @content_type
end

#hrefsObject

This is an array with the urls that are being requested.



22
23
24
# File 'lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb', line 22

def hrefs
  @hrefs
end

#propertiesObject

An array with requested properties.



17
18
19
# File 'lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb', line 17

def properties
  @properties
end

#versionObject

The version of vcard data that should be returned. Usually 3.0, referring to vCard 3.0.



34
35
36
# File 'lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb', line 34

def version
  @version
end

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb', line 55

def self.xml_deserialize(reader)
  elems = reader.parse_inner_tree(
    '{urn:ietf:params:xml:ns:carddav}address-data' => Filter::AddressData,
    '{DAV:}prop'                                   => Tilia::Xml::Element::KeyValue
  )

  new_props = {
    'hrefs'      => [],
    'properties' => []
  }

  elems.each do |elem|
    case elem['name']
    when '{DAV:}prop'
      new_props['properties'] = elem['value'].keys
      if elem['value'].key?("{#{Plugin::NS_CARDDAV}}address-data")
        new_props = new_props.merge(elem['value']["{#{Plugin::NS_CARDDAV}}address-data"])
      end
    when '{DAV:}href'
      new_props['hrefs'] << Uri.resolve(reader.context_uri, elem['value'])
    end
  end

  obj = new
  new_props.each do |key, value|
    key = key.underscore
    next unless %w(properties hrefs content_type version).include?(key)
    obj.send("#{key}=".to_sym, value)
  end

  obj
end