Class: Viewpoint::EWS::Types::CalendarItem

Inherits:
Object
  • Object
show all
Includes:
Viewpoint::EWS, Viewpoint::EWS::Types, Item, StringUtils
Defined in:
lib/ews/types/calendar_item.rb

Constant Summary

CALENDAR_ITEM_KEY_PATHS =
{
   recurring?:   [:is_recurring, :text],
   meeting?:     [:is_meeting, :text],
   cancelled?:   [:is_cancelled, :text],
   duration:     [:duration, :text],
   time_zone:    [:time_zone, :text],
   start:        [:start, :text],
   end:          [:end, :text],
   location:     [:location, :text],
   all_day?:     [:is_all_day_event, :text],
   my_response_type:   [:my_response_type, :text],
   organizer: [:organizer, :elems, 0, :mailbox, :elems],
   optional_attendees: [:optional_attendees, :elems ],
   required_attendees: [:required_attendees, :elems ],
   recurrence: [:recurrence, :elems ],
   deleted_occurrences: [:deleted_occurrences, :elems ],
   modified_occurrences: [:modified_occurrences, :elems ]
}
CALENDAR_ITEM_KEY_TYPES =
{
  start:        ->(str){DateTime.parse(str)},
  end:          ->(str){DateTime.parse(str)},
  recurring?:   ->(str){str.downcase == 'true'},
  meeting?:     ->(str){str.downcase == 'true'},
  cancelled?:   ->(str){str.downcase == 'true'},
  all_day?:     ->(str){str.downcase == 'true'},
  organizer: :build_mailbox_user,
  optional_attendees: :build_attendees_users,
  required_attendees: :build_attendees_users,
  deleted_occurrences: :build_deleted_occurrences,
  modified_occurrences: :build_modified_occurrences
}
CALENDAR_ITEM_KEY_ALIAS =
{}

Constants included from StringUtils

StringUtils::DURATION_RE

Constants included from Item

Item::ITEM_KEY_ALIAS, Item::ITEM_KEY_PATHS, Item::ITEM_KEY_TYPES

Constants included from ItemFieldUriMap

ItemFieldUriMap::FIELD_URIS

Constants included from Viewpoint::EWS::Types

KEY_ALIAS, KEY_PATHS, KEY_TYPES, OOF_KEY_ALIAS, OOF_KEY_PATHS, OOF_KEY_TYPES

Constants included from Viewpoint::EWS

ConnectingSID

Instance Attribute Summary

Attributes included from Item

#ews_item, #parent

Attributes included from Viewpoint::EWS::Types

#ews_item

Attributes included from Viewpoint::EWS

#logger

Instance Method Summary collapse

Methods included from StringUtils

included

Methods included from Item

#add_file_attachment, #add_inline_attachment, #add_item_attachment, #copy, #default_body_type=, #delete!, #forward, #get_all_properties!, included, #initialize, #mark_read!, #move!, #recycle!, #reply_to, #reply_to_all, #submit!, #submit_attachments!

Methods included from Viewpoint::EWS::Types

#auto_deepen?, #deepen!, #ews_methods, #freeze!, #frozen?, #initialize, #mark_deep!, #method_missing, #methods, #respond_to?, #shallow?, #to_s, #unfreeze!

Methods included from Viewpoint::EWS

#remove_impersonation, root_logger, #set_impersonation

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Viewpoint::EWS::Types

Instance Method Details

#duration_in_secondsObject



107
108
109
# File 'lib/ews/types/calendar_item.rb', line 107

def duration_in_seconds
  iso8601_duration_to_seconds(duration)
end

#update_item!(updates, options = {}) ⇒ CalendarItem, false

TODO:

AppendToItemField updates not implemented

Updates the specified item attributes

Uses `SetItemField` if value is present and `DeleteItemField` if value is nil

Examples:

Update Subject and Body

item = #...
item.update_item!(subject: 'New subject', body: 'New Body')

Parameters:

  • updates (Hash)

    with (:attribute => value)

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :conflict_resolution (String)

    one of 'NeverOverwrite', 'AutoResolve' (default) or 'AlwaysOverwrite'

  • :send_meeting_invitations_or_cancellations (String)

    one of 'SendToNone' (default), 'SendOnlyToAll', 'SendOnlyToChanged', 'SendToAllAndSaveCopy' or 'SendToChangedAndSaveCopy'

Returns:

See Also:



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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ews/types/calendar_item.rb', line 56

def update_item!(updates, options = {})
  item_updates = []
  updates.each do |attribute, value|
    item_field = FIELD_URIS[attribute][:text] if FIELD_URIS.include? attribute
    field = {field_uRI: {field_uRI: item_field}}

    if value.nil? && item_field
      # Build DeleteItemField Change
      item_updates << {delete_item_field: field}
    elsif item_field
      # Build SetItemField Change
      item = Viewpoint::EWS::Template::CalendarItem.new(attribute => value)

      # Remap attributes because ews_builder #dispatch_field_item! uses #build_xml!
      item_attributes = item.to_ews_item.map do |name, value|
        if value.is_a? String
          {name => {text: value}}
        elsif value.is_a? Hash
          node = {name => {}}
          value.each do |attrib_key, attrib_value|
            attrib_key = camel_case(attrib_key) unless attrib_key == :text
            node[name][attrib_key] = attrib_value
          end
          node
        else
          {name => value}
        end
      end

      item_updates << {set_item_field: field.merge(calendar_item: {sub_elements: item_attributes})}
    else
      # Ignore unknown attribute
    end
  end

  if item_updates.any?
    data = {}
    data[:conflict_resolution] = options[:conflict_resolution] || 'AutoResolve'
    data[:send_meeting_invitations_or_cancellations] = options[:send_meeting_invitations_or_cancellations] || 'SendToNone'
    data[:item_changes] = [{item_id: self.item_id, updates: item_updates}]
    rm = ews.update_item(data).response_messages.first
    if rm && rm.success?
      self.get_all_properties!
      self
    else
      raise EwsCreateItemError, "Could not update calendar item. #{rm.code}: #{rm.message_text}" unless rm
    end
  end

end