Class: Tilia::CalDav::Xml::Notification::InviteReply

Inherits:
Object
  • Object
show all
Includes:
NotificationInterface
Defined in:
lib/tilia/cal_dav/xml/notification/invite_reply.rb

Overview

This class represents the cs:invite-reply notification element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ InviteReply

Creates the Invite Reply Notification.

This constructor receives an array with the following elements:

* id           - A unique id
* etag         - The etag
* dtStamp      - A DateTime object with a timestamp for the notification.
* inReplyTo    - This should refer to the 'id' of the notification
                 this is a reply to.
* type         - The type of notification, see SharingPlugin::STATUS_*
                 constants for details.
* hostUrl      - A url to the shared calendar.
* summary      - Description of the share, can be the same as the
                 calendar, but may also be modified (optional).

Parameters:

  • array

    values



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/tilia/cal_dav/xml/notification/invite_reply.rb', line 71

def initialize(values)
  required = [
    'id',
    'etag',
    'href',
    'dtStamp',
    'inReplyTo',
    'type',
    'hostUrl'
  ]

  required.each do |item|
    fail ArgumentError, "#{item} is a required constructor option" unless values.key?(item)
  end

  values.each do |key, value|
    key = key.underscore
    fail ArgumentError, "Unknown option: #{key}" unless %w(id dt_stamp in_reply_to href type host_url summary etag).include?(key)
    instance_variable_set("@#{key}".to_sym, value)
  end
end

Instance Attribute Details

#etagObject (readonly)

Returns the ETag for this notification.

The ETag must be surrounded by literal double-quotes.

Returns:

  • string



162
163
164
# File 'lib/tilia/cal_dav/xml/notification/invite_reply.rb', line 162

def etag
  @etag
end

#idObject (readonly)

Returns a unique id for this notification

This is just the base url. This should generally be some kind of unique id.

Returns:

  • string



155
156
157
# File 'lib/tilia/cal_dav/xml/notification/invite_reply.rb', line 155

def id
  @id
end

Instance Method Details

#xml_serialize(writer) ⇒ Object

The xmlSerialize metod is called during xml writing.

Use the writer argument to write its own xml serialization.

An important note: do not create a parent element. Any element implementing XmlSerializble should only ever write what’s considered its ‘inner xml’.

The parent of the current element is responsible for writing a containing element.

This allows serializers to be re-used for different element names.

If you are opening new elements, you must also close them again.

Parameters:

  • Writer

    writer

Returns:

  • void



110
111
112
# File 'lib/tilia/cal_dav/xml/notification/invite_reply.rb', line 110

def xml_serialize(writer)
  writer.write_element("{#{Plugin::NS_CALENDARSERVER}}invite-reply")
end

#xml_serialize_full(writer) ⇒ Object

This method serializes the entire notification, as it is used in the response body.

Parameters:

  • Writer

    writer

Returns:

  • void



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/tilia/cal_dav/xml/notification/invite_reply.rb', line 119

def xml_serialize_full(writer)
  cs = "{#{Plugin::NS_CALENDARSERVER}}"

  writer.write_element(cs + 'dtstamp', @dt_stamp.utc.strftime('%Y%m%dT%H%M%SZ'))

  writer.start_element(cs + 'invite-reply')

  writer.write_element(cs + 'uid', @id)
  writer.write_element(cs + 'in-reply-to', @in_reply_to)
  writer.write_element('{DAV:}href', @href)

  case @type
  when SharingPlugin::STATUS_ACCEPTED
    writer.write_element(cs + 'invite-accepted')
  when SharingPlugin::STATUS_DECLINED
    writer.write_element(cs + 'invite-declined')
  end

  writer.write_element(
    cs + 'hosturl',
    '{DAV:}href' => writer.context_uri + @host_url
  )

  unless @summary.blank?
    writer.write_element(cs + 'summary', @summary)
  end

  writer.end_element # invite-reply
end