viewpoint 0.1.26 → 1.1.1

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