Class: Viewpoint::EWS::CalendarItem
- Defined in:
- lib/model/calendar_item.rb
Constant Summary
Constants included from ItemFieldUriMap
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
-
.create_item(v_start, v_end, subject, body = nil, location = nil, required_attendees = [], optional_attendees = [], resources = []) {|opts| ... } ⇒ Object
Create a new CalendarItem.
-
.create_item_from_hash(item, folder_id = :calendar, send_invites = 'SendToAllAndSaveCopy') ⇒ Object
This is a class method that creates a new CalendarItem in the Exchange Data Store.
-
.format_attendees(attendees, type = :required_attendees) ⇒ Object
Format attendees (usually called from #add_attendees!.
Instance Method Summary collapse
-
#add_attendees(required, optional = [], resources = []) ⇒ Boolean
Add attendees to this CalendarItem.
-
#add_attendees!(required, optional = [], resources = []) ⇒ Object
This is the same as the #add_attendees method, but it actually commits the change back to Exchange.
-
#delete!(soft = false, cancel_type = 'SendOnlyToAll') ⇒ Boolean
Delete this item.
-
#initialize(ews_item, opts = {}) ⇒ CalendarItem
constructor
Initialize an Exchange Web Services item of type CalendarItem.
-
#recycle!(cancel_type = 'SendOnlyToAll') ⇒ Boolean
Delete this item by moving it to the Deleted Items folder.
-
#remove_attendees(attendees) ⇒ Boolean
Remove the attendees from the attendee list.
-
#remove_attendees!(attendees) ⇒ Object
This is the same as the #remove_attendees method, but it actually commits the change back to Exchange.
-
#update!(updates) ⇒ Object
Call UpdateItem for this item with the passed updates TODO: This is a stand-in for the Item#update! method until I can firm it up a bit.
Methods inherited from Message
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_attribs, #update_attribs!
Constructor Details
#initialize(ews_item, opts = {}) ⇒ CalendarItem
Initialize an Exchange Web Services item of type CalendarItem
105 106 107 |
# File 'lib/model/calendar_item.rb', line 105 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(v_start, v_end, subject, body = nil, location = nil, required_attendees = [], optional_attendees = [], resources = []) {|opts| ... } ⇒ Object
Create a new CalendarItem. If a block is given it is passed an opts hash with the keys :folder_id and :send_invites.
See ::create_item_from_hash for details
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/model/calendar_item.rb', line 86 def self.create_item(v_start, v_end, subject, body = nil, location = nil, required_attendees=[], optional_attendees=[], resources=[]) item = {} opts = {:folder_id => :calendar, :send_invites => 'SendToAllAndSaveCopy'} yield opts if block_given? item[:start] = {:text => v_start.to_s} item[:end] = {:text => v_end.to_s} item[:subject] = {:text => subject} item[:body] = {:text => body, :body_type => 'Text'} unless body.nil? item[:location] = {:text => location} unless location.nil? item.merge!(self.format_attendees(required_attendees)) unless required_attendees.empty? item.merge!(self.format_attendees(optional_attendees, :optional_attendees)) unless optional_attendees.empty? resources.each do |a| item[:resources] = [] unless item[:resources].is_a?(Array) item[:resources] << {:attendee => {:mailbox => {:email_address => {:text => a}}}} end self.create_item_from_hash(item, opts[:folder_id], opts[:send_invites]) end |
.create_item_from_hash(item, folder_id = :calendar, send_invites = 'SendToAllAndSaveCopy') ⇒ Object
This is a class method that creates a new CalendarItem in the Exchange Data Store.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/model/calendar_item.rb', line 44 def self.create_item_from_hash(item, folder_id = :calendar, send_invites = 'SendToAllAndSaveCopy') conn = Viewpoint::EWS::EWS.instance resp = conn.ews.create_calendar_item(folder_id, item, send_invites) if(resp.status == 'Success') resp = resp.items.shift self.new(resp[resp.keys.first]) else raise EwsError, "Could not create CalendarItem. #{resp.code}: #{resp.}" end end |
.format_attendees(attendees, type = :required_attendees) ⇒ Object
Format attendees (usually called from #add_attendees!
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/model/calendar_item.rb', line 58 def self.format_attendees(attendees, type=:required_attendees) case attendees.class.to_s when 'String' return {type => [{:attendee => {:mailbox => {:email_address => {:text => attendees}}}}]} when /Attendee|MailboxUser/ return {type => [{:attendee => {:mailbox => [{:name => {:text => attendees.name}}, {:email_address => {:text => attendees.email_address}}]}}]} when 'Hash' return {type => [{:attendee => {:mailbox => [{:name => {:text => attendees[:name]}}, {:email_address => {:text => attendees[:email_address]}}]}}]} when 'Array' as = {type => []} attendees.each do |a| as.merge!(format_attendees(a, type)) {|k,v1,v2| v1 + v2} end return as end end |
Instance Method Details
#add_attendees(required, optional = [], resources = []) ⇒ Boolean
add ability to add resources
Add attendees to this CalendarItem. This does not commit the changes so you will have to use #save! to
commit them back. If you want to commit them at once look at the #add_attendees! method.
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/model/calendar_item.rb', line 127 def add_attendees(required, optional = [], resources = []) update = {} update.merge!(self.class.format_attendees(required)) unless required.empty? || required.nil? update.merge!(self.class.format_attendees(optional, :optional_attendees)) unless optional.empty? || optional.nil? return false if update.empty? @required_attendees, @optional_attendees = nil, nil changes = update_attribs(update, :append) @updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2} true end |
#add_attendees!(required, optional = [], resources = []) ⇒ Object
This is the same as the #add_attendees method, but it actually commits the change back to Exchange
142 143 144 145 |
# File 'lib/model/calendar_item.rb', line 142 def add_attendees!(required, optional = [], resources = []) add_attendees(required, optional, resources) save! end |
#delete!(soft = false, cancel_type = 'SendOnlyToAll') ⇒ Boolean
Add exception handling for failed deletes
Delete this item
226 227 228 229 230 231 |
# File 'lib/model/calendar_item.rb', line 226 def delete!(soft=false, cancel_type='SendOnlyToAll') deltype = soft ? 'SoftDelete' : 'HardDelete' resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], deltype, cancel_type) self.clear_object! resp.status == 'Success' end |
#recycle!(cancel_type = 'SendOnlyToAll') ⇒ Boolean
Add exception handling for failed deletes
Delete this item by moving it to the Deleted Items folder
237 238 239 240 241 |
# File 'lib/model/calendar_item.rb', line 237 def recycle!(cancel_type='SendOnlyToAll') resp = (Viewpoint::EWS::EWS.instance).ews.delete_item([@item_id], 'MoveToDeletedItems', cancel_type) self.clear_object! resp.status == 'Success' end |
#remove_attendees(attendees) ⇒ Boolean
Remove the attendees from the attendee list. This does not commit the changes so you will have to use
#save! to commit them back. If you want to commit them at once look at the #remove_attendees! method.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/model/calendar_item.rb', line 153 def remove_attendees(attendees) return false if attendees.empty? emails = attendees.is_a?(Array) ? attendees : attendees.values emails = emails.collect do |v| case v.class.to_s when 'String' v when /MailboxUser|Attendee/ v.email_address when 'Hash' v[:email_address] end end update = {} [:required_attendees, :optional_attendees].each do |type| ivar = self.send(type.to_s) next if ivar.nil? required_a = ivar.select {|v| !emails.include?(v.email_address) } formatted_a = self.class.format_attendees(required_a, type) if formatted_a[type].empty? update[:preformatted] ||= [] update[:preformatted] << {:delete_item_field => [{:field_uRI => {:field_uRI=>FIELD_URIS[type][:text]}}]} self.instance_eval "undef #{type}" else update.merge!(formatted_a) end end return false if update.empty? @required_attendees, @optional_attendees = nil, nil @updates.merge!(update) {|k,v1,v2| v1 + v2} true end |
#remove_attendees!(attendees) ⇒ Object
This is the same as the #remove_attendees method, but it actually commits the change back to Exchange
193 194 195 196 |
# File 'lib/model/calendar_item.rb', line 193 def remove_attendees!(attendees) remove_attendees(attendees) save! end |
#update!(updates) ⇒ Object
Call UpdateItem for this item with the passed updates TODO: This is a stand-in for the Item#update! method until I can firm it up a bit. It is neccessary for the SendMeetingInvitationsOrCancellations attrib
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/model/calendar_item.rb', line 202 def update!(updates) conn = Viewpoint::EWS::EWS.instance resp = conn.ews.update_item([{:id => @item_id, :change_key => @change_key}], {:updates => updates}, {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve', :send_meeting_invitations_or_cancellations => 'SendOnlyToChanged'}) if resp.status == 'Success' @item_id = resp.items.first[resp.items.first.keys.first][:item_id][:id] @change_key = resp.items.first[resp.items.first.keys.first][:item_id][:change_key] @shallow = true deepen! else raise EwsError, "Trouble updating Item. #{resp.code}: #{resp.}" end end |