Class: Protocol::Caldav::Collection
- Inherits:
-
Object
- Object
- Protocol::Caldav::Collection
- Defined in:
- lib/protocol/caldav/collection.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#displayname ⇒ Object
readonly
Returns the value of attribute displayname.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build_propfind(xml) ⇒ Object
- #build_propname(xml) ⇒ Object
- #build_xml(xml) ⇒ Object
-
#initialize(path:, type: :collection, displayname: nil, description: nil, color: nil, props: {}) ⇒ Collection
constructor
A new instance of Collection.
- #to_propfind_xml ⇒ Object
- #to_propname_xml ⇒ Object
- #update_attrs(updates) ⇒ Object
Constructor Details
#initialize(path:, type: :collection, displayname: nil, description: nil, color: nil, props: {}) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 16 17 18 19 |
# File 'lib/protocol/caldav/collection.rb', line 12 def initialize(path:, type: :collection, displayname: nil, description: nil, color: nil, props: {}) @path = path @type = type @displayname = displayname @description = description @color = color @props = props || {} end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def color @color end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def description @description end |
#displayname ⇒ Object (readonly)
Returns the value of attribute displayname.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def displayname @displayname end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def path @path end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def props @props end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/protocol/caldav/collection.rb', line 10 def type @type end |
Instance Method Details
#build_propfind(xml) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 87 88 89 90 |
# File 'lib/protocol/caldav/collection.rb', line 37 def build_propfind(xml) XmlBuilder.response(xml, href: @path.to_s) do XmlBuilder.propstat_ok(xml) do xml.tag!("d:resourcetype") do xml.tag!("d:collection") if @type == :calendar xml.tag!("c:calendar") end if @type == :addressbook xml.tag!("cr:addressbook") end end if @displayname xml.tag!("d:displayname", @displayname) end if @description xml.tag!("c:calendar-description", @description) end if @color xml.tag!("x:calendar-color", @color) end = @path.storage_class.list_items(@path.to_s).map { |_, data| data[:etag] } ctag = CTag.compute( path: @path.to_s, displayname: @displayname, description: @description, color: @color, item_etags: , ) xml.tag!("cs:getctag", ctag) xml.tag!("d:sync-token", "http://caldav.local/sync/#{ctag}") if @type == :calendar xml.tag!("c:supported-calendar-component-set") do xml.tag!("c:comp", name: "VEVENT") xml.tag!("c:comp", name: "VTODO") xml.tag!("c:comp", name: "VJOURNAL") end end xml.tag!("d:current-user-privilege-set") do xml.tag!("d:privilege") { xml.tag!("d:read") } xml.tag!("d:privilege") { xml.tag!("d:write") } xml.tag!("d:privilege") { xml.tag!("d:all") } end @props.each do |key, value| xml.tag!(key, value) end end end end |
#build_propname(xml) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/protocol/caldav/collection.rb', line 92 def build_propname(xml) XmlBuilder.response(xml, href: @path.to_s) do XmlBuilder.propstat_ok(xml) do xml.tag!("d:resourcetype") if @displayname xml.tag!("d:displayname") end if @description xml.tag!("c:calendar-description") end if @color xml.tag!("x:calendar-color") end xml.tag!("cs:getctag") xml.tag!("d:sync-token") if @type == :calendar xml.tag!("c:supported-calendar-component-set") end end end end |
#build_xml(xml) ⇒ Object
114 115 116 |
# File 'lib/protocol/caldav/collection.rb', line 114 def build_xml(xml) build_propfind(xml) end |
#to_propfind_xml ⇒ Object
118 119 120 121 122 |
# File 'lib/protocol/caldav/collection.rb', line 118 def to_propfind_xml x = Builder::XmlMarkup.new build_propfind(x) x.target! end |
#to_propname_xml ⇒ Object
124 125 126 127 128 |
# File 'lib/protocol/caldav/collection.rb', line 124 def to_propname_xml x = Builder::XmlMarkup.new build_propname(x) x.target! end |
#update_attrs(updates) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/protocol/caldav/collection.rb', line 21 def update_attrs(updates) if updates.key?(:displayname) @displayname = updates[:displayname] end if updates.key?(:description) @description = updates[:description] end if updates.key?(:color) @color = updates[:color] end if updates.key?(:props) @props = (@props || {}).merge(updates[:props]) end self end |