viewpoint 1.2.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/README.md +11 -6
- data/lib/ews/calendar_accessors.rb +37 -33
- data/lib/ews/connection.rb +152 -125
- data/lib/ews/connection_helper.rb +36 -33
- data/lib/ews/convert_accessors.rb +58 -54
- data/lib/ews/errors.rb +59 -53
- data/lib/ews/ews_client.rb +92 -79
- data/lib/ews/exceptions/exceptions.rb +61 -61
- data/lib/ews/folder_accessors.rb +235 -234
- data/lib/ews/impersonation.rb +29 -23
- data/lib/ews/item_accessors.rb +215 -213
- data/lib/ews/mailbox_accessors.rb +82 -79
- data/lib/ews/meeting_accessors.rb +38 -31
- data/lib/ews/message_accessors.rb +83 -81
- data/lib/ews/push_subscription_accessors.rb +29 -27
- data/lib/ews/room_accessors.rb +48 -46
- data/lib/ews/roomlist_accessors.rb +47 -45
- data/lib/ews/soap/builders/ews_builder.rb +1191 -1176
- data/lib/ews/soap/ews_response.rb +68 -73
- data/lib/ews/soap/ews_soap_availability_response.rb +57 -57
- data/lib/ews/soap/ews_soap_free_busy_response.rb +115 -117
- data/lib/ews/soap/ews_soap_response.rb +99 -101
- data/lib/ews/soap/ews_soap_room_response.rb +45 -45
- data/lib/ews/soap/ews_soap_roomlist_response.rb +45 -46
- data/lib/ews/soap/exchange_availability.rb +54 -52
- data/lib/ews/soap/exchange_data_services.rb +693 -711
- data/lib/ews/soap/exchange_notification.rb +123 -128
- data/lib/ews/soap/exchange_synchronization.rb +82 -82
- data/lib/ews/soap/exchange_time_zones.rb +41 -44
- data/lib/ews/soap/exchange_user_configuration.rb +30 -27
- data/lib/ews/soap/exchange_web_service.rb +237 -233
- data/lib/ews/soap/parsers/ews_parser.rb +46 -42
- data/lib/ews/soap/parsers/ews_sax_document.rb +63 -58
- data/lib/ews/soap/response_message.rb +69 -68
- data/lib/ews/soap/responses/create_attachment_response_message.rb +45 -45
- data/lib/ews/soap/responses/create_item_response_message.rb +26 -25
- data/lib/ews/soap/responses/find_item_response_message.rb +76 -78
- data/lib/ews/soap/responses/get_events_response_message.rb +52 -51
- data/lib/ews/soap/responses/send_notification_response_message.rb +53 -51
- data/lib/ews/soap/responses/subscribe_response_message.rb +37 -34
- data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +38 -35
- data/lib/ews/soap/responses/sync_folder_items_response_message.rb +38 -35
- data/lib/ews/soap.rb +27 -26
- data/lib/ews/templates/calendar_item.rb +64 -60
- data/lib/ews/templates/forward_item.rb +19 -17
- data/lib/ews/templates/message.rb +61 -58
- data/lib/ews/templates/reply_to_item.rb +20 -18
- data/lib/ews/templates/task.rb +55 -55
- data/lib/ews/types/attachment.rb +75 -74
- data/lib/ews/types/attendee.rb +27 -25
- data/lib/ews/types/calendar_folder.rb +58 -59
- data/lib/ews/types/calendar_item.rb +133 -131
- data/lib/ews/types/contact.rb +11 -5
- data/lib/ews/types/contacts_folder.rb +10 -5
- data/lib/ews/types/copied_event.rb +47 -48
- data/lib/ews/types/created_event.rb +22 -20
- data/lib/ews/types/deleted_event.rb +22 -20
- data/lib/ews/types/distribution_list.rb +11 -5
- data/lib/ews/types/event.rb +60 -59
- data/lib/ews/types/export_items_response_message.rb +54 -50
- data/lib/ews/types/file_attachment.rb +63 -61
- data/lib/ews/types/folder.rb +58 -57
- data/lib/ews/types/free_busy_changed_event.rb +22 -20
- data/lib/ews/types/generic_folder.rb +348 -372
- data/lib/ews/types/item.rb +401 -397
- data/lib/ews/types/item_attachment.rb +87 -80
- data/lib/ews/types/item_field_uri_map.rb +201 -200
- data/lib/ews/types/mailbox_user.rb +146 -154
- data/lib/ews/types/meeting_cancellation.rb +11 -5
- data/lib/ews/types/meeting_message.rb +11 -5
- data/lib/ews/types/meeting_request.rb +11 -5
- data/lib/ews/types/meeting_response.rb +11 -5
- data/lib/ews/types/message.rb +11 -5
- data/lib/ews/types/modified_event.rb +43 -45
- data/lib/ews/types/moved_event.rb +47 -48
- data/lib/ews/types/new_mail_event.rb +22 -20
- data/lib/ews/types/out_of_office.rb +145 -144
- data/lib/ews/types/post_item.rb +11 -5
- data/lib/ews/types/search_folder.rb +10 -5
- data/lib/ews/types/status_event.rb +37 -36
- data/lib/ews/types/task.rb +39 -33
- data/lib/ews/types/tasks_folder.rb +31 -25
- data/lib/ews/types.rb +134 -139
- data/lib/viewpoint/logging/config.rb +19 -19
- data/lib/viewpoint/logging.rb +23 -17
- data/lib/viewpoint/string_utils.rb +31 -32
- data/lib/viewpoint.rb +18 -18
- metadata +50 -25
- data/Changelog.txt +0 -1004
data/lib/ews/item_accessors.rb
CHANGED
|
@@ -1,242 +1,244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
module Viewpoint
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
4
|
+
#
|
|
5
|
+
# Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
module Viewpoint
|
|
19
|
+
module EWS
|
|
20
|
+
# Item operations mixed into the EWS client.
|
|
21
|
+
module ItemAccessors
|
|
22
|
+
include Viewpoint::EWS
|
|
23
|
+
|
|
24
|
+
# This is a class method that fetches an existing Item from the
|
|
25
|
+
# Exchange Store.
|
|
26
|
+
# @param [String] item_id The id of the item. You can also pass a Hash in the
|
|
27
|
+
# form: {id: <fold_id>, change_key: <change_key>}
|
|
28
|
+
# @param [Hash] opts Misc options to control request
|
|
29
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
30
|
+
# @return [Item] Returns an Item or subclass of Item
|
|
31
|
+
# @todo Add support to fetch an item with a ChangeKey
|
|
32
|
+
def get_item(item_id, opts = {})
|
|
33
|
+
args = get_item_args(item_id, opts.clone)
|
|
34
|
+
obj = OpenStruct.new(opts: args)
|
|
35
|
+
yield obj if block_given?
|
|
36
|
+
resp = ews.get_item(args)
|
|
37
|
+
get_item_parser(resp)
|
|
38
|
+
end
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
# @param [Hash] opts Misc options to control request
|
|
41
|
+
# @option opts [Symbol] :folder_id
|
|
42
|
+
# @see GenericFolder#items
|
|
43
|
+
def find_items(opts = {})
|
|
44
|
+
args = find_items_args(opts.clone)
|
|
45
|
+
obj = OpenStruct.new(opts: args, restriction: {})
|
|
46
|
+
yield obj if block_given?
|
|
47
|
+
merge_restrictions! obj
|
|
48
|
+
resp = ews.find_item(args)
|
|
49
|
+
find_items_parser resp
|
|
50
|
+
end
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
# This is a class method that fetches an existing Item from the
|
|
53
|
+
# Exchange Store.
|
|
54
|
+
# @param [String] item_id The id of the item. You can also pass a Hash in the
|
|
55
|
+
# form: {id: <fold_id>, change_key: <change_key>}
|
|
56
|
+
# @param [Hash] opts Misc options to control request
|
|
57
|
+
# @option opts [Symbol] :shape :id_only/:default/:all_properties
|
|
58
|
+
# @return [Item] Returns an Item or subclass of Item
|
|
59
|
+
# @todo Add support to fetch an item with a ChangeKey
|
|
60
|
+
def get_items(item_ids, opts = {})
|
|
61
|
+
args = get_item_args(item_ids, opts.clone)
|
|
62
|
+
obj = OpenStruct.new(opts: args)
|
|
63
|
+
yield obj if block_given?
|
|
64
|
+
resp = ews.get_item(args)
|
|
65
|
+
get_items_parser(resp)
|
|
66
|
+
end
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
# Copy an array of items to the specified folder
|
|
69
|
+
# @param items [Array] an array of EWS Items that you want to copy
|
|
70
|
+
# @param folder [String,Symbol,GenericFolder] The folder to copy to. This must
|
|
71
|
+
# be a subclass of GenericFolder, a DistinguishedFolderId (must me a Symbol)
|
|
72
|
+
# or a FolderId (String)
|
|
73
|
+
# @return [Array<Hash>] returns a Hash for each item passed
|
|
74
|
+
# on success:
|
|
75
|
+
# {:success => true, :item_id => <new_item_id>}
|
|
76
|
+
# on failure:
|
|
77
|
+
# {:success => false, :error_message => <the message>}
|
|
78
|
+
def copy_items(items, folder)
|
|
79
|
+
folder = folder.id if folder.is_a?(Types::GenericFolder)
|
|
80
|
+
item_ids = items.collect { |i| { item_id: { id: i.id, change_key: i.change_key } } }
|
|
81
|
+
copy_opts = {
|
|
82
|
+
to_folder_id: { id: folder },
|
|
83
|
+
item_ids: item_ids
|
|
84
|
+
}
|
|
85
|
+
resp = ews.copy_item(copy_opts)
|
|
86
|
+
copy_move_items_parser(resp)
|
|
87
|
+
end
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
# Move an array of items to the specified folder
|
|
90
|
+
# @see #copy_items for parameter info
|
|
91
|
+
def move_items(items, folder)
|
|
92
|
+
folder = folder.id if folder.is_a?(Types::GenericFolder)
|
|
93
|
+
item_ids = items.collect { |i| { item_id: { id: i.id, change_key: i.change_key } } }
|
|
94
|
+
move_opts = {
|
|
95
|
+
to_folder_id: { id: folder },
|
|
96
|
+
item_ids: item_ids
|
|
97
|
+
}
|
|
98
|
+
resp = ews.move_item(move_opts)
|
|
99
|
+
copy_move_items_parser(resp, :move_item_response_message)
|
|
100
|
+
end
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
# Exports an entire item into base64 string
|
|
103
|
+
# @param item_ids [Array] array of item ids. Can also be a single id value
|
|
104
|
+
# return [Array] array of bulk items
|
|
105
|
+
def export_items(item_ids)
|
|
106
|
+
args = export_items_args(item_ids)
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
resp = ews.export_items(args)
|
|
109
|
+
export_items_parser(resp)
|
|
110
|
+
end
|
|
108
111
|
|
|
109
|
-
private
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def get_item_args(item_id, opts)
|
|
115
|
+
opts[:shape] ||= :default
|
|
116
|
+
default_args = {
|
|
117
|
+
item_shape: { base_shape: opts[:shape] }
|
|
118
|
+
}
|
|
119
|
+
default_args[:item_ids] = case item_id
|
|
120
|
+
when Hash
|
|
121
|
+
if item_id.keys.index(:id)
|
|
122
|
+
[{ item_id: item_id }]
|
|
123
|
+
else
|
|
124
|
+
[item_id]
|
|
125
|
+
end
|
|
126
|
+
when Array
|
|
127
|
+
item_id.map do |i|
|
|
128
|
+
case i
|
|
129
|
+
when Hash
|
|
130
|
+
i
|
|
131
|
+
else
|
|
132
|
+
{ item_id: { id: i } }
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
else
|
|
136
|
+
[{ item_id: { id: item_id } }]
|
|
137
|
+
end
|
|
138
|
+
default_args.merge opts
|
|
122
139
|
end
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
|
|
141
|
+
def get_item_parser(resp)
|
|
142
|
+
rm = resp.response_messages[0]
|
|
143
|
+
|
|
144
|
+
if rm && rm.status == 'Success'
|
|
145
|
+
i = rm.items.first
|
|
146
|
+
itype = i.keys.first
|
|
147
|
+
class_by_name(itype).new(ews, i[itype])
|
|
128
148
|
else
|
|
129
|
-
|
|
149
|
+
rm.respond_to?(:code) ? rm.code : 'Unknown'
|
|
150
|
+
rm.respond_to?(:message_text) ? rm.message_text : 'Unknown'
|
|
151
|
+
raise EwsItemNotFound, "Could not retrieve item. #{rm.code}: #{rm.message_text}"
|
|
130
152
|
end
|
|
131
153
|
end
|
|
132
|
-
else
|
|
133
|
-
[{:item_id => {:id => item_id}}]
|
|
134
|
-
end
|
|
135
|
-
default_args.merge opts
|
|
136
|
-
end
|
|
137
154
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if(rm && rm.status == 'Success')
|
|
142
|
-
i = rm.items.first
|
|
143
|
-
itype = i.keys.first
|
|
144
|
-
class_by_name(itype).new(ews, i[itype])
|
|
145
|
-
else
|
|
146
|
-
code = rm.respond_to?(:code) ? rm.code : "Unknown"
|
|
147
|
-
text = rm.respond_to?(:message_text) ? rm.message_text : "Unknown"
|
|
148
|
-
raise EwsItemNotFound, "Could not retrieve item. #{rm.code}: #{rm.message_text}"
|
|
149
|
-
end
|
|
150
|
-
end
|
|
155
|
+
def get_items_parser(resp)
|
|
156
|
+
items = []
|
|
151
157
|
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
resp.response_messages.each do |rm|
|
|
159
|
+
next unless rm && rm.status == 'Success'
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
items << class_by_name(type).new(ews, i[type])
|
|
161
|
+
rm.items.each do |i|
|
|
162
|
+
type = i.keys.first
|
|
163
|
+
items << class_by_name(type).new(ews, i[type])
|
|
164
|
+
end
|
|
160
165
|
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
166
|
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
items
|
|
168
|
+
end
|
|
166
169
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
def find_items_args(opts)
|
|
171
|
+
default_args = {
|
|
172
|
+
traversal: 'Shallow',
|
|
173
|
+
item_shape: { base_shape: 'Default' }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
default_args[:parent_folder_ids] = if opts[:folder_id].is_a?(Hash)
|
|
177
|
+
[opts.delete(:folder_id)]
|
|
178
|
+
else
|
|
179
|
+
[{ id: opts.delete(:folder_id) }]
|
|
180
|
+
end
|
|
181
|
+
default_args.merge(opts)
|
|
182
|
+
end
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
default_args[:parent_folder_ids] = [{:id => opts.delete(:folder_id)}]
|
|
177
|
-
end
|
|
178
|
-
default_args.merge(opts)
|
|
179
|
-
end
|
|
184
|
+
def find_items_parser(resp)
|
|
185
|
+
rm = resp.response_messages[0]
|
|
186
|
+
raise EwsError, "Could not retrieve folder. #{rm.code}: #{rm.message_text}" unless rm.success?
|
|
180
187
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
items << class_by_name(type).new(ews, i[type])
|
|
188
|
+
items = []
|
|
189
|
+
rm.root_folder.items.each do |i|
|
|
190
|
+
type = i.keys.first
|
|
191
|
+
items << class_by_name(type).new(ews, i[type])
|
|
192
|
+
end
|
|
193
|
+
items
|
|
188
194
|
end
|
|
189
|
-
items
|
|
190
|
-
else
|
|
191
|
-
raise EwsError, "Could not retrieve folder. #{rm.code}: #{rm.message_text}"
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
def copy_move_items_parser(resp, _resp_type = :copy_item_response_message)
|
|
197
|
+
resp.response_messages.collect { |r|
|
|
198
|
+
obj = {}
|
|
199
|
+
if r.success?
|
|
200
|
+
obj[:success] = true
|
|
201
|
+
item = r.items.first
|
|
202
|
+
key = item.keys.first
|
|
203
|
+
obj[:item_id] = item[key][:elems][0][:item_id][:attribs][:id]
|
|
204
|
+
else
|
|
205
|
+
obj[:success] = false
|
|
206
|
+
obj[:error_message] = "#{r.response_code}: #{r.message_text}"
|
|
207
|
+
end
|
|
208
|
+
obj
|
|
209
|
+
}
|
|
206
210
|
end
|
|
207
|
-
obj
|
|
208
|
-
}
|
|
209
|
-
end
|
|
210
211
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
212
|
+
def export_items_args(item_ids)
|
|
213
|
+
default_args = {}
|
|
214
|
+
default_args[:item_ids] = []
|
|
215
|
+
if item_ids.is_a?(Array)
|
|
216
|
+
item_ids.each do |id|
|
|
217
|
+
default_args[:item_ids] = default_args[:item_ids] + [{ item_id: { id: id } }]
|
|
218
|
+
end
|
|
219
|
+
else
|
|
220
|
+
default_args[:item_ids] = [{ item_id: { id: item_ids } }]
|
|
221
|
+
end
|
|
222
|
+
default_args
|
|
217
223
|
end
|
|
218
|
-
else
|
|
219
|
-
default_args[:item_ids] = [{:item_id => {:id => item_ids}}]
|
|
220
|
-
end
|
|
221
|
-
default_args
|
|
222
|
-
end
|
|
223
224
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
225
|
+
def export_items_parser(resp)
|
|
226
|
+
rm = resp.response_messages
|
|
227
|
+
return unless rm
|
|
228
|
+
|
|
229
|
+
items = []
|
|
230
|
+
rm.each do |i|
|
|
231
|
+
if i.success?
|
|
232
|
+
type = i.type
|
|
233
|
+
items << class_by_name(type).new(ews, i.message[:elems])
|
|
234
|
+
else
|
|
235
|
+
code = i.respond_to?(:code) ? i.code : 'Unknown'
|
|
236
|
+
text = i.respond_to?(:message_text) ? i.message_text : 'Unknown'
|
|
237
|
+
items << "Could not retrieve item. #{code}: #{text}"
|
|
238
|
+
end
|
|
236
239
|
end
|
|
240
|
+
items
|
|
237
241
|
end
|
|
238
|
-
items
|
|
239
242
|
end
|
|
240
243
|
end
|
|
241
|
-
|
|
242
|
-
end # Viewpoint::EWS::ItemAccessors
|
|
244
|
+
end
|
|
@@ -1,92 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
# This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
4
|
+
#
|
|
5
|
+
# Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
5
18
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
module Viewpoint
|
|
20
|
+
module EWS
|
|
21
|
+
# Mailbox operations mixed into the EWS client.
|
|
22
|
+
module MailboxAccessors
|
|
23
|
+
include Viewpoint::EWS
|
|
9
24
|
|
|
10
|
-
|
|
25
|
+
# Resolve contacts in the Exchange Data Store
|
|
26
|
+
# @param [String] ustring A string to resolve contacts to.
|
|
27
|
+
# @return [Array<MailboxUser>] It returns an Array of MailboxUsers.
|
|
28
|
+
def search_contacts(ustring)
|
|
29
|
+
resp = ews.resolve_names(name: ustring)
|
|
11
30
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
resp = ews.resolve_names(:name => ustring)
|
|
27
|
-
|
|
28
|
-
users = []
|
|
29
|
-
if(resp.status == 'Success')
|
|
30
|
-
mb = resp.response_message[:elems][:resolution_set][:elems][0][:resolution][:elems][0]
|
|
31
|
-
users << Types::MailboxUser.new(ews, mb[:mailbox][:elems])
|
|
32
|
-
elsif(resp.code == 'ErrorNameResolutionMultipleResults')
|
|
33
|
-
resp.response_message[:elems][:resolution_set][:elems].each do |u|
|
|
34
|
-
if u[:resolution][:elems][0][:mailbox]
|
|
35
|
-
users << Types::MailboxUser.new(ews, u[:resolution][:elems][0][:mailbox][:elems])
|
|
36
|
-
end
|
|
31
|
+
users = []
|
|
32
|
+
if resp.status == 'Success'
|
|
33
|
+
mb = resp.response_message[:elems][:resolution_set][:elems][0][:resolution][:elems][0]
|
|
34
|
+
users << Types::MailboxUser.new(ews, mb[:mailbox][:elems])
|
|
35
|
+
elsif resp.code == 'ErrorNameResolutionMultipleResults'
|
|
36
|
+
resp.response_message[:elems][:resolution_set][:elems].each do |u|
|
|
37
|
+
if u[:resolution][:elems][0][:mailbox]
|
|
38
|
+
users << Types::MailboxUser.new(ews, u[:resolution][:elems][0][:mailbox][:elems])
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
raise EwsError, "Find User produced an error: #{resp.code}: #{resp.message}"
|
|
43
|
+
end
|
|
44
|
+
users
|
|
37
45
|
end
|
|
38
|
-
else
|
|
39
|
-
raise EwsError, "Find User produced an error: #{resp.code}: #{resp.message}"
|
|
40
|
-
end
|
|
41
|
-
users
|
|
42
|
-
end
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
# GetUserAvailability request
|
|
48
|
+
# @see http://msdn.microsoft.com/en-us/library/aa563800.aspx
|
|
49
|
+
# @param [Array<String>] emails A list of emails you want to retrieve free-busy info for.
|
|
50
|
+
# @param [Hash] opts
|
|
51
|
+
# @option opts [DateTime] :start_time
|
|
52
|
+
# @option opts [DateTime] :end_time
|
|
53
|
+
# @option opts [Symbol] :requested_view :merged_only/:free_busy/
|
|
54
|
+
# :free_busy_merged/:detailed/:detailed_merged
|
|
55
|
+
# @option opts [Hash] :time_zone The TimeZone data
|
|
56
|
+
# Example: {:bias => 'UTC offset in minutes',
|
|
57
|
+
# :standard_time => {:bias => 480, :time => '02:00:00',
|
|
58
|
+
# :day_order => 5, :month => 10, :day_of_week => 'Sunday'},
|
|
59
|
+
# :daylight_time => {same options as :standard_time}}
|
|
60
|
+
def get_user_availability(emails, opts)
|
|
61
|
+
opts = opts.clone
|
|
62
|
+
args = get_user_availability_args(emails, opts)
|
|
63
|
+
resp = ews.get_user_availability(args.merge(opts))
|
|
64
|
+
get_user_availability_parser(resp)
|
|
65
|
+
end
|
|
63
66
|
|
|
67
|
+
private
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
def get_user_availability_args(emails, opts)
|
|
70
|
+
unless opts.key?(:start_time) && opts.key?(:end_time) && opts.key?(:requested_view)
|
|
71
|
+
raise EwsBadArgumentError, 'You must specify a start_time, end_time and requested_view.'
|
|
72
|
+
end
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
{
|
|
75
|
+
mailbox_data: emails.collect { |e| [{ email: { address: e } }] }.flatten,
|
|
76
|
+
free_busy_view_options: {
|
|
77
|
+
time_window: {
|
|
78
|
+
start_time: opts[:start_time],
|
|
79
|
+
end_time: opts[:end_time]
|
|
80
|
+
},
|
|
81
|
+
requested_view: { requested_free_busy_view: opts[:requested_view] }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
end
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
start_time: opts[:start_time],
|
|
77
|
-
end_time: opts[:end_time]
|
|
78
|
-
},
|
|
79
|
-
requested_view: { :requested_free_busy_view => opts[:requested_view] },
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
end
|
|
86
|
+
def get_user_availability_parser(resp)
|
|
87
|
+
unless resp.status == 'Success'
|
|
88
|
+
raise EwsError, "GetUserAvailability produced an error: #{resp.code}: #{resp.message}"
|
|
89
|
+
end
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
resp
|
|
87
|
-
else
|
|
88
|
-
raise EwsError, "GetUserAvailability produced an error: #{resp.code}: #{resp.message}"
|
|
91
|
+
resp
|
|
92
|
+
end
|
|
89
93
|
end
|
|
90
94
|
end
|
|
91
|
-
|
|
92
|
-
end # Viewpoint::EWS::MailboxAccessors
|
|
95
|
+
end
|