Class: Viewpoint::EWS::Types::Task

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

Constant Summary collapse

TASK_KEY_PATHS =
{
   complete?:         [:is_complete, :text],
   recurring?:        [:is_recurring, :text],
   start_date:        [:start_date, :text],
   due_date:          [:due_date, :text],
   reminder_due_by:   [:reminder_due_by, :text],
   reminder?:         [:reminder_is_set, :text],
   percent_complete:  [:percent_complete, :text],
   status:            [:status, :text],
   owner:             [:owner, :text],
}
TASK_KEY_TYPES =
{
  recurring?:       ->(str){str.downcase == 'true'},
  complete?:        ->(str){str.downcase == 'true'},
  reminder?:        ->(str){str.downcase == 'true'},
  percent_complete: ->(str){str.to_i},
}
TASK_KEY_ALIAS =
{}

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 StringUtils

StringUtils::DURATION_RE

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 Item

#add_file_attachment, #add_inline_attachment, #add_item_attachment, #copy, #default_body_type=, #delete!, #forward, #get_all_properties!, included, #initialize, #mark_read!, #mark_unread!, #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 StringUtils

included

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

#update_task!(updates, options = {}) ⇒ Task, false

Updates the specified attributes

Examples:

Update Subject and Body

item = #...
item.update_item!(subject: 'New subject', due_date: Time.parse('25.03.2013 12:00'))

Parameters:

  • updates (Hash)

    with (:attribute => value)

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

Options Hash (options):

  • :conflict_resolution (String)

    one of ‘NeverOverwrite’, ‘AutoResolve’ (default) or ‘AlwaysOverwrite’

Returns:



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
# File 'lib/ews/types/task.rb', line 37

def update_task!(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::Task.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(task: {sub_elements: item_attributes})}
    else
      # Ignore unknown attribute
    end
  end

  if item_updates.any?
    data = {}
    data[:conflict_resolution] = options[:conflict_resolution] || 'AlwaysOverwrite'
    data[:item_changes] = [{item_id: self.item_id, updates: item_updates}]
    response_message = ews.update_item(data).response_messages.first
    if response_message && response_message.success?
      self.get_all_properties!
      self
    elsif response_message
      raise EwsCreateItemError, "Could not update task. #{response_message.code}: #{response_message.message_text}"
    else
      raise StandardError("No response message received.")
    end
  end

end