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.



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

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.



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

def body
  @body
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



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

def content_type
  @content_type
end

#etagObject (readonly)

Returns the value of attribute etag.



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

def etag
  @etag
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#new?Boolean

Returns:

  • (Boolean)


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

def new?
  @new_record
end

#to_propfind_xmlObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/protocol/caldav/item.rb', line 24

def to_propfind_xml
  <<~XML
    <d:response>
      <d:href>#{Xml.escape(@path.to_s)}</d:href>
      <d:propstat>
        <d:prop>
          <d:getetag>#{Xml.escape(@etag)}</d:getetag>
          <d:getcontenttype>#{Xml.escape(@content_type)}</d:getcontenttype>
        </d:prop>
        <d:status>HTTP/1.1 200 OK</d:status>
      </d:propstat>
    </d:response>
  XML
end

#to_propname_xmlObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/protocol/caldav/item.rb', line 39

def to_propname_xml
  <<~XML
    <d:response>
      <d:href>#{Xml.escape(@path.to_s)}</d:href>
      <d:propstat>
        <d:prop>
          <d:getetag/>
          <d:getcontenttype/>
        </d:prop>
        <d:status>HTTP/1.1 200 OK</d:status>
      </d:propstat>
    </d:response>
  XML
end

#to_report_xml(data_tag:) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/protocol/caldav/item.rb', line 54

def to_report_xml(data_tag:)
  <<~XML
    <d:response>
      <d:href>#{Xml.escape(@path.to_s)}</d:href>
      <d:propstat>
        <d:prop>
          <d:getetag>#{Xml.escape(@etag)}</d:getetag>
          <#{data_tag}>#{Xml.escape(@body)}</#{data_tag}>
        </d:prop>
        <d:status>HTTP/1.1 200 OK</d:status>
      </d:propstat>
    </d:response>
  XML
end