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