viewpoint 0.1.26 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +203 -0
- data/lib/ews/calendar_accessors.rb +34 -0
- data/lib/ews/connection.rb +140 -0
- data/lib/ews/connection_helper.rb +35 -0
- data/lib/ews/convert_accessors.rb +56 -0
- data/lib/{exceptions/exceptions.rb → ews/errors.rb} +29 -19
- data/lib/ews/ews_client.rb +105 -0
- data/lib/ews/exceptions/exceptions.rb +61 -0
- data/lib/ews/folder_accessors.rb +264 -0
- data/lib/ews/impersonation.rb +30 -0
- data/lib/ews/item_accessors.rb +242 -0
- data/lib/ews/mailbox_accessors.rb +92 -0
- data/lib/ews/meeting_accessors.rb +39 -0
- data/lib/ews/message_accessors.rb +93 -0
- data/lib/ews/push_subscription_accessors.rb +33 -0
- data/lib/ews/room_accessors.rb +48 -0
- data/lib/ews/roomlist_accessors.rb +47 -0
- data/lib/ews/soap.rb +64 -0
- data/lib/ews/soap/builders/ews_builder.rb +1384 -0
- data/lib/ews/soap/ews_response.rb +84 -0
- data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
- data/lib/ews/soap/ews_soap_free_busy_response.rb +119 -0
- data/lib/ews/soap/ews_soap_response.rb +103 -0
- data/lib/ews/soap/ews_soap_room_response.rb +53 -0
- data/lib/ews/soap/ews_soap_roomlist_response.rb +54 -0
- data/lib/ews/soap/exchange_availability.rb +61 -0
- data/lib/ews/soap/exchange_data_services.rb +780 -0
- data/lib/ews/soap/exchange_notification.rb +146 -0
- data/lib/ews/soap/exchange_synchronization.rb +93 -0
- data/lib/ews/soap/exchange_time_zones.rb +56 -0
- data/lib/ews/soap/exchange_user_configuration.rb +33 -0
- data/lib/ews/soap/exchange_web_service.rb +264 -0
- data/lib/{model/item_attachment.rb → ews/soap/parsers/ews_parser.rb} +24 -14
- data/lib/ews/soap/parsers/ews_sax_document.rb +70 -0
- data/lib/ews/soap/response_message.rb +80 -0
- data/lib/ews/soap/responses/create_attachment_response_message.rb +47 -0
- data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
- data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
- data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
- data/lib/ews/soap/responses/send_notification_response_message.rb +59 -0
- data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
- data/lib/{model/attendee.rb → ews/soap/responses/sync_folder_hierarchy_response_message.rb} +14 -15
- data/lib/ews/soap/responses/sync_folder_items_response_message.rb +36 -0
- data/lib/ews/templates/calendar_item.rb +79 -0
- data/lib/ews/templates/forward_item.rb +24 -0
- data/lib/ews/templates/message.rb +85 -0
- data/lib/ews/templates/reply_to_item.rb +25 -0
- data/lib/ews/templates/task.rb +74 -0
- data/lib/ews/types.rb +194 -0
- data/lib/ews/types/attachment.rb +77 -0
- data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
- data/lib/ews/types/calendar_folder.rb +50 -0
- data/lib/ews/types/calendar_item.rb +130 -0
- data/lib/ews/types/contact.rb +7 -0
- data/lib/ews/types/contacts_folder.rb +8 -0
- data/lib/ews/types/copied_event.rb +51 -0
- data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
- data/lib/ews/types/deleted_event.rb +24 -0
- data/lib/ews/types/distribution_list.rb +7 -0
- data/lib/ews/types/event.rb +62 -0
- data/lib/ews/types/export_items_response_message.rb +52 -0
- data/lib/ews/types/file_attachment.rb +65 -0
- data/lib/ews/types/folder.rb +60 -0
- data/lib/ews/types/free_busy_changed_event.rb +24 -0
- data/lib/ews/types/generic_folder.rb +418 -0
- data/lib/ews/types/item.rb +447 -0
- data/lib/ews/types/item_attachment.rb +84 -0
- data/lib/{model → ews/types}/item_field_uri_map.rb +2 -18
- data/lib/ews/types/mailbox_user.rb +156 -0
- data/lib/ews/types/meeting_cancellation.rb +7 -0
- data/lib/ews/types/meeting_message.rb +7 -0
- data/lib/ews/types/meeting_request.rb +7 -0
- data/lib/ews/types/meeting_response.rb +7 -0
- data/lib/ews/types/message.rb +7 -0
- data/lib/ews/types/modified_event.rb +48 -0
- data/lib/{extensions/string.rb → ews/types/moved_event.rb} +31 -15
- data/lib/ews/types/new_mail_event.rb +24 -0
- data/lib/ews/types/out_of_office.rb +147 -0
- data/lib/ews/types/post_item.rb +7 -0
- data/lib/ews/types/search_folder.rb +8 -0
- data/lib/ews/types/status_event.rb +39 -0
- data/lib/ews/types/task.rb +41 -0
- data/lib/ews/types/tasks_folder.rb +27 -0
- data/lib/viewpoint.rb +85 -108
- data/lib/{model/distribution_list.rb → viewpoint/logging.rb} +6 -3
- data/lib/{model/meeting_response.rb → viewpoint/logging/config.rb} +3 -3
- data/lib/viewpoint/string_utils.rb +76 -0
- metadata +156 -123
- data/README +0 -114
- data/lib/model/calendar_folder.rb +0 -67
- data/lib/model/calendar_item.rb +0 -267
- data/lib/model/contact.rb +0 -238
- data/lib/model/contacts_folder.rb +0 -46
- data/lib/model/event.rb +0 -116
- data/lib/model/file_attachment.rb +0 -53
- data/lib/model/folder.rb +0 -47
- data/lib/model/generic_folder.rb +0 -461
- data/lib/model/item.rb +0 -312
- data/lib/model/mailbox_user.rb +0 -146
- data/lib/model/meeting_request.rb +0 -39
- data/lib/model/message.rb +0 -142
- data/lib/model/model.rb +0 -269
- data/lib/model/search_folder.rb +0 -48
- data/lib/model/task.rb +0 -121
- data/lib/model/tasks_folder.rb +0 -44
- data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
- data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
- data/lib/soap/handsoap/ews_service.rb +0 -790
- data/lib/soap/handsoap/parser.rb +0 -104
- data/lib/soap/handsoap/parsers/ews_parser.rb +0 -245
- data/lib/soap/soap_provider.rb +0 -64
data/lib/model/contact.rb
DELETED
@@ -1,238 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
3
|
-
|
4
|
-
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
-
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
you may not use this file except in compliance with the License.
|
8
|
-
You may obtain a copy of the License at
|
9
|
-
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
|
12
|
-
Unless required by applicable law or agreed to in writing, software
|
13
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
See the License for the specific language governing permissions and
|
16
|
-
limitations under the License.
|
17
|
-
=end
|
18
|
-
|
19
|
-
module Viewpoint
|
20
|
-
module EWS
|
21
|
-
# Represents a Contact Item in the Exchange datastore.
|
22
|
-
class Contact < Item
|
23
|
-
|
24
|
-
# This is a class method that creates a new Contact in the Exchange Data Store.
|
25
|
-
# @param [Hash] item A Hash of values based on values found here:
|
26
|
-
# http://msdn.microsoft.com/en-us/library/aa581315.aspx
|
27
|
-
# @param [String, Symbol] folder_id The folder to create this item in. Either a
|
28
|
-
# DistinguishedFolderId (must me a Symbol) or a FolderId (String)
|
29
|
-
# @param [String] send_invites "SendToNone/SendOnlyToAll/SendToAllAndSaveCopy"
|
30
|
-
# See: http://msdn.microsoft.com/en-us/library/aa565209.aspx
|
31
|
-
# @example Typical Usage
|
32
|
-
# item = {
|
33
|
-
# :file_as => {:text => 'Dan Wanek'},
|
34
|
-
# :given_name => {:text => 'Dan Wanek'},
|
35
|
-
# :company_name => {:text => 'Test Company'},
|
36
|
-
# :email_addresses => [
|
37
|
-
# {:entry => {:key => 'EmailAddress1', :text => 'myemail@work.com'}},
|
38
|
-
# {:entry => {:key => 'EmailAddress2', :text => 'myemail@home.com'}}
|
39
|
-
# ],
|
40
|
-
# :physical_addresses => [
|
41
|
-
# {:entry => {:key => 'Business', :sub_elements => {:street => {:text => '6343 N Baltimore'}, :city => {:text => 'Bismarck'}, :state => {:text => 'ND'} }}}
|
42
|
-
# ],
|
43
|
-
# :phone_numbers => [
|
44
|
-
# {:entry => {:key => 'BusinessPhone', :text => '7012220000'}}
|
45
|
-
# ],
|
46
|
-
# :job_title => {:text => 'Systems Architect'}
|
47
|
-
# }
|
48
|
-
# @example Minimal Usage
|
49
|
-
def self.create_item_from_hash(item, folder_id = :contacts)
|
50
|
-
conn = Viewpoint::EWS::EWS.instance
|
51
|
-
resp = conn.ews.create_contact_item(folder_id, item)
|
52
|
-
if(resp.status == 'Success')
|
53
|
-
resp = resp.items.shift
|
54
|
-
self.new(resp[resp.keys.first])
|
55
|
-
else
|
56
|
-
raise EwsError, "Could not create Contact. #{resp.code}: #{resp.message}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Create a Contact in the Exchange Data Store
|
61
|
-
def self.add_contact()
|
62
|
-
item = {}
|
63
|
-
|
64
|
-
conn = Viewpoint::EWS::EWS.instance
|
65
|
-
resp = conn.ews.create_contact_item()
|
66
|
-
|
67
|
-
if(resp.status == 'Success')
|
68
|
-
resp = resp.items.shift
|
69
|
-
self.new(resp[resp.keys.first])
|
70
|
-
else
|
71
|
-
raise EwsError, "Could not add contact. #{resp.code}: #{resp.message}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Initialize an Exchange Web Services item of type Contact
|
76
|
-
def initialize(ews_item, opts={})
|
77
|
-
super(ews_item, opts)
|
78
|
-
end
|
79
|
-
|
80
|
-
def set_email_addresses(email1, email2=nil, email3=nil)
|
81
|
-
changes = []
|
82
|
-
type = self.class.name.split(/::/).last.ruby_case.to_sym
|
83
|
-
k = :email_addresses
|
84
|
-
v = 'EmailAddress1'
|
85
|
-
changes << {:set_item_field =>
|
86
|
-
[{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email1}}}}]} unless email1.nil?
|
87
|
-
v = 'EmailAddress2'
|
88
|
-
changes << {:set_item_field =>
|
89
|
-
[{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email2}}}}]} unless email2.nil?
|
90
|
-
v = 'EmailAddress3'
|
91
|
-
changes << {:set_item_field =>
|
92
|
-
[{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email3}}}}]} unless email3.nil?
|
93
|
-
@updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2}
|
94
|
-
end
|
95
|
-
|
96
|
-
# Set the phone number. You must give a type based on the available Exchange phone number types
|
97
|
-
# @param [Symbol] type the type of number to set. It must be one of these:
|
98
|
-
# :assistant_phone, :business_fax, :business_phone, :business_phone2, :callback, :car_phone, :company_main_phone,
|
99
|
-
# :home_fax, :home_phone, :home_phone2, :isdn, :mobile_phone, :other_fax, :other_telephone, :pager, :primary_phone,
|
100
|
-
# :radio_phone, :telex, :tty_tdd_phone
|
101
|
-
# @param [String] phone_number The phone number
|
102
|
-
def set_phone_number(phone_type, phone_number)
|
103
|
-
valid_types = [:assistant_phone, :business_fax, :business_phone, :business_phone2, :callback, :car_phone, :company_main_phone,
|
104
|
-
:home_fax, :home_phone, :home_phone2, :isdn, :mobile_phone, :other_fax, :other_telephone, :pager, :primary_phone,
|
105
|
-
:radio_phone, :telex, :tty_tdd_phone]
|
106
|
-
raise EwsError, "Invalid phone type (#{phone_type}) passed to Contact#set_phone_number." unless valid_types.index phone_type
|
107
|
-
type = self.class.name.split(/::/).last.ruby_case.to_sym
|
108
|
-
|
109
|
-
changes = []
|
110
|
-
k = :phone_numbers
|
111
|
-
v = phone_type.to_s.camel_case
|
112
|
-
changes << {:set_item_field =>
|
113
|
-
[{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => phone_number}}}}]}
|
114
|
-
@updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2}
|
115
|
-
end
|
116
|
-
|
117
|
-
# Set an address for this contact
|
118
|
-
# @param [Symbol] address_type the type of Exchange address to set. It must be one of the following:
|
119
|
-
# :business, :home, :other
|
120
|
-
# @param [Hash] address the address elements to set. It may include the following keys
|
121
|
-
# :street, :city, :state, :country_or_region, :postal_code
|
122
|
-
# @todo check for empty address hash
|
123
|
-
def set_address(address_type, address)
|
124
|
-
valid_types = [:business, :home, :other]
|
125
|
-
raise EwsError, "Invalid address type (#{address_type}) passed to Contact#set_address." unless valid_types.index address_type
|
126
|
-
valid_field_types = [:street, :city, :state, :country_or_region, :postal_code]
|
127
|
-
type = self.class.name.split(/::/).last.ruby_case.to_sym
|
128
|
-
v = address_type.to_s.camel_case
|
129
|
-
|
130
|
-
changes = []
|
131
|
-
field = 'PhysicalAddresses'
|
132
|
-
address.keys.each do |addr_item|
|
133
|
-
raise EwsError, "Invalid address element (#{addr_item}) passed to Contact#set_address." unless valid_field_types.index addr_item
|
134
|
-
index_field = "contacts:PhysicalAddress:#{addr_item.to_s.camel_case}"
|
135
|
-
changes << {:set_item_field =>
|
136
|
-
[{:indexed_field_uRI => {
|
137
|
-
:field_uRI => index_field, :field_index => v}}, {type => {field => {:entry => {:key => v, addr_item =>{ :text => address[addr_item]}}}}}
|
138
|
-
]}
|
139
|
-
end
|
140
|
-
@updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2}
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
def init_methods
|
147
|
-
super()
|
148
|
-
|
149
|
-
define_str_var :file_as, :file_as_mapping, :display_name, :job_title, :given_name, :surname, :company_name
|
150
|
-
define_attr_str_var :complete_name, :first_name, :middle_name, :last_name, :initials, :full_name
|
151
|
-
define_inet_addresses :email_addresses, :im_addresses
|
152
|
-
define_phone_numbers :phone_numbers
|
153
|
-
define_physical_addresses :physical_addresses
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
# Define email_addresses or im_addresses for a Contact
|
158
|
-
def define_inet_addresses(*inet_addresses)
|
159
|
-
inet_addresses.each do |itype|
|
160
|
-
eval "@#{itype} ||= {}"
|
161
|
-
return unless self.instance_variable_get("@#{itype}").empty?
|
162
|
-
if(@ews_item.has_key?(itype))
|
163
|
-
@ews_methods << itype
|
164
|
-
if(@ews_item[itype][:entry].is_a?(Array))
|
165
|
-
@ews_item[itype][:entry].each do |entry|
|
166
|
-
next if entry.keys.length == 1
|
167
|
-
eval "@#{itype}[entry[:key].ruby_case.to_sym] = (entry.has_key?(:text) ? entry[:text] : '')"
|
168
|
-
end
|
169
|
-
else
|
170
|
-
entry = @ews_item[itype][:entry]
|
171
|
-
next if entry.keys.length == 1
|
172
|
-
eval "@#{itype}[entry[:key].ruby_case.to_sym] = (entry.has_key?(:text) ? entry[:text] : '')"
|
173
|
-
end
|
174
|
-
self.instance_eval <<-EOF
|
175
|
-
def #{itype}
|
176
|
-
self.instance_variable_get "@#{itype}"
|
177
|
-
end
|
178
|
-
EOF
|
179
|
-
else
|
180
|
-
@ews_methods_undef << itype
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def define_phone_numbers(phone_numbers)
|
186
|
-
@phone_numbers ||= {}
|
187
|
-
return unless @phone_numbers.empty?
|
188
|
-
if(@ews_item.has_key?(phone_numbers))
|
189
|
-
if(@ews_item[phone_numbers][:entry].is_a?(Array))
|
190
|
-
@ews_item[phone_numbers][:entry].each do |entry|
|
191
|
-
next if entry.keys.length == 1
|
192
|
-
@phone_numbers[entry[:key].ruby_case.to_sym] = (entry.has_key?(:text) ? entry[:text] : "")
|
193
|
-
end
|
194
|
-
else # it is a Hash then
|
195
|
-
entry = @ews_item[phone_numbers][:entry]
|
196
|
-
return if entry.keys.length == 1
|
197
|
-
@phone_numbers[entry[:key].ruby_case.to_sym] = (entry.has_key?(:text) ? entry[:text] : "")
|
198
|
-
end
|
199
|
-
self.instance_eval <<-EOF
|
200
|
-
def #{phone_numbers}
|
201
|
-
@phone_numbers
|
202
|
-
end
|
203
|
-
EOF
|
204
|
-
@ews_methods << phone_numbers
|
205
|
-
else
|
206
|
-
@ews_methods_undef << itype
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
# Define physical_addresses for a Contact
|
211
|
-
def define_physical_addresses(physical_addresses)
|
212
|
-
@physical_addresses ||= {}
|
213
|
-
return unless @physical_addresses.empty?
|
214
|
-
if(@ews_item.has_key?(physical_addresses))
|
215
|
-
@ews_methods << physical_addresses
|
216
|
-
entries = @ews_item[physical_addresses][:entry]
|
217
|
-
entries = entries.is_a?(Array) ? entries : [entries]
|
218
|
-
entries.each do |entry|
|
219
|
-
next if entry.keys.length == 1
|
220
|
-
key = entry.delete(:key)
|
221
|
-
@physical_addresses[key.ruby_case.to_sym] = {}
|
222
|
-
entry.each_pair do |ekey,ev|
|
223
|
-
@physical_addresses[key.ruby_case.to_sym][ekey] = ev[:text]
|
224
|
-
end
|
225
|
-
end
|
226
|
-
self.instance_eval <<-EOF
|
227
|
-
def #{physical_addresses}
|
228
|
-
@physical_addresses
|
229
|
-
end
|
230
|
-
EOF
|
231
|
-
else
|
232
|
-
@ews_methods_undef << itype
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
end # Contact
|
237
|
-
end # EWS
|
238
|
-
end # Viewpoint
|
@@ -1,46 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
3
|
-
|
4
|
-
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
-
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
you may not use this file except in compliance with the License.
|
8
|
-
You may obtain a copy of the License at
|
9
|
-
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
|
12
|
-
Unless required by applicable law or agreed to in writing, software
|
13
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
See the License for the specific language governing permissions and
|
16
|
-
limitations under the License.
|
17
|
-
=end
|
18
|
-
|
19
|
-
module Viewpoint
|
20
|
-
module EWS
|
21
|
-
class ContactsFolder < GenericFolder
|
22
|
-
|
23
|
-
# Find folders of type Contact
|
24
|
-
# @see GenericFolder.find_folders
|
25
|
-
# @param [String,Symbol] root An folder id, either a DistinguishedFolderId (must me a Symbol)
|
26
|
-
# or a FolderId (String)
|
27
|
-
# @param [String] traversal Shallow/Deep/SoftDeleted
|
28
|
-
# @param [String] shape the shape to return IdOnly/Default/AllProperties
|
29
|
-
# @param [optional, String] folder_type an optional folder type to limit the search to like 'IPF.Task'
|
30
|
-
# @return [Array] Returns an Array of Folder or subclasses of Folder
|
31
|
-
def self.find_folders(root = :msgfolderroot, traversal = 'Deep', shape = 'Default', folder_type = 'IPF.Contact')
|
32
|
-
super(root, traversal, shape, folder_type)
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
# initialize with an item of CalendarFolderType
|
37
|
-
def initialize(folder)
|
38
|
-
super(folder)
|
39
|
-
|
40
|
-
# @todo Handle:
|
41
|
-
# <SharingEffectiveRights/>
|
42
|
-
end
|
43
|
-
|
44
|
-
end # ContactsFolder
|
45
|
-
end # EWS
|
46
|
-
end # Viewpoint
|
data/lib/model/event.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
3
|
-
|
4
|
-
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
-
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
you may not use this file except in compliance with the License.
|
8
|
-
You may obtain a copy of the License at
|
9
|
-
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
|
12
|
-
Unless required by applicable law or agreed to in writing, software
|
13
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
See the License for the specific language governing permissions and
|
16
|
-
limitations under the License.
|
17
|
-
=end
|
18
|
-
|
19
|
-
module Viewpoint
|
20
|
-
module EWS
|
21
|
-
class Event < Item
|
22
|
-
|
23
|
-
attr_reader :subject, :organizer, :location, :start, :end, :cal_item_type
|
24
|
-
|
25
|
-
# Initialize an Exchange Web Services item
|
26
|
-
def initialize(ews_item, parent_folder, opts={})
|
27
|
-
raise InvalidEWSItemError if ews_item.nil?
|
28
|
-
|
29
|
-
@subject = ews_item.subject # String
|
30
|
-
@location = ews_item.location if ews_item.location
|
31
|
-
@cal_item_type = ews_item.calendarItemType
|
32
|
-
@organizer = ews_item.organizer.mailbox.name if ews_item.organizer and ews_item.organizer.mailbox # String
|
33
|
-
@start = ews_item.start if ews_item.start # DateTime
|
34
|
-
@end = ews_item.v_end if ews_item.v_end # DateTime
|
35
|
-
@busy_status = ews_item.legacyFreeBusyStatus if ews_item.legacyFreeBusyStatus # String
|
36
|
-
@date_time_recieved = ews_item.dateTimeReceived if ews_item.dateTimeReceived # DateTime
|
37
|
-
|
38
|
-
# This is where the event object gets loaded if it
|
39
|
-
# is requested. Think of it like IMAP downloading the
|
40
|
-
# body when the message is viewed.
|
41
|
-
@message = nil
|
42
|
-
|
43
|
-
super(ews_item, opts)
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def body
|
49
|
-
get_calitem if @message == nil
|
50
|
-
@message.body
|
51
|
-
end
|
52
|
-
|
53
|
-
def sender
|
54
|
-
@organizer
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
# Convert item to iCal format: http://www.ietf.org/rfc/rfc2445.txt
|
59
|
-
# Returns Icalendar::Event object
|
60
|
-
def to_ical_event
|
61
|
-
get_calitem if @message == nil
|
62
|
-
iev = Icalendar::Event.new
|
63
|
-
iev.uid = @message.uID
|
64
|
-
unless(@message.organizer == nil)
|
65
|
-
iev.organizer = "CN=\"#{@message.organizer.mailbox.name}\"" if @message.organizer.mailbox.name
|
66
|
-
iev.organizer += ":MAILTO:#{@message.organizer.mailbox.emailAddress}" if @message.organizer.mailbox.emailAddress
|
67
|
-
end
|
68
|
-
# TODO: Handle EWS Timezones better. TZ_HASH in viewpoint.rb is the start of this
|
69
|
-
require 'time'
|
70
|
-
#tzoffset = @message.timeZone.sub(/^\(GMT([^\)]+)\).*$/,'\1')
|
71
|
-
dtstart = Time.at(@message.start.strftime('%s').to_i)
|
72
|
-
dtend = Time.at(@message.v_end.strftime('%s').to_i)
|
73
|
-
dtstamp = Time.at(@message.dateTimeStamp.strftime('%s').to_i)
|
74
|
-
last_modified = Time.at(@message.lastModifiedTime.strftime('%s').to_i)
|
75
|
-
timestr = "%Y%m%dT%H%M%S"
|
76
|
-
iev.dtstart = dtstart.strftime(timestr)
|
77
|
-
iev.dtend = dtend.strftime(timestr)
|
78
|
-
iev.tzid = dtstart.strftime('%Z')
|
79
|
-
iev.dtstamp = dtstamp.strftime(timestr)
|
80
|
-
iev.last_modified = last_modified.strftime(timestr)
|
81
|
-
iev.location = @message.location if @message.location
|
82
|
-
iev.klass = @message.sensitivity if @message.sensitivity
|
83
|
-
iev.summary = @message.subject if @message.subject
|
84
|
-
iev.description = @message.body if @message.body
|
85
|
-
iev.transp = @message.legacyFreeBusyStatus if @message.legacyFreeBusyStatus
|
86
|
-
iev.duration = @message.duration if @message.duration
|
87
|
-
iev.sequence = @message.appointmentSequenceNumber if @message.appointmentSequenceNumber
|
88
|
-
iev.status = @message.myResponseType if @message.myResponseType
|
89
|
-
#iev.attach @message.attachments if @message.hasAttachments
|
90
|
-
@message.requiredAttendees.each do |pers|
|
91
|
-
output = "ROLE=REQ-PARTICIPANT;CN=\"#{pers.mailbox.name}\"" if pers.mailbox.respond_to?(:name)
|
92
|
-
output += ":MAILTO:#{pers.mailbox.emailAddress}" if pers.mailbox.respond_to?(:emailAddress)
|
93
|
-
iev.attendees << output if output
|
94
|
-
end if @message.requiredAttendees
|
95
|
-
@message.optionalAttendees.each do |pers|
|
96
|
-
output = "ROLE=OPT-PARTICIPANT;CN=\"#{pers.mailbox.name}\"" if pers.mailbox.respond_to?(:name)
|
97
|
-
output += ":MAILTO:#{pers.mailbox.emailAddress}" if pers.mailbox.respond_to?(:emailAddress)
|
98
|
-
iev.attendees << output if output
|
99
|
-
end if @message.optionalAttendees
|
100
|
-
|
101
|
-
#iev.categories = @message.categories if @message.categories
|
102
|
-
#iev.resources = @message.resources if @message.resources
|
103
|
-
return iev
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
# These methods are marked 'private' because they return EWS Types and I am trying to
|
108
|
-
# hide those because they are not elegant and a bit too tedious for the public interface.
|
109
|
-
private
|
110
|
-
|
111
|
-
def get_calitem
|
112
|
-
@message = @parent_folder.get_item(@item_id)
|
113
|
-
end
|
114
|
-
end # Event
|
115
|
-
end # EWS
|
116
|
-
end # Viewpoint
|
@@ -1,53 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
3
|
-
|
4
|
-
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
-
|
6
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
you may not use this file except in compliance with the License.
|
8
|
-
You may obtain a copy of the License at
|
9
|
-
|
10
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
|
12
|
-
Unless required by applicable law or agreed to in writing, software
|
13
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
See the License for the specific language governing permissions and
|
16
|
-
limitations under the License.
|
17
|
-
=end
|
18
|
-
|
19
|
-
module Viewpoint
|
20
|
-
module EWS
|
21
|
-
# This class represents a file attachment item. You can save this object
|
22
|
-
# to a file withthe #save_to_file method.
|
23
|
-
class FileAttachment < Attachment
|
24
|
-
|
25
|
-
attr_reader :file_name, :content
|
26
|
-
# @param [String] attachment_id The unique ID for the attachment.
|
27
|
-
def initialize(attachment_id)
|
28
|
-
@id = attachment_id
|
29
|
-
conn = Viewpoint::EWS::EWS.instance
|
30
|
-
resp = conn.ews.get_attachment([attachment_id])
|
31
|
-
@file_name = resp.items.first[:file_attachment][:name][:text]
|
32
|
-
|
33
|
-
# content in Base64
|
34
|
-
@content = resp.items.first[:file_attachment][:content][:text]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Save this FileAttachment object to a file. By default it saves
|
38
|
-
# it to the original file's name in the current working directory.
|
39
|
-
# @param [String,nil] base_dir the directory to save the file to. Pass nil if you
|
40
|
-
# do not want to specify a directory or you are passing a full path name to file_name
|
41
|
-
# @param [String] file_name The name of the file to save the content to.
|
42
|
-
# Leave this blank to use the default attachment name.
|
43
|
-
def save_to_file(base_dir = nil, file_name = @file_name)
|
44
|
-
base_dir << '/' unless(base_dir.nil? or base_dir.end_with?('/'))
|
45
|
-
File.open("#{base_dir}#{file_name}", 'w+') do |f|
|
46
|
-
f.write(Base64.decode64(@content))
|
47
|
-
end
|
48
|
-
true
|
49
|
-
end
|
50
|
-
|
51
|
-
end # FileAttachment
|
52
|
-
end # EWS
|
53
|
-
end # Viewpoint
|