Class: Protocol::Caldav::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/caldav/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, body:, content_type:, etag:, new_record: false) ⇒ Item

Returns a new instance of Item.



13
14
15
16
17
18
19
# File 'lib/protocol/caldav/item.rb', line 13

def initialize(path:, body:, content_type:, etag:, new_record: false)
  @path = path
  @body = body
  @content_type = content_type
  @etag = etag
  @new_record = new_record
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/protocol/caldav/item.rb', line 11

def body
  @body
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



11
12
13
# File 'lib/protocol/caldav/item.rb', line 11

def content_type
  @content_type
end

#etagObject (readonly)

Returns the value of attribute etag.



11
12
13
# File 'lib/protocol/caldav/item.rb', line 11

def etag
  @etag
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/protocol/caldav/item.rb', line 11

def path
  @path
end

Instance Method Details

#build_propfind(xml) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/protocol/caldav/item.rb', line 25

def build_propfind(xml)
  XmlBuilder.response(xml, href: @path.to_s) do
    XmlBuilder.propstat_ok(xml) do
      xml.tag!("d:getetag", @etag)
      xml.tag!("d:getcontenttype", @content_type)
    end
  end
end

#build_propname(xml) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/protocol/caldav/item.rb', line 34

def build_propname(xml)
  XmlBuilder.response(xml, href: @path.to_s) do
    XmlBuilder.propstat_ok(xml) do
      xml.tag!("d:getetag")
      xml.tag!("d:getcontenttype")
    end
  end
end

#build_report(xml, data_tag:) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/protocol/caldav/item.rb', line 43

def build_report(xml, data_tag:)
  XmlBuilder.response(xml, href: @path.to_s) do
    XmlBuilder.propstat_ok(xml) do
      xml.tag!("d:getetag", @etag)
      xml.tag!(data_tag, @body)
    end
  end
end

#build_xml(xml) ⇒ Object



52
53
54
# File 'lib/protocol/caldav/item.rb', line 52

def build_xml(xml)
  build_propfind(xml)
end

#new?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/protocol/caldav/item.rb', line 21

def new?
  @new_record
end

#to_propfind_xmlObject



56
57
58
59
60
# File 'lib/protocol/caldav/item.rb', line 56

def to_propfind_xml
  x = Builder::XmlMarkup.new
  build_propfind(x)
  x.target!
end

#to_propname_xmlObject



62
63
64
65
66
# File 'lib/protocol/caldav/item.rb', line 62

def to_propname_xml
  x = Builder::XmlMarkup.new
  build_propname(x)
  x.target!
end

#to_report_xml(data_tag:) ⇒ Object



68
69
70
71
72
# File 'lib/protocol/caldav/item.rb', line 68

def to_report_xml(data_tag:)
  x = Builder::XmlMarkup.new
  build_report(x, data_tag: data_tag)
  x.target!
end