Class: Viewpoint::EWS::Task

Inherits:
Item
  • Object
show all
Defined in:
lib/model/task.rb

Constant Summary

Constants included from ItemFieldUriMap

ItemFieldUriMap::FIELD_URIS

Instance Attribute Summary

Attributes inherited from Item

#change_key, #item_id, #parent_folder_id

Attributes included from Model

#ews_methods, #ews_methods_undef

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

add_attachments, #attachments, #clear_updates!, #copy, #deepen!, get_item, #mark_read!, #mark_unread!, #move!, #parent_folder, #save!, #text_only=, #text_only?, #update!, #update_attribs, #update_attribs!

Constructor Details

#initialize(ews_item, opts = {}) ⇒ Task

Initialize an Exchange Web Services item of type Task



74
75
76
# File 'lib/model/task.rb', line 74

def initialize(ews_item, opts={})
  super(ews_item, opts)
end

Dynamic Method Handling

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

Class Method Details

.create_item_from_hash(item, folder_id = :tasks, disposition = 'SaveOnly') ⇒ Object

Create a Task in the Exchange Data Store from a hash

Examples:

Typical Usage

item = {
  :subject => {:text => 'Planning'},
  :body => {:body_type => 'Text', :text => 'This is a test'},
  :start_date => {:text => '2010-07-29T14:00:00'},
  :due_date => {:text => '2010-07-29T15:00:00'},
}

Minimal Usage

item = {:subject => {:text => 'This is a test'}}


40
41
42
43
44
45
46
47
48
49
# File 'lib/model/task.rb', line 40

def self.create_item_from_hash(item, folder_id = :tasks, disposition = 'SaveOnly')
  conn = Viewpoint::EWS::EWS.instance
  resp = conn.ews.create_task_item(folder_id, item, disposition)
  if(resp.status == 'Success')
    resp = resp.items.shift
    self.new(resp[resp.keys.first])
  else
    raise EwsError, "Could not create Task. #{resp.code}: #{resp.message}"
  end
end

.create_task(folder, subject, body, v_start = nil, v_end = nil, status = nil) ⇒ Object

Create a Task in the Exchange Data Store



61
62
63
64
65
66
67
68
69
70
# File 'lib/model/task.rb', line 61

def self.create_task(folder, subject, body, v_start = nil, v_end = nil, status = nil)
  item = {}
  item[:subject] = {:text => subject}
  item[:body] = {:text => body, :body_type => 'Text'} unless body.nil?
  item[:start_date] = {:text => v_start.to_s} unless v_start.nil?
  item[:due_date] = {:text => v_end.to_s} unless v_end.nil?
  item[:status] = {:text => status} unless status.nil?
  
  self.create_item_from_hash(item, folder)
end

Instance Method Details

#delete!(soft = false, affected_task_occurrences = 'AllOccurrences') ⇒ Boolean

TODO:

Add exception handling for failed deletes

Delete this item



88
89
90
91
92
93
# File 'lib/model/task.rb', line 88

def delete!(soft=false, affected_task_occurrences='AllOccurrences')
  deltype = soft ? 'SoftDelete' : 'HardDelete'
  resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], deltype, nil, affected_task_occurrences)
  self.clear_object!
  resp.status == 'Success'
end

#recycle!(affected_task_occurrences = 'AllOccurrences') ⇒ Boolean

TODO:

Add exception handling for failed deletes

Delete this item by moving it to the Deleted Items folder



102
103
104
105
106
# File 'lib/model/task.rb', line 102

def recycle!(affected_task_occurrences='AllOccurrences')
  resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], 'MoveToDeletedItems', nil, affected_task_occurrences)
  self.clear_object!
  resp.status == 'Success'
end