Class: Viewpoint::EWS::Event

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

Constant Summary

Constants included from ItemFieldUriMap

ItemFieldUriMap::FIELD_URIS

Instance Attribute Summary collapse

Attributes inherited from Item

#change_key, #item_id, #parent_folder_id

Attributes included from Model

#ews_methods, #ews_methods_undef

Instance Method Summary collapse

Methods inherited from Item

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

Constructor Details

#initialize(ews_item, parent_folder, opts = {}) ⇒ Event

Initialize an Exchange Web Services item

Raises:

  • (InvalidEWSItemError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/model/event.rb', line 26

def initialize(ews_item, parent_folder, opts={})
  raise InvalidEWSItemError if ews_item.nil?

  @subject = ews_item.subject # String
  @location = ews_item.location if ews_item.location
  @cal_item_type = ews_item.calendarItemType
  @organizer = ews_item.organizer.mailbox.name if ews_item.organizer and ews_item.organizer.mailbox # String
  @start = ews_item.start if ews_item.start # DateTime
  @end = ews_item.v_end if ews_item.v_end # DateTime
  @busy_status = ews_item.legacyFreeBusyStatus if ews_item.legacyFreeBusyStatus # String
  @date_time_recieved = ews_item.dateTimeReceived if ews_item.dateTimeReceived # DateTime

  # This is where the event object gets loaded if it
  # is requested.  Think of it like IMAP downloading the
  # body when the message is viewed.
  @message = nil

  super(ews_item, opts)
end

Dynamic Method Handling

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

Instance Attribute Details

#cal_item_typeObject (readonly)

Returns the value of attribute cal_item_type.



23
24
25
# File 'lib/model/event.rb', line 23

def cal_item_type
  @cal_item_type
end

#endObject (readonly)

Returns the value of attribute end.



23
24
25
# File 'lib/model/event.rb', line 23

def end
  @end
end

#locationObject (readonly)

Returns the value of attribute location.



23
24
25
# File 'lib/model/event.rb', line 23

def location
  @location
end

#organizerObject (readonly)

Returns the value of attribute organizer.



23
24
25
# File 'lib/model/event.rb', line 23

def organizer
  @organizer
end

#startObject (readonly)

Returns the value of attribute start.



23
24
25
# File 'lib/model/event.rb', line 23

def start
  @start
end

#subjectObject (readonly)

Returns the value of attribute subject.



23
24
25
# File 'lib/model/event.rb', line 23

def subject
  @subject
end

Instance Method Details

#bodyObject



48
49
50
51
# File 'lib/model/event.rb', line 48

def body
  get_calitem if @message == nil
  @message.body
end

#senderObject



53
54
55
# File 'lib/model/event.rb', line 53

def sender
  @organizer
end

#to_ical_eventObject

Convert item to iCal format: www.ietf.org/rfc/rfc2445.txt Returns Icalendar::Event object



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
# File 'lib/model/event.rb', line 60

def to_ical_event
  get_calitem if @message == nil
  iev = Icalendar::Event.new
  iev.uid = @message.uID
  unless(@message.organizer == nil)
    iev.organizer = "CN=\"#{@message.organizer.mailbox.name}\"" if @message.organizer.mailbox.name
    iev.organizer += ":MAILTO:#{@message.organizer.mailbox.emailAddress}" if @message.organizer.mailbox.emailAddress
  end
  # TODO: Handle EWS Timezones better.  TZ_HASH in viewpoint.rb is the start of this
  require 'time'
  #tzoffset = @message.timeZone.sub(/^\(GMT([^\)]+)\).*$/,'\1')
  dtstart = Time.at(@message.start.strftime('%s').to_i)
  dtend   = Time.at(@message.v_end.strftime('%s').to_i)
  dtstamp = Time.at(@message.dateTimeStamp.strftime('%s').to_i)
  last_modified = Time.at(@message.lastModifiedTime.strftime('%s').to_i)
  timestr = "%Y%m%dT%H%M%S"
  iev.dtstart = dtstart.strftime(timestr)
  iev.dtend   = dtend.strftime(timestr)
  iev.tzid    = dtstart.strftime('%Z')
  iev.dtstamp = dtstamp.strftime(timestr)
  iev.last_modified = last_modified.strftime(timestr)
  iev.location = @message.location if @message.location
  iev.klass = @message.sensitivity if @message.sensitivity
  iev.summary = @message.subject if @message.subject
  iev.description = @message.body if @message.body
  iev.transp = @message.legacyFreeBusyStatus if @message.legacyFreeBusyStatus
  iev.duration = @message.duration if @message.duration
  iev.sequence = @message.appointmentSequenceNumber if @message.appointmentSequenceNumber
  iev.status = @message.myResponseType if @message.myResponseType
  #iev.attach @message.attachments if @message.hasAttachments
  @message.requiredAttendees.each do |pers|
    output =  "ROLE=REQ-PARTICIPANT;CN=\"#{pers.mailbox.name}\"" if pers.mailbox.respond_to?(:name)
    output += ":MAILTO:#{pers.mailbox.emailAddress}" if pers.mailbox.respond_to?(:emailAddress)
    iev.attendees << output if output
  end if @message.requiredAttendees
  @message.optionalAttendees.each do |pers|
    output =  "ROLE=OPT-PARTICIPANT;CN=\"#{pers.mailbox.name}\"" if pers.mailbox.respond_to?(:name)
    output += ":MAILTO:#{pers.mailbox.emailAddress}" if pers.mailbox.respond_to?(:emailAddress)
    iev.attendees << output if output
  end if @message.optionalAttendees

  #iev.categories = @message.categories if @message.categories
  #iev.resources  = @message.resources if @message.resources
  return iev
end