viewpoint 0.1.27 → 1.0.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/README.md +196 -0
  2. data/lib/ews/calendar_accessors.rb +34 -0
  3. data/lib/ews/connection.rb +117 -0
  4. data/lib/ews/connection_helper.rb +35 -0
  5. data/lib/ews/ews_client.rb +71 -0
  6. data/lib/ews/exceptions/exceptions.rb +59 -0
  7. data/lib/ews/folder_accessors.rb +199 -0
  8. data/lib/ews/item_accessors.rb +157 -0
  9. data/lib/ews/mailbox_accessors.rb +87 -0
  10. data/lib/ews/message_accessors.rb +86 -0
  11. data/lib/ews/push_subscription_accessors.rb +33 -0
  12. data/lib/ews/soap.rb +63 -0
  13. data/lib/ews/soap/builders/ews_builder.rb +1011 -0
  14. data/lib/ews/soap/ews_response.rb +83 -0
  15. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  16. data/lib/ews/soap/ews_soap_free_busy_response.rb +109 -0
  17. data/lib/ews/soap/ews_soap_response.rb +103 -0
  18. data/lib/ews/soap/exchange_availability.rb +61 -0
  19. data/lib/ews/soap/exchange_data_services.rb +742 -0
  20. data/lib/ews/soap/exchange_notification.rb +146 -0
  21. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  22. data/lib/ews/soap/exchange_web_service.rb +294 -0
  23. data/lib/{model/attendee.rb → ews/soap/parsers/ews_parser.rb} +20 -14
  24. data/lib/ews/soap/parsers/ews_sax_document.rb +66 -0
  25. data/lib/ews/soap/response_message.rb +78 -0
  26. data/lib/ews/soap/responses/create_attachment_response_message.rb +46 -0
  27. data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
  28. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  29. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  30. data/lib/ews/soap/responses/send_notification_response_message.rb +58 -0
  31. data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
  32. data/lib/ews/templates/forward_item.rb +24 -0
  33. data/lib/ews/templates/message.rb +66 -0
  34. data/lib/ews/templates/reply_to_item.rb +25 -0
  35. data/lib/ews/types.rb +146 -0
  36. data/lib/ews/types/attachment.rb +77 -0
  37. data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
  38. data/lib/ews/types/calendar_folder.rb +8 -0
  39. data/lib/ews/types/calendar_item.rb +37 -0
  40. data/lib/ews/types/contact.rb +7 -0
  41. data/lib/ews/types/contacts_folder.rb +8 -0
  42. data/lib/ews/types/copied_event.rb +51 -0
  43. data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
  44. data/lib/{model/meeting_response.rb → ews/types/deleted_event.rb} +6 -6
  45. data/lib/ews/types/distribution_list.rb +7 -0
  46. data/lib/ews/types/event.rb +62 -0
  47. data/lib/ews/types/file_attachment.rb +65 -0
  48. data/lib/ews/types/folder.rb +60 -0
  49. data/lib/{model/distribution_list.rb → ews/types/free_busy_changed_event.rb} +6 -6
  50. data/lib/ews/types/generic_folder.rb +352 -0
  51. data/lib/ews/types/item.rb +381 -0
  52. data/lib/ews/types/item_attachment.rb +46 -0
  53. data/lib/{model → ews/types}/item_field_uri_map.rb +2 -2
  54. data/lib/ews/types/mailbox_user.rb +156 -0
  55. data/lib/ews/types/meeting_cancellation.rb +7 -0
  56. data/lib/ews/types/meeting_message.rb +7 -0
  57. data/lib/ews/types/meeting_request.rb +7 -0
  58. data/lib/ews/types/meeting_response.rb +7 -0
  59. data/lib/ews/types/message.rb +7 -0
  60. data/lib/ews/types/modified_event.rb +48 -0
  61. data/lib/{model/item_attachment.rb → ews/types/moved_event.rb} +33 -15
  62. data/lib/ews/types/new_mail_event.rb +24 -0
  63. data/lib/ews/types/out_of_office.rb +147 -0
  64. data/lib/ews/types/search_folder.rb +8 -0
  65. data/lib/ews/types/status_event.rb +39 -0
  66. data/lib/ews/types/task.rb +7 -0
  67. data/lib/ews/types/tasks_folder.rb +8 -0
  68. data/lib/viewpoint.rb +82 -106
  69. metadata +99 -67
  70. data/README +0 -114
  71. data/lib/exceptions/exceptions.rb +0 -46
  72. data/lib/model/calendar_folder.rb +0 -67
  73. data/lib/model/calendar_item.rb +0 -267
  74. data/lib/model/contact.rb +0 -238
  75. data/lib/model/contacts_folder.rb +0 -46
  76. data/lib/model/event.rb +0 -116
  77. data/lib/model/file_attachment.rb +0 -53
  78. data/lib/model/folder.rb +0 -47
  79. data/lib/model/generic_folder.rb +0 -471
  80. data/lib/model/item.rb +0 -313
  81. data/lib/model/mailbox_user.rb +0 -146
  82. data/lib/model/meeting_request.rb +0 -39
  83. data/lib/model/message.rb +0 -142
  84. data/lib/model/model.rb +0 -269
  85. data/lib/model/search_folder.rb +0 -48
  86. data/lib/model/task.rb +0 -121
  87. data/lib/model/tasks_folder.rb +0 -44
  88. data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
  89. data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
  90. data/lib/soap/handsoap/ews_service.rb +0 -813
  91. data/lib/soap/handsoap/parser.rb +0 -104
  92. data/lib/soap/handsoap/parsers/ews_parser.rb +0 -246
  93. data/lib/soap/soap_provider.rb +0 -64
@@ -1,146 +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
- require 'soap/handsoap/builders/ews_build_helpers.rb'
20
- module Viewpoint
21
- module EWS
22
- module SOAP
23
-
24
- # This class includes all the build helpers and also contains some root
25
- # level methods to help code reuse. The CreateItem operation is an example
26
- # of this because the different item types share a lot but have a few subtle
27
- # differences.
28
- class EwsBuilder
29
- include EwsBuildHelpers
30
-
31
- def initialize(node, opts, &block)
32
- @node, @opts = node, opts
33
- instance_eval(&block) if block_given?
34
- end
35
-
36
- # @see ExchangeWebService#subscribe
37
- def pull_subscription_request!(folder_ids, event_types, timeout)
38
- @node.add("#{NS_EWS_MESSAGES}:PullSubscriptionRequest") do |ps|
39
- folder_ids!(ps, folder_ids, nil, "#{NS_EWS_TYPES}:FolderIds")
40
- event_types!(ps, event_types)
41
- ps.add("#{NS_EWS_TYPES}:Timeout", timeout)
42
- end
43
- end
44
-
45
- # @see ExchangeWebService#subscribe
46
- def push_subscription_request!(folder_ids, event_types, url, watermark=nil, status_frequency=5)
47
- @node.add("#{NS_EWS_MESSAGES}:PushSubscriptionRequest") do |ps|
48
- folder_ids!(ps, folder_ids, nil, "#{NS_EWS_TYPES}:FolderIds")
49
- event_types!(ps, event_types)
50
- ps.add("#{NS_EWS_TYPES}:Watermark", watermark) unless watermark.nil?
51
- ps.add("#{NS_EWS_TYPES}:StatusFrequency", status_frequency)
52
- ps.add("#{NS_EWS_TYPES}:URL", url)
53
- end
54
- end
55
-
56
- # @param [String] type The type of items in the items array message/calendar
57
- # @todo Fix max_changes_returned to be more flexible
58
- def create_item!(folder_id, items, message_disposition, send_invites, type)
59
- @node.set_attr('MessageDisposition', message_disposition) if message_disposition
60
- @node.set_attr('SendMeetingInvitations', send_invites) if send_invites
61
-
62
- saved_item_folder_id!(@node, folder_id) unless folder_id.nil?
63
- items!(@node, items, type)
64
- end
65
-
66
- def add_delegate!(owner, delegate, permissions)
67
- d_user = {
68
- :user_id => {:primary_smtp_address => {:text => delegate}},
69
- :delegate_permissions => permissions
70
- }
71
-
72
- mailbox!(@node, {:email_address => {:text => owner}})
73
- delegate_users!(@node, [d_user])
74
- end
75
-
76
- def remove_delegate!(owner, delegate)
77
- mailbox!(@node, {:email_address => {:text => owner}})
78
- @node.add("#{NS_EWS_MESSAGES}:UserIds") do |uids|
79
- user_id!(uids, {:user_id => {:primary_smtp_address => {:text => delegate}}})
80
- end
81
- end
82
-
83
- # Build the request XML for GetUserAvailability.
84
- # @see http://msdn.microsoft.com/en-us/library/aa494212.aspx
85
- def get_user_availability!(email_address, start_time, end_time)
86
- add_time_zone_info
87
- @node.add("#{NS_EWS_MESSAGES}:MailboxDataArray") do |mda|
88
- mda.add("#{NS_EWS_TYPES}:MailboxData") do |mbdata|
89
- mbdata.add("#{NS_EWS_TYPES}:Email") do |email|
90
- email.add("#{NS_EWS_TYPES}:Name")
91
- email.add("#{NS_EWS_TYPES}:Address", email_address)
92
- end
93
- mbdata.add("#{NS_EWS_TYPES}:AttendeeType", 'Required')
94
- end
95
- end
96
- @node.add("#{NS_EWS_TYPES}:FreeBusyViewOptions") do |fbvo|
97
- fbvo.add("#{NS_EWS_TYPES}:TimeWindow") do |tw|
98
- tw.add("#{NS_EWS_TYPES}:StartTime", start_time)
99
- tw.add("#{NS_EWS_TYPES}:EndTime", end_time)
100
- end
101
- fbvo.add("#{NS_EWS_TYPES}:MergedFreeBusyIntervalInMinutes", 10)
102
- fbvo.add("#{NS_EWS_TYPES}:RequestedView", 'MergedOnly')
103
- end
104
- end
105
-
106
- # This is forthcoming in Exchange 2010. It will replace much of the Restriction
107
- # based code.
108
- # @param [Array] An array of query strings
109
- # @see http://msdn.microsoft.com/en-us/library/ee693615.aspx
110
- def query_strings!(query_strings)
111
- query_strings.each do |qs|
112
- @node.add("#{NS_EWS_MESSAGES}:QueryString", qs)
113
- end
114
- end
115
-
116
- private
117
-
118
- # Add a description of the time zone to the request XML.
119
- # The timezone information defaults to US/Pacific time.
120
- def add_time_zone_info(offset_hours_std = -8, offset_hours_dst = -7)
121
- base_bias = (-1 * offset_hours_std * 60).to_s
122
- standard_bias = '0'
123
- savings_bias = (offset_hours_std - offset_hours_dst).to_s
124
- @node.add("#{NS_EWS_TYPES}:TimeZone") do |tz|
125
- tz.add("#{NS_EWS_TYPES}:Bias", base_bias) # e.g. '480'
126
- tz.add("#{NS_EWS_TYPES}:StandardTime") do |stime|
127
- stime.add("#{NS_EWS_TYPES}:Bias", standard_bias) # e.g. '0'
128
- stime.add("#{NS_EWS_TYPES}:Time", '02:00:00')
129
- stime.add("#{NS_EWS_TYPES}:DayOrder", '1')
130
- stime.add("#{NS_EWS_TYPES}:Month", '11')
131
- stime.add("#{NS_EWS_TYPES}:DayOfWeek", 'Sunday')
132
- end
133
- tz.add("#{NS_EWS_TYPES}:DaylightTime") do |dtime|
134
- dtime.add("#{NS_EWS_TYPES}:Bias", savings_bias) # e.g. '-60'
135
- dtime.add("#{NS_EWS_TYPES}:Time", '02:00:00')
136
- dtime.add("#{NS_EWS_TYPES}:DayOrder", '2')
137
- dtime.add("#{NS_EWS_TYPES}:Month", '3')
138
- dtime.add("#{NS_EWS_TYPES}:DayOfWeek", 'Sunday')
139
- end
140
- end
141
- end
142
-
143
- end # EwsBuilder
144
- end # SOAP
145
- end # EWS
146
- end # Viewpoint
@@ -1,813 +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
- require 'handsoap'
20
- require 'soap/handsoap/builder'
21
- require 'soap/handsoap/parser'
22
-
23
- Handsoap.http_driver = :http_client
24
-
25
- module Viewpoint
26
- module EWS
27
- module SOAP
28
- class ExchangeWebService < Handsoap::Service
29
- include Viewpoint::EWS::SOAP
30
-
31
- SOAP_ACTION_PREFIX = "http://schemas.microsoft.com/exchange/services/2006/messages"
32
-
33
- @@raw_soap = false
34
- @@http_options = nil
35
-
36
- def initialize()
37
- if $DEBUG
38
- @debug = File.new('ews_debug.out', 'w')
39
- @debug.sync = true
40
- end
41
- end
42
-
43
- def self.set_auth(user,pass)
44
- @@user = user
45
- @@pass = pass
46
- end
47
-
48
- # Turn off parsing and just return the soap response
49
- def self.raw_soap!
50
- @@raw_soap = true
51
- end
52
-
53
- # Set various HTTP options like ssl_ca_trust, etc
54
- def self.set_http_options(option_hash)
55
- if @@http_options.nil?
56
- @@http_options = option_hash
57
- else
58
- @@http_options.merge!(option_hash)
59
- end
60
- end
61
-
62
- # ********* Begin Hooks *********
63
-
64
-
65
- def on_create_document(doc)
66
- doc.alias NS_EWS_TYPES, 'http://schemas.microsoft.com/exchange/services/2006/types'
67
- doc.alias NS_EWS_MESSAGES, 'http://schemas.microsoft.com/exchange/services/2006/messages'
68
- header = doc.find('Header')
69
- header.add("#{NS_EWS_TYPES}:RequestServerVersion") { |rsv| rsv.set_attr('Version','Exchange2007_SP1') }
70
- end
71
-
72
- # Adds knowledge of namespaces to the response object. These have to be identical to the
73
- # URIs returned in the XML response. For example, I had some issues with the 'soap'
74
- # namespace because my original URI did not end in a '/'
75
- # @example
76
- # Won't work: http://schemas.xmlsoap.org/soap/envelope
77
- # Works: http://schemas.xmlsoap.org/soap/envelope/
78
- def on_response_document(doc)
79
- doc.add_namespace NS_SOAP, 'http://schemas.xmlsoap.org/soap/envelope/'
80
- doc.add_namespace NS_EWS_TYPES, 'http://schemas.microsoft.com/exchange/services/2006/types'
81
- doc.add_namespace NS_EWS_MESSAGES, 'http://schemas.microsoft.com/exchange/services/2006/messages'
82
- end
83
-
84
- def on_after_create_http_request(req)
85
- begin
86
- req.set_auth @@user, @@pass
87
- rescue NameError => e
88
- raise EwsLoginError, "Please remember to set your credential information."
89
- end
90
- end
91
-
92
- def on_http_error(response)
93
- case response.status
94
- when 401
95
- raise EwsLoginError, "Failed to login to EWS at #{uri}. Please check your credentials."
96
- when 404
97
- raise EwsError, "File not found (404): #{uri} Please check the endpoint URL. Body: #{response.body}"
98
- else
99
- raise EwsError, "Unknown error (#{response.status}): #{uri} : Body: #{response.body}"
100
- end
101
- end
102
-
103
- # ********** End Hooks **********
104
-
105
-
106
- # Resolve ambiguous e-mail addresses and display names
107
- # @see http://msdn.microsoft.com/en-us/library/aa565329.aspx ResolveNames
108
- # @see http://msdn.microsoft.com/en-us/library/aa581054.aspx UnresolvedEntry
109
- #
110
- # @param [String] name an unresolved entry
111
- # @param [Boolean] full_contact_data whether or not to return full contact info
112
- # @param [Hash] opts optional parameters to this method
113
- # @option opts [String] :search_scope where to seach for this entry, one of
114
- # SOAP::Contacts, SOAP::ActiveDirectory, SOAP::ActiveDirectoryContacts (default),
115
- # SOAP::ContactsActiveDirectory
116
- # @option opts [String, FolderId] :parent_folder_id either the name of a folder or
117
- # it's numerical ID. @see http://msdn.microsoft.com/en-us/library/aa565998.aspx
118
- def resolve_names(name, full_contact_data = true, opts = {})
119
- action = "#{SOAP_ACTION_PREFIX}/ResolveNames"
120
- resp = invoke("#{NS_EWS_MESSAGES}:ResolveNames", action) do |root|
121
- build!(root) do
122
- root.set_attr('ReturnFullContactData',full_contact_data)
123
- root.add("#{NS_EWS_MESSAGES}:UnresolvedEntry",name)
124
- end
125
- end
126
- parse!(resp)
127
- end
128
-
129
-
130
- # Exposes the full membership of distribution lists.
131
- # @see http://msdn.microsoft.com/en-us/library/aa494152.aspx ExpandDL
132
- #
133
- # @param [String] dist_email The e-mail address associated with the Distribution List
134
- # @todo Fully support all of the ExpandDL operations. Today it just supports
135
- # taking an e-mail address as an argument
136
- def expand_dl(dist_email)
137
- action = "#{SOAP_ACTION_PREFIX}/ExpandDL"
138
- resp = invoke("#{NS_EWS_MESSAGES}:ExpandDL", action) do |root|
139
- build!(root) do
140
- mailbox!(root, {:email_address => {:text => dist_email}})
141
- end
142
- end
143
- parse!(resp)
144
- end
145
-
146
- # Find subfolders of an identified folder
147
- # @see http://msdn.microsoft.com/en-us/library/aa563918.aspx
148
- #
149
- # @param [Array] parent_folder_ids An Array of folder ids, either a
150
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
151
- # @param [String] traversal Shallow/Deep/SoftDeleted
152
- # @param [Hash] folder_shape defines the FolderShape node
153
- # See: http://msdn.microsoft.com/en-us/library/aa494311.aspx
154
- # @option folder_shape [String] :base_shape IdOnly/Default/AllProperties
155
- # @option folder_shape :additional_properties
156
- # See: http://msdn.microsoft.com/en-us/library/aa563810.aspx
157
- # @param [Hash] opts optional parameters to this method
158
- def find_folder(parent_folder_ids = [:root], traversal = 'Shallow', folder_shape = {:base_shape => 'Default'}, opts = {})
159
- action = "#{SOAP_ACTION_PREFIX}/FindFolder"
160
- resp = invoke("#{NS_EWS_MESSAGES}:FindFolder", action) do |root|
161
- build!(root) do
162
- restriction = opts.delete(:restriction)
163
- root.set_attr('Traversal', traversal)
164
- folder_shape!(root, folder_shape)
165
- root.add("#{NS_EWS_MESSAGES}:Restriction") do |r|
166
- add_hierarchy!(r, restriction)
167
- end unless restriction.nil?
168
- parent_folder_ids!(root, parent_folder_ids)
169
- end
170
- end
171
- parse!(resp)
172
- end
173
-
174
- # Identifies items that are located in a specified folder
175
- # @see http://msdn.microsoft.com/en-us/library/aa566107.aspx
176
- #
177
- # @param [Array] parent_folder_ids An Array of folder ids, either a
178
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
179
- # @param [String] traversal Shallow/Deep/SoftDeleted
180
- # @param [Hash] item_shape defines the FolderShape node
181
- # See: http://msdn.microsoft.com/en-us/library/aa494311.aspx
182
- # @option item_shape [String] :base_shape IdOnly/Default/AllProperties
183
- # @option item_shape :additional_properties
184
- # See: http://msdn.microsoft.com/en-us/library/aa563810.aspx
185
- # @param [Hash] opts optional parameters to this method
186
- # @option opts [Hash] :calendar_view Limit FindItem by a start and end date
187
- # {:calendar_view => {:max_entries_returned => 2, :start => <DateTime Obj>, :end => <DateTime Obj>}}
188
- def find_item(parent_folder_ids, traversal = 'Shallow', item_shape = {:base_shape => 'Default'}, opts = {})
189
- action = "#{SOAP_ACTION_PREFIX}/FindItem"
190
- resp = invoke("#{NS_EWS_MESSAGES}:FindItem", action) do |root|
191
- build!(root) do
192
- root.set_attr('Traversal', traversal)
193
- item_shape!(root, item_shape)
194
- query_strings = opts.delete(:query_string)
195
- restriction = opts.delete(:restriction)
196
- if(opts.has_key?(:calendar_view))
197
- cal_view = opts[:calendar_view]
198
- cal_view.each_pair do |k,v|
199
- cal_view[k] = v.to_s
200
- end
201
- end
202
- add_hierarchy!(root, opts, NS_EWS_MESSAGES)
203
- #query_strings!(query_strings)
204
- root.add("#{NS_EWS_MESSAGES}:Restriction") do |r|
205
- add_hierarchy!(r, restriction)
206
- end unless restriction.nil?
207
- parent_folder_ids!(root, parent_folder_ids)
208
- end
209
- end
210
- parse!(resp)
211
- end
212
-
213
- # Gets folders from the Exchange store
214
- # @see http://msdn.microsoft.com/en-us/library/aa580274.aspx
215
- #
216
- # @param [Array] folder_ids An Array of folder ids, either a
217
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
218
- # @param [Hash] folder_shape defines the FolderShape node
219
- # See: http://msdn.microsoft.com/en-us/library/aa494311.aspx
220
- # @option folder_shape [String] :base_shape IdOnly/Default/AllProperties
221
- # @option folder_shape :additional_properties
222
- # See: http://msdn.microsoft.com/en-us/library/aa563810.aspx
223
- # @param [String,nil] act_as User to act on behalf as. This user must have been
224
- # given delegate access to this folder or else this operation will fail.
225
- # @param [Hash] opts optional parameters to this method
226
- def get_folder(folder_ids, folder_shape = {:base_shape => 'Default'}, act_as = nil)
227
- action = "#{SOAP_ACTION_PREFIX}/GetFolder"
228
- resp = invoke("#{NS_EWS_MESSAGES}:GetFolder", action) do |root|
229
- build!(root) do
230
- folder_shape!(root, folder_shape)
231
- folder_ids!(root, folder_ids, act_as)
232
- end
233
- end
234
- parse!(resp)
235
- end
236
-
237
- # Converts item and folder identifiers between formats that are accepted by Microsoft Exchange
238
- # @see http://msdn.microsoft.com/en-us/library/bb799665.aspx
239
- #
240
- # @param [String] id identifier to convert
241
- # @param [String] mailbox mailbox where is located the item
242
- # @param [String] alternate_id_format Format of the identifier to be converted, by default Exchange Web Services identifier
243
- # @param [String] destination_format Destination format, by default Outlook identifier
244
- def convert_id(id, mailbox, alternate_id_format = 'EwsId', destination_format = 'HexEntryId')
245
- action = "#{SOAP_ACTION_PREFIX}/ConvertId"
246
- resp = invoke("#{NS_EWS_MESSAGES}:ConvertId", action) do |root|
247
- build!(root) do
248
- root.set_attr('DestinationFormat', destination_format)
249
- root.add("#{NS_EWS_MESSAGES}:SourceIds") do |source_ids|
250
- source_ids.add("#{NS_EWS_TYPES}:AlternateId") do |alternate_id|
251
- alternate_id.set_attr('Format', alternate_id_format)
252
- alternate_id.set_attr('Id', id)
253
- alternate_id.set_attr('Mailbox', mailbox)
254
- end
255
- end
256
- end
257
- end
258
- parse!(resp)
259
- end
260
-
261
- # Creates folders, calendar folders, contacts folders, tasks folders, and search folders.
262
- # @see http://msdn.microsoft.com/en-us/library/aa563574.aspx CreateFolder
263
- #
264
- # @param [String,Symbol] parent_folder_id either the name of a folder or it's
265
- # numerical ID. See: http://msdn.microsoft.com/en-us/library/aa565998.aspx
266
- # @param [Array,String] folder_name The display name for the new folder or folders
267
- def create_folder(parent_folder_id, folder_name)
268
- action = "#{SOAP_ACTION_PREFIX}/CreateFolder"
269
- resp = invoke("#{NS_EWS_MESSAGES}:CreateFolder", action) do |root|
270
- build!(root) do
271
- root.add("#{NS_EWS_MESSAGES}:ParentFolderId") do |pfid|
272
- folder_id!(pfid, parent_folder_id)
273
- end
274
- folder_name = (folder_name.is_a?(Array)) ? folder_name : [folder_name]
275
- root.add("#{NS_EWS_MESSAGES}:Folders") do |fids|
276
- folder_name.each do |f|
277
- add_hierarchy!(fids, {:folder => {:display_name => {:text => f}}})
278
- end
279
- end
280
- end
281
- end
282
- parse!(resp)
283
- end
284
-
285
- # Deletes folders from a mailbox.
286
- # @see http://msdn.microsoft.com/en-us/library/aa564767.aspx DeleteFolder
287
- #
288
- # @param [Array,String,Symbol] folder_id either the name of a folder or it's
289
- # numerical ID. See: http://msdn.microsoft.com/en-us/library/aa565998.aspx
290
- # @param [String,nil] delete_type Type of delete to do: HardDelete/SoftDelete/MoveToDeletedItems
291
- def delete_folder(folder_id, delete_type = 'MoveToDeletedItems')
292
- action = "#{SOAP_ACTION_PREFIX}/DeleteFolder"
293
- resp = invoke("#{NS_EWS_MESSAGES}:DeleteFolder", action) do |root|
294
- build!(root) do
295
- root.set_attr('DeleteType', delete_type)
296
- folder_id = (folder_id.is_a?(Array)) ? folder_id : [folder_id]
297
- folder_ids!(root, folder_id)
298
- end
299
- end
300
- parse!(resp)
301
- end
302
-
303
- def update_folder
304
- action = "#{SOAP_ACTION_PREFIX}/UpdateFolder"
305
- resp = invoke("#{NS_EWS_MESSAGES}:UpdateFolder", action) do |update_folder|
306
- build_update_folder!(update_folder)
307
- end
308
- parse_update_folder(resp)
309
- end
310
-
311
- def move_folder
312
- action = "#{SOAP_ACTION_PREFIX}/MoveFolder"
313
- resp = invoke("#{NS_EWS_MESSAGES}:MoveFolder", action) do |move_folder|
314
- build_move_folder!(move_folder)
315
- end
316
- parse_move_folder(resp)
317
- end
318
-
319
- def copy_folder
320
- action = "#{SOAP_ACTION_PREFIX}/CopyFolder"
321
- resp = invoke("#{NS_EWS_MESSAGES}:CopyFolder", action) do |copy_folder|
322
- build_copy_folder!(copy_folder)
323
- end
324
- parse_copy_folder(resp)
325
- end
326
-
327
- # Used to subscribe client applications to either push or pull notifications.
328
- # @see http://msdn.microsoft.com/en-us/library/aa566188.aspx Subscribe on MSDN
329
- #
330
- # @param [Array] folder_ids An Array of folder ids, either a
331
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
332
- # @param [Array] event_types An Array of EventTypes that we should track.
333
- # Available types are, CopiedEvent, CreatedEvent, DeletedEvent, ModifiedEvent,
334
- # MovedEvent, NewMailEvent, FreeBusyChangedEvent
335
- # @param [Integer] timeout The number of minutes in which the subscription
336
- # will timeout after not receiving a get_events operation.
337
- # @todo Decide how/if to handle the optional SubscribeToAllFolders attribute of
338
- # the PullSubscriptionRequest element.
339
- def subscribe(folder_ids, event_types, timeout = 10)
340
- action = "#{SOAP_ACTION_PREFIX}/Subscribe"
341
- resp = invoke("#{NS_EWS_MESSAGES}:Subscribe", action) do |root|
342
- build!(root) do
343
- pull_subscription_request!(folder_ids, event_types, timeout)
344
- end
345
- end
346
- parse!(resp)
347
- end
348
-
349
- # Used to subscribe client applications to either push or pull notifications.
350
- # @see http://msdn.microsoft.com/en-us/library/aa566188.aspx Subscribe on MSDN
351
- def push_subscribe(folder_ids, event_types, url, watermark=nil, status_frequency=5)
352
- action = "#{SOAP_ACTION_PREFIX}/Subscribe"
353
- resp = invoke("#{NS_EWS_MESSAGES}:Subscribe", action) do |root|
354
- build!(root) do
355
- push_subscription_request!(folder_ids, event_types, url, watermark, status_frequency)
356
- end
357
- end
358
- parse!(resp)
359
-
360
- end
361
-
362
- # End a pull notification subscription.
363
- # @see http://msdn.microsoft.com/en-us/library/aa564263.aspx
364
- #
365
- # @param [String] subscription_id The Id of the subscription
366
- def unsubscribe(subscription_id)
367
- action = "#{SOAP_ACTION_PREFIX}/Unsubscribe"
368
- resp = invoke("#{NS_EWS_MESSAGES}:Unsubscribe", action) do |root|
369
- build!(root) do
370
- subscription_id!(root, subscription_id)
371
- end
372
- end
373
- parse!(resp)
374
- end
375
-
376
- # Used by pull subscription clients to request notifications from the Client Access server
377
- # @see http://msdn.microsoft.com/en-us/library/aa566199.aspx GetEvents on MSDN
378
- #
379
- # @param [String] subscription_id Subscription identifier
380
- # @param [String] watermark Event bookmark in the events queue
381
- def get_events(subscription_id, watermark)
382
- action = "#{SOAP_ACTION_PREFIX}/GetEvents"
383
- resp = invoke("#{NS_EWS_MESSAGES}:GetEvents", action) do |root|
384
- build!(root) do
385
- subscription_id!(root, subscription_id)
386
- watermark!(root, watermark)
387
- end
388
- end
389
- parse!(resp)
390
- end
391
-
392
- # Defines a request to synchronize a folder hierarchy on a client
393
- # @see http://msdn.microsoft.com/en-us/library/aa580990.aspx
394
- def sync_folder_hierarchy
395
- sync_state = nil
396
- folder_id = :publicfoldersroot
397
- action = "#{SOAP_ACTION_PREFIX}/SyncFolderHierarchy"
398
- resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderHierarchy", action) do |root|
399
- build!(root) do
400
- folder_shape!(root, {:base_shape => 'Default'})
401
- root.add("#{NS_EWS_MESSAGES}:SyncFolderId") do |sfid|
402
- folder_id!(sfid, folder_id)
403
- end
404
- sync_state!(root, sync_state) unless sync_state.nil?
405
- end
406
- end
407
- parse!(resp)
408
- end
409
-
410
- # Synchronizes items between the Exchange server and the client
411
- # @see http://msdn.microsoft.com/en-us/library/aa563967.aspx
412
- #
413
- # @param [String, Symbol] folder_id either a DistinguishedFolderId
414
- # (must me a Symbol) or a FolderId (String)
415
- # @param [String] sync_state Base-64 encoded string used to determine
416
- # where we are in the sync process.
417
- # @param [Integer] max_changes The amount of items to sync per call
418
- # to SyncFolderItems
419
- # @param [Hash] item_shape defines the ItemShape node
420
- # See: http://msdn.microsoft.com/en-us/library/aa565261.aspx
421
- # @option item_shape [String] :base_shape IdOnly/Default/AllProperties
422
- # @option item_shape :additional_properties
423
- # See: http://msdn.microsoft.com/en-us/library/aa565261.aspx
424
- # @param [Hash] opts optional parameters to this method
425
- def sync_folder_items(folder_id, sync_state = nil, max_changes = 256, item_shape = {:base_shape => 'Default'}, opts = {})
426
- action = "#{SOAP_ACTION_PREFIX}/SyncFolderItems"
427
- resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderItems", action) do |root|
428
- build!(root) do
429
- item_shape!(root, item_shape)
430
- root.add("#{NS_EWS_MESSAGES}:SyncFolderId") do |sfid|
431
- folder_id!(sfid, folder_id)
432
- end
433
- sync_state!(root, sync_state) unless sync_state.nil?
434
- root.add("#{NS_EWS_MESSAGES}:MaxChangesReturned", max_changes)
435
- end
436
- end
437
- parse!(resp)
438
- end
439
-
440
- # Gets items from the Exchange store
441
- # @see http://msdn.microsoft.com/en-us/library/aa565934.aspx
442
- #
443
- # @param [Array] item_ids An Array of item ids
444
- # @param [Hash] item_shape defines the ItemShape node
445
- # See: http://msdn.microsoft.com/en-us/library/aa565261.aspx
446
- # @option item_shape [String] :base_shape ('Default') IdOnly/Default/AllProperties
447
- # @option item_shape :additional_properties
448
- # See: http://msdn.microsoft.com/en-us/library/aa563810.aspx
449
- # @param [Hash] opts optional parameters to this method
450
- def get_item(item_ids, item_shape = {})
451
- action = "#{SOAP_ACTION_PREFIX}/GetItem"
452
- item_shape[:base_shape] = 'Default' unless item_shape.has_key?(:base_shape)
453
- resp = invoke("#{NS_EWS_MESSAGES}:GetItem", action) do |root|
454
- build!(root) do
455
- item_shape!(root, item_shape)
456
- item_ids!(root, item_ids)
457
- end
458
- end
459
- parse!(resp)
460
- end
461
-
462
- # Operation is used to create e-mail messages
463
- # This is actually a CreateItem operation but they differ for different types
464
- # of Exchange objects so it is named appropriately here.
465
- # @see http://msdn.microsoft.com/en-us/library/aa566468.aspx
466
- #
467
- # @param [String, Symbol] folder_id The folder to save this message in. Either a
468
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
469
- # @param [Hash, Array] items An array of item Hashes or a single item Hash. Hash
470
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
471
- # Values should be based on values found here: http://msdn.microsoft.com/en-us/library/aa494306.aspx
472
- # @param [String] message_disposition "SaveOnly/SendOnly/SendAndSaveCopy"
473
- # See: http://msdn.microsoft.com/en-us/library/aa565209.aspx
474
- def create_message_item(folder_id, items, message_disposition = 'SaveOnly')
475
- action = "#{SOAP_ACTION_PREFIX}/CreateItem"
476
- resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
477
- build!(node) do
478
- create_item!(folder_id, items, message_disposition, send_invites=false, 'message')
479
- end
480
- end
481
- parse!(resp)
482
- end
483
-
484
- # Operation is used to create calendar items
485
- # @see http://msdn.microsoft.com/en-us/library/aa564690.aspx
486
- #
487
- # @param [String, Symbol] folder_id The folder to create this item in. Either a
488
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
489
- # @param [Hash, Array] items An array of item Hashes or a single item Hash. Hash
490
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
491
- # Values should be based on values found here: http://msdn.microsoft.com/en-us/library/aa564765.aspx
492
- # @param [String] send_invites "SendToNone/SendOnlyToAll/SendToAllAndSaveCopy"
493
- def create_calendar_item(folder_id, items, send_invites = 'SendToAllAndSaveCopy')
494
- action = "#{SOAP_ACTION_PREFIX}/CreateItem"
495
- resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
496
- build!(node) do
497
- create_item!(folder_id, items, message_disposition=false, send_invites, 'calendar')
498
- end
499
- end
500
- parse!(resp)
501
- end
502
-
503
- # Operation is used to create task items
504
- # This is actually a CreateItem operation but they differ for different types
505
- # of Exchange objects so it is named appropriately here.
506
- # @see http://msdn.microsoft.com/en-us/library/aa563439.aspx
507
- #
508
- # @param [String, Symbol] folder_id The folder to save this task in. Either a
509
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
510
- # @param [Hash, Array] items An array of item Hashes or a single item Hash. Hash
511
- # values should be based on values found here: http://msdn.microsoft.com/en-us/library/aa494306.aspx
512
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
513
- # @param [String] message_disposition "SaveOnly/SendOnly/SendAndSaveCopy"
514
- # See: http://msdn.microsoft.com/en-us/library/aa565209.aspx
515
- def create_task_item(folder_id, items, message_disposition = 'SaveOnly')
516
- action = "#{SOAP_ACTION_PREFIX}/CreateItem"
517
- resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
518
- build!(node) do
519
- create_item!(folder_id, items, message_disposition, false, 'task')
520
- end
521
- end
522
- parse!(resp)
523
- end
524
-
525
- # Operation is used to create contact items
526
- # This is actually a CreateItem operation but they differ for different types
527
- # of Exchange objects so it is named appropriately here.
528
- # @see # http://msdn.microsoft.com/en-us/library/aa580529.aspx
529
- #
530
- # @param [String, Symbol] folder_id The folder to save this task in. Either a
531
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String)
532
- # @param [Hash, Array] items An array of item Hashes or a single item Hash. Hash
533
- # values should be based on values found here: http://msdn.microsoft.com/en-us/library/aa581315.aspx
534
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
535
- def create_contact_item(folder_id, items)
536
- action = "#{SOAP_ACTION_PREFIX}/CreateItem"
537
- resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
538
- build!(node) do
539
- create_item!(folder_id, items, nil, false, 'contact')
540
- end
541
- end
542
- parse!(resp)
543
- end
544
-
545
- # Delete an item from a mailbox in the Exchange store
546
- # @see http://msdn.microsoft.com/en-us/library/aa562961.aspx
547
- # @param [Array] item_ids An Array of item ids
548
- # @param [String] delete_type Type of deletion: "HardDelete/SoftDelete/MoveToDeletedItems"
549
- # @param [String, nil] send_meeting_cancellations "SendToNone/SendOnlyToAll/SendToAllAndSaveCopy"
550
- # This is only applicable to CalendarItems and should be nil otherwise, which is the default
551
- # @param [String, nil] affected_task_occurrences "AllOccurrences/SpecifiedOccurrenceOnly"
552
- # This is really only related to tasks and can be nil otherwise, which is the default.
553
- def delete_item(item_ids, delete_type, send_meeting_cancellations = nil, affected_task_occurrences = nil)
554
- action = "#{SOAP_ACTION_PREFIX}/DeleteItem"
555
- resp = invoke("#{NS_EWS_MESSAGES}:DeleteItem", action) do |root|
556
- build!(root) do
557
- root.set_attr('DeleteType', delete_type)
558
- root.set_attr('SendMeetingCancellations', send_meeting_cancellations) unless send_meeting_cancellations.nil?
559
- root.set_attr('AffectedTaskOccurrences', affected_task_occurrences) unless affected_task_occurrences.nil?
560
- item_ids!(root, item_ids)
561
- end
562
- end
563
- parse!(resp)
564
- end
565
-
566
- # Used to modify the properties of an existing item in the Exchange store
567
- # @see http://msdn.microsoft.com/en-us/library/aa581084.aspx
568
- # @param [Array] item_ids An Array of item ids
569
- # @param [Hash] changes a Hash of changes to be fed to auto_hierarchy!
570
- # @param [Hash] opts various attributes to set for this update. See the Technet docs for more info
571
- def update_item(item_ids, changes, opts = {:message_disposition => 'SaveOnly', :conflict_resolution => 'AutoResolve'})
572
- action = "#{SOAP_ACTION_PREFIX}/UpdateItem"
573
- resp = invoke("#{NS_EWS_MESSAGES}:UpdateItem", action) do |root|
574
- build!(root) do
575
- root.set_attr('MessageDisposition', opts[:message_disposition]) if opts.has_key?(:message_disposition)
576
- root.set_attr('ConflictResolution', opts[:conflict_resolution]) if opts.has_key?(:message_disposition)
577
- root.set_attr('SendMeetingInvitationsOrCancellations', opts[:send_meeting_invitations_or_cancellations]) if opts.has_key?(:send_meeting_invitations_or_cancellations)
578
- item_changes!(root, item_ids, changes)
579
- end
580
- end
581
- parse!(resp)
582
- end
583
-
584
- # Used to send e-mail messages that are located in the Exchange store.
585
- # @see http://msdn.microsoft.com/en-us/library/aa580238.aspx
586
- # @param [Array<Hash>] item_ids An Array of item ids. These item_ids should be a Hash of
587
- # :id and :change_key.
588
- # @param [Boolean] save_item Save item after sending (Think sent-items)
589
- # @param [String, Symbol,nil] saved_item_folder The folder to save this item in. Either a
590
- # DistinguishedFolderId (must me a Symbol) or a FolderId (String). Just leave
591
- # it blank for the default :sentitems
592
- def send_item(item_ids, save_item=true, saved_item_folder=nil)
593
- action = "#{SOAP_ACTION_PREFIX}/SendItem"
594
- resp = invoke("#{NS_EWS_MESSAGES}:SendItem", action) do |root|
595
- build!(root) do
596
- root.set_attr('SaveItemToFolder', save_item)
597
- item_ids!(root,item_ids)
598
- saved_item_folder_id!(root,saved_item_folder) unless saved_item_folder.nil?
599
- end
600
- end
601
- parse!(resp)
602
- end
603
-
604
- # Used to move one or more items to a single destination folder.
605
- # @see http://msdn.microsoft.com/en-us/library/aa565781.aspx
606
- # @param [Array] item_ids An Array of item ids
607
- # @param [String, Symbol] folder_id either a DistinguishedFolderId
608
- # (must me a Symbol) or a FolderId (String)
609
- def move_item(item_ids, folder_id)
610
- action = "#{SOAP_ACTION_PREFIX}/MoveItem"
611
- resp = invoke("#{NS_EWS_MESSAGES}:MoveItem", action) do |root|
612
- build!(root) do
613
- to_folder_id!(root, folder_id)
614
- item_ids!(root, item_ids)
615
- end
616
- end
617
- parse!(resp)
618
- end
619
-
620
- # Copies items and puts the items in a different folder
621
- # @see http://msdn.microsoft.com/en-us/library/aa565012.aspx
622
- # @param [Array] item_ids An Array of item ids
623
- # @param [String, Symbol] folder_id either a DistinguishedFolderId
624
- # (must me a Symbol) or a FolderId (String)
625
- def copy_item(item_ids, folder_id)
626
- action = "#{SOAP_ACTION_PREFIX}/CopyItem"
627
- resp = invoke("#{NS_EWS_MESSAGES}:CopyItem", action) do |root|
628
- build!(root) do
629
- to_folder_id!(root, folder_id)
630
- item_ids!(root, item_ids)
631
- end
632
- end
633
- parse!(resp)
634
- end
635
-
636
- # Creates either an item or file attachment and attaches it to the specified item.
637
- # @see http://msdn.microsoft.com/en-us/library/aa565877.aspx
638
- # @param [String,Hash] parent_id The id of the Item. If this is a Hash
639
- # it should contain the Id and the ChangeKey.
640
- # @option parent_id [String] :id The item Id
641
- # @option parent_id [String] :change_key The ChangeKey
642
- # @param [Array<Hash>] files An Array of Base64 encoded Strings with an associated name
643
- # hash format= :name => <name>, :content => <Base64 encoded string>
644
- # @param [Array] items Exchange Items to attach to this Item
645
- # @todo Need to implement attachment of Item types
646
- def create_attachment(parent_id, files = [], items = [])
647
- action = "#{SOAP_ACTION_PREFIX}/CreateAttachment"
648
- resp = invoke("#{NS_EWS_MESSAGES}:CreateAttachment", action) do |root|
649
- build!(root) do
650
- item_id!(root, parent_id, "#{NS_EWS_MESSAGES}:ParentItemId")
651
- attachments!(root, files, items)
652
- end
653
- end
654
- parse!(resp)
655
- end
656
-
657
- def delete_attachment
658
- action = "#{SOAP_ACTION_PREFIX}/DeleteAttachment"
659
- resp = invoke("#{NS_EWS_MESSAGES}:DeleteAttachment", action) do |delete_attachment|
660
- build_delete_attachment!(delete_attachment)
661
- end
662
- parse_delete_attachment(resp)
663
- end
664
-
665
- # Used to retrieve existing attachments on items in the Exchange store
666
- # @see http://msdn.microsoft.com/en-us/library/aa494316.aspx
667
- # @param [Array] attachment_ids Attachment Ids to fetch
668
- def get_attachment(attachment_ids)
669
- action = "#{SOAP_ACTION_PREFIX}/GetAttachment"
670
- resp = invoke("#{NS_EWS_MESSAGES}:GetAttachment", action) do |root|
671
- build!(root) do
672
- attachment_shape!(root)
673
- attachment_ids!(root, attachment_ids)
674
- end
675
- end
676
- parse!(resp)
677
- end
678
-
679
- def create_managed_folder
680
- action = "#{SOAP_ACTION_PREFIX}/CreateManagedFolder"
681
- resp = invoke("#{NS_EWS_MESSAGES}:CreateManagedFolder", action) do |create_managed_folder|
682
- build_create_managed_folder!(create_managed_folder)
683
- end
684
- parse_create_managed_folder(resp)
685
- end
686
-
687
- # Retrieves the delegate settings for a specific mailbox.
688
- # @see http://msdn.microsoft.com/en-us/library/bb799735.aspx
689
- #
690
- # @param [String] owner The user that is delegating permissions
691
- def get_delegate(owner)
692
- action = "#{SOAP_ACTION_PREFIX}/GetDelegate"
693
- resp = invoke("#{NS_EWS_MESSAGES}:GetDelegate", action) do |root|
694
- root.set_attr('IncludePermissions', 'true')
695
- build!(root) do
696
- mailbox!(root, {:email_address => {:text => owner}})
697
- end
698
- end
699
- parse!(resp)
700
- end
701
-
702
- # Adds one or more delegates to a principal's mailbox and sets specific access permissions.
703
- # @see http://msdn.microsoft.com/en-us/library/bb856527.aspx
704
- #
705
- # @param [String] owner The user that is delegating permissions
706
- # @param [String] delegate The user that is being given delegate permission
707
- # @param [Hash] permissions A hash of permissions that will be delegated.
708
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
709
- def add_delegate(owner, delegate, permissions)
710
- action = "#{SOAP_ACTION_PREFIX}/AddDelegate"
711
- resp = invoke("#{NS_EWS_MESSAGES}:AddDelegate", action) do |root|
712
- build!(root) do
713
- add_delegate!(owner, delegate, permissions)
714
- end
715
- end
716
- parse!(resp)
717
- end
718
-
719
- # Removes one or more delegates from a user's mailbox.
720
- # @see http://msdn.microsoft.com/en-us/library/bb856564.aspx
721
- #
722
- # @param [String] owner The user that is delegating permissions
723
- # @param [String] delegate The user that is being given delegate permission
724
- def remove_delegate(owner, delegate)
725
- action = "#{SOAP_ACTION_PREFIX}/RemoveDelegate"
726
- resp = invoke("#{NS_EWS_MESSAGES}:RemoveDelegate", action) do |root|
727
- build!(root) do
728
- remove_delegate!(owner, delegate)
729
- end
730
- end
731
- parse!(resp)
732
- end
733
-
734
- # Updates delegate permissions on a principal's mailbox
735
- # @see http://msdn.microsoft.com/en-us/library/bb856529.aspx
736
- #
737
- # @param [String] owner The user that is delegating permissions
738
- # @param [String] delegate The user that is being given delegate permission
739
- # @param [Hash] permissions A hash of permissions that will be delegated.
740
- # This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
741
- def update_delegate(owner, delegate, permissions)
742
- action = "#{SOAP_ACTION_PREFIX}/UpdateDelegate"
743
- resp = invoke("#{NS_EWS_MESSAGES}:UpdateDelegate", action) do |root|
744
- build!(root) do
745
- add_delegate!(owner, delegate, permissions)
746
- end
747
- end
748
- parse!(resp)
749
- end
750
-
751
- # Provides detailed information about the availability of a set of users, rooms, and resources
752
- # within a specified time window.
753
- # @see http://msdn.microsoft.com/en-us/library/aa564001.aspx
754
- def get_user_availability(email_address, start_time, end_time)
755
- action = "#{SOAP_ACTION_PREFIX}/GetUserAvailability"
756
- resp = invoke("#{NS_EWS_MESSAGES}:GetUserAvailabilityRequest", action) do |root|
757
- build!(root) do
758
- get_user_availability!(email_address, start_time, end_time)
759
- end
760
- end
761
- parse!(resp)
762
- end
763
-
764
- # Gets a mailbox user's Out of Office (OOF) settings and messages.
765
- # @see http://msdn.microsoft.com/en-us/library/aa563465.aspx
766
- def get_user_oof_settings(mailbox)
767
- action = "#{SOAP_ACTION_PREFIX}/GetUserOofSettings"
768
- resp = invoke("#{NS_EWS_MESSAGES}:GetUserOofSettingsRequest", action) do |root|
769
- build!(root) do
770
- mailbox!(root,mailbox[:mailbox],NS_EWS_TYPES)
771
- end
772
- end
773
- parse!(resp)
774
- end
775
-
776
- # Sets a mailbox user's Out of Office (OOF) settings and message.
777
- # @see http://msdn.microsoft.com/en-us/library/aa580294.aspx
778
- def set_user_oof_settings(mailbox, oof_state, ext_audience, dt_start, dt_end, int_msg, ext_mg)
779
- action = "#{SOAP_ACTION_PREFIX}/SetUserOofSettings"
780
- resp = invoke("#{NS_EWS_MESSAGES}:SetUserOofSettings", action) do |root|
781
- build!(root)
782
- end
783
- parse!(resp)
784
- end
785
-
786
-
787
- # Private Methods (Builders and Parsers)
788
- private
789
-
790
- def build!(node, opts = {}, &block)
791
- EwsBuilder.new(node, opts, &block)
792
- end
793
-
794
- def parse!(response, opts = {})
795
- return response if @@raw_soap
796
- raise EwsError, "Can't parse an empty response. Please check your endpoint." if(response.nil?)
797
- EwsParser.new(response).parse(opts)
798
- end
799
-
800
- # Override the superclasses' invoke so we can add http_options to each request
801
- def invoke(msg, action)
802
- raise EwsError, "EWS Endpoint not set." if uri.nil?
803
- begin
804
- super(msg, {:soap_action => action, :http_options => @@http_options})
805
- rescue SocketError
806
- raise EwsError, "Could not connect to endpoint: #{uri}"
807
- end
808
- end
809
-
810
- end # class ExchangeWebService
811
- end # module SOAP
812
- end # EWS
813
- end # Viewpoint