viewpoint 0.1.27 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/README.md +196 -0
  2. data/lib/ews/calendar_accessors.rb +34 -0
  3. data/lib/ews/connection.rb +117 -0
  4. data/lib/ews/connection_helper.rb +35 -0
  5. data/lib/ews/ews_client.rb +71 -0
  6. data/lib/ews/exceptions/exceptions.rb +59 -0
  7. data/lib/ews/folder_accessors.rb +199 -0
  8. data/lib/ews/item_accessors.rb +157 -0
  9. data/lib/ews/mailbox_accessors.rb +87 -0
  10. data/lib/ews/message_accessors.rb +86 -0
  11. data/lib/ews/push_subscription_accessors.rb +33 -0
  12. data/lib/ews/soap.rb +63 -0
  13. data/lib/ews/soap/builders/ews_builder.rb +1011 -0
  14. data/lib/ews/soap/ews_response.rb +83 -0
  15. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  16. data/lib/ews/soap/ews_soap_free_busy_response.rb +109 -0
  17. data/lib/ews/soap/ews_soap_response.rb +103 -0
  18. data/lib/ews/soap/exchange_availability.rb +61 -0
  19. data/lib/ews/soap/exchange_data_services.rb +742 -0
  20. data/lib/ews/soap/exchange_notification.rb +146 -0
  21. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  22. data/lib/ews/soap/exchange_web_service.rb +294 -0
  23. data/lib/{model/attendee.rb → ews/soap/parsers/ews_parser.rb} +20 -14
  24. data/lib/ews/soap/parsers/ews_sax_document.rb +66 -0
  25. data/lib/ews/soap/response_message.rb +78 -0
  26. data/lib/ews/soap/responses/create_attachment_response_message.rb +46 -0
  27. data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
  28. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  29. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  30. data/lib/ews/soap/responses/send_notification_response_message.rb +58 -0
  31. data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
  32. data/lib/ews/templates/forward_item.rb +24 -0
  33. data/lib/ews/templates/message.rb +66 -0
  34. data/lib/ews/templates/reply_to_item.rb +25 -0
  35. data/lib/ews/types.rb +146 -0
  36. data/lib/ews/types/attachment.rb +77 -0
  37. data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
  38. data/lib/ews/types/calendar_folder.rb +8 -0
  39. data/lib/ews/types/calendar_item.rb +37 -0
  40. data/lib/ews/types/contact.rb +7 -0
  41. data/lib/ews/types/contacts_folder.rb +8 -0
  42. data/lib/ews/types/copied_event.rb +51 -0
  43. data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
  44. data/lib/{model/meeting_response.rb → ews/types/deleted_event.rb} +6 -6
  45. data/lib/ews/types/distribution_list.rb +7 -0
  46. data/lib/ews/types/event.rb +62 -0
  47. data/lib/ews/types/file_attachment.rb +65 -0
  48. data/lib/ews/types/folder.rb +60 -0
  49. data/lib/{model/distribution_list.rb → ews/types/free_busy_changed_event.rb} +6 -6
  50. data/lib/ews/types/generic_folder.rb +352 -0
  51. data/lib/ews/types/item.rb +381 -0
  52. data/lib/ews/types/item_attachment.rb +46 -0
  53. data/lib/{model → ews/types}/item_field_uri_map.rb +2 -2
  54. data/lib/ews/types/mailbox_user.rb +156 -0
  55. data/lib/ews/types/meeting_cancellation.rb +7 -0
  56. data/lib/ews/types/meeting_message.rb +7 -0
  57. data/lib/ews/types/meeting_request.rb +7 -0
  58. data/lib/ews/types/meeting_response.rb +7 -0
  59. data/lib/ews/types/message.rb +7 -0
  60. data/lib/ews/types/modified_event.rb +48 -0
  61. data/lib/{model/item_attachment.rb → ews/types/moved_event.rb} +33 -15
  62. data/lib/ews/types/new_mail_event.rb +24 -0
  63. data/lib/ews/types/out_of_office.rb +147 -0
  64. data/lib/ews/types/search_folder.rb +8 -0
  65. data/lib/ews/types/status_event.rb +39 -0
  66. data/lib/ews/types/task.rb +7 -0
  67. data/lib/ews/types/tasks_folder.rb +8 -0
  68. data/lib/viewpoint.rb +82 -106
  69. metadata +99 -67
  70. data/README +0 -114
  71. data/lib/exceptions/exceptions.rb +0 -46
  72. data/lib/model/calendar_folder.rb +0 -67
  73. data/lib/model/calendar_item.rb +0 -267
  74. data/lib/model/contact.rb +0 -238
  75. data/lib/model/contacts_folder.rb +0 -46
  76. data/lib/model/event.rb +0 -116
  77. data/lib/model/file_attachment.rb +0 -53
  78. data/lib/model/folder.rb +0 -47
  79. data/lib/model/generic_folder.rb +0 -471
  80. data/lib/model/item.rb +0 -313
  81. data/lib/model/mailbox_user.rb +0 -146
  82. data/lib/model/meeting_request.rb +0 -39
  83. data/lib/model/message.rb +0 -142
  84. data/lib/model/model.rb +0 -269
  85. data/lib/model/search_folder.rb +0 -48
  86. data/lib/model/task.rb +0 -121
  87. data/lib/model/tasks_folder.rb +0 -44
  88. data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
  89. data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
  90. data/lib/soap/handsoap/ews_service.rb +0 -813
  91. data/lib/soap/handsoap/parser.rb +0 -104
  92. data/lib/soap/handsoap/parsers/ews_parser.rb +0 -246
  93. data/lib/soap/soap_provider.rb +0 -64
@@ -0,0 +1,59 @@
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
19
+
20
+ # Generic Ews Error
21
+ class EwsError < StandardError; end
22
+
23
+ # Raise when authentication/authorization issues occur.
24
+ class EwsLoginError < EwsError; end
25
+
26
+ class EwsSubscriptionError < EwsError; end
27
+
28
+ # Raised when a user tries to query a folder subscription after the
29
+ # subscription has timed out.
30
+ class EwsSubscriptionTimeout < EwsSubscriptionError; end
31
+
32
+ # Represents a function in EWS that is not yet implemented in Viewpoint
33
+ class EwsNotImplemented < EwsError; end
34
+
35
+ # Raised when an method is called in the wrong way
36
+ class EwsBadArgumentError < EwsError; end
37
+
38
+ # Raised when an item that is asked for is not found
39
+ class EwsItemNotFound < EwsError; end
40
+
41
+ # Raised when a folder that is asked for is not found
42
+ class EwsFolderNotFound < EwsError; end
43
+
44
+ # Raise an Exchange Server version error. This is in case some functionality
45
+ # does not exist in a particular Server version but is called.
46
+ class EwsServerVersionError < EwsError; end
47
+
48
+ # Raised when #auto_deepen == false and a method is called for attributes
49
+ # that have not yet been fetched.
50
+ class EwsMinimalObjectError < EwsError; end
51
+
52
+ # Failed to save an object back to the EWS store.
53
+ class SaveFailed < EwsError; end
54
+
55
+ class EwsCreateItemError < EwsError; end
56
+
57
+ class EwsSendItemError < EwsError; end
58
+
59
+ end # Viewpoint::EWS
@@ -0,0 +1,199 @@
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::FolderAccessors
19
+ include Viewpoint::EWS
20
+
21
+ FOLDER_TYPE_MAP = {
22
+ :mail => 'IPF.Note',
23
+ :calendar => 'IPF.Appointment',
24
+ :task => 'IPF.Task',
25
+ }
26
+
27
+ # Find subfolders of the passed root folder. If no parameters are passed this
28
+ # method will search from the Root folder.
29
+ # @param [Hash] opts Misc options to control request
30
+ # @option opts [String,Symbol] :root Either a FolderId(String) or a
31
+ # DistinguishedFolderId(Symbol) . This is where to start the search from.
32
+ # Usually :root,:msgfolderroot, or :publicfoldersroot
33
+ # @option opts [Symbol] :traversal :shallow/:deep/:soft_deleted
34
+ # @option opts [Symbol] :shape :id_only/:default/:all_properties
35
+ # @option opts [optional, String] :folder_type an optional folder type to
36
+ # limit the search to like 'IPF.Task'
37
+ # @return [Array] Returns an Array of Folder or subclasses of Folder
38
+ # @raise [EwsError] raised when the backend SOAP method returns an error.
39
+ def folders(opts={})
40
+ opts = opts.clone
41
+ args = find_folders_args(opts)
42
+ obj = OpenStruct.new(opts: args, restriction: {})
43
+ yield obj if block_given?
44
+ merge_restrictions! obj
45
+ resp = ews.find_folder( args )
46
+ find_folders_parser(resp)
47
+ end
48
+ alias :find_folders :folders
49
+
50
+ # Get a specific folder by id or symbol
51
+ # @param [String,Symbol,Hash] folder_id Either a FolderId(String) or a
52
+ # DistinguishedFolderId(Symbol). You can also pass a Hash in the form:
53
+ # {id: <fold_id>, change_key: <change_key>}
54
+ # @param [Hash] opts Misc options to control request
55
+ # @option opts [Symbol] :shape :id_only/:default/:all_properties
56
+ # @option opts [String,nil] :act_as User to act on behalf as. This user must
57
+ # have been given delegate access to the folder or this operation will fail.
58
+ # @raise [EwsError] raised when the backend SOAP method returns an error.
59
+ def get_folder(folder_id, opts = {})
60
+ opts = opts.clone
61
+ args = get_folder_args(folder_id, opts)
62
+ resp = ews.get_folder(args)
63
+ get_folder_parser(resp)
64
+ end
65
+
66
+ # Get a specific folder by its name
67
+ # @param [String] name The folder name
68
+ # @param [Hash] opts Misc options to control request
69
+ # @option opts [String,Symbol] :parent Either a FolderId(String) or a
70
+ # DistinguishedFolderId(Symbol) . This is the parent folder.
71
+ # @option opts [Symbol] :shape :id_only/:default/:all_properties
72
+ # @option opts [String,nil] :act_as User to act on behalf as. This user must
73
+ # have been given delegate access to the folder or this operation will fail.
74
+ # @raise [EwsError] raised when the backend SOAP method returns an error.
75
+ def get_folder_by_name(name, opts={})
76
+ opts = opts.clone
77
+ opts[:root] = opts.delete(:parent)
78
+ folders(opts) do |obj|
79
+ obj.restriction = {
80
+ :is_equal_to =>
81
+ [
82
+ {:field_uRI => {:field_uRI=>'folder:DisplayName'}},
83
+ {:field_uRI_or_constant => {:constant => {:value=>name}}}
84
+ ]
85
+ }
86
+ end.first
87
+ end
88
+
89
+ # @param [String] name The name of the new folder
90
+ # @param [Hash] opts
91
+ # @option opts [String,Symbol] :parent Either a FolderId(String) or a
92
+ # DistinguishedFolderId(Symbol) . This is the parent folder.
93
+ # @option opts [Symbol] :type the type of folder to create. must be one of
94
+ # :folder, :calendar, :contacts, :search, or :tasks
95
+ # @see http://msdn.microsoft.com/en-us/library/aa580808.aspx
96
+ def make_folder(name, opts={})
97
+ parent = opts[:parent] || :msgfolderroot
98
+ resp = ews.create_folder :parent_folder_id => {:id => parent},
99
+ :folders => [folder_type(opts[:type]) => {:display_name => name}]
100
+ create_folder_parser(resp).first
101
+ end
102
+ alias :mkfolder :make_folder
103
+
104
+
105
+ private
106
+
107
+ # Build up the arguements for #find_folders
108
+ def find_folders_args(opts)
109
+ opts[:root] = opts[:root] || :msgfolderroot
110
+ opts[:traversal] = opts[:traversal] || :shallow
111
+ opts[:shape] = opts[:shape] || :default
112
+ if( opts[:folder_type] )
113
+ restr = { :is_equal_to =>
114
+ [
115
+ {:field_uRI => {:field_uRI=>'folder:FolderClass'}},
116
+ {:field_uRI_or_constant=>{:constant =>
117
+ {:value => map_folder_type(opts[:folder_type])}}},
118
+ ]
119
+ }
120
+ end
121
+ args = {
122
+ :parent_folder_ids => [{:id => opts[:root]}],
123
+ :traversal => opts[:traversal],
124
+ :folder_shape => {:base_shape => opts[:shape]}
125
+ }
126
+ args[:restriction] = restr if restr
127
+ args
128
+ end
129
+
130
+ # @param [Viewpoint::EWS::SOAP::EwsSoapResponse] resp
131
+ def find_folders_parser(resp)
132
+ if resp.status == 'Success'
133
+ folders = resp.response_message[:elems][:root_folder][:elems][0][:folders][:elems]
134
+ return [] if folders.nil?
135
+ folders.collect do |f|
136
+ ftype = f.keys.first
137
+ class_by_name(ftype).new(ews, f[ftype])
138
+ end
139
+ else
140
+ raise EwsFolderNotFound, "Could not retrieve folders. #{resp.code}: #{resp.message}"
141
+ end
142
+ end
143
+
144
+ def create_folder_parser(resp)
145
+ if resp.status == 'Success'
146
+ folders = resp.response_message[:elems][:folders][:elems]
147
+ folders.collect do |f|
148
+ ftype = f.keys.first
149
+ class_by_name(ftype).new(ews, f[ftype])
150
+ end
151
+ else
152
+ raise EwsError, "Could not create folder. #{resp.code}: #{resp.message}"
153
+ end
154
+ end
155
+
156
+ # Build up the arguements for #get_folder
157
+ def get_folder_args(folder_id, opts)
158
+ opts[:shape] ||= :default
159
+ default_args = {
160
+ :folder_shape => {:base_shape => opts[:shape]}
161
+ }
162
+ if folder_id.is_a?(Hash)
163
+ default_args[:folder_ids] = [folder_id]
164
+ else
165
+ default_args[:folder_ids] = [{:id => folder_id}]
166
+ end
167
+ default_args.merge opts
168
+ end
169
+
170
+ # @param [Viewpoint::EWS::SOAP::EwsSoapResponse] resp
171
+ def get_folder_parser(resp)
172
+ if(resp.status == 'Success')
173
+ f = resp.response_message[:elems][:folders][:elems][0]
174
+ ftype = f.keys.first
175
+ class_by_name(ftype).new(ews, f[ftype])
176
+ else
177
+ raise EwsFolderNotFound, "Could not retrieve folder. #{resp.code}: #{resp.message}"
178
+ end
179
+ end
180
+
181
+ # Map a passed parameter to a know folder type mapping. If no mapping
182
+ # exits simply allow the passed in type to be passed to the SOAP call.
183
+ # @param [Symbol] type a symbol in FOLDER_TYPE_MAP
184
+ def map_folder_type(type)
185
+ FOLDER_TYPE_MAP[type] || type
186
+ end
187
+
188
+ def folder_type(type)
189
+ case type
190
+ when nil, :folder
191
+ :folder
192
+ when :calendar, :contacts, :search, :tasks
193
+ "#{type}_folder".to_sym
194
+ else
195
+ raise EwsBadArgumentError, "Not a proper folder type: :#{type}"
196
+ end
197
+ end
198
+
199
+ end
@@ -0,0 +1,157 @@
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
36
+
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
48
+
49
+ # Copy an array of items to the specified folder
50
+ # @param items [Array] an array of EWS Items that you want to copy
51
+ # @param folder [String,Symbol,GenericFolder] The folder to copy to. This must
52
+ # be a subclass of GenericFolder, a DistinguishedFolderId (must me a Symbol)
53
+ # or a FolderId (String)
54
+ # @return [Array<Hash>] returns a Hash for each item passed
55
+ # on success:
56
+ # {:success => true, :item_id => <new_item_id>}
57
+ # on failure:
58
+ # {:success => false, :error_message => <the message>}
59
+ def copy_items(items, folder)
60
+ folder = folder.id if folder.kind_of?(Types::GenericFolder)
61
+ item_ids = items.collect{|i| {item_id: {id: i.id, change_key: i.change_key}}}
62
+ copy_opts = {
63
+ :to_folder_id => {:id => folder},
64
+ :item_ids => item_ids
65
+ }
66
+ resp = ews.copy_item(copy_opts)
67
+ copy_move_items_parser(resp)
68
+ end
69
+
70
+ # Move an array of items to the specified folder
71
+ # @see #copy_items for parameter info
72
+ def move_items(items, folder)
73
+ folder = folder.id if folder.kind_of?(Types::GenericFolder)
74
+ item_ids = items.collect{|i| {item_id: {id: i.id, change_key: i.change_key}}}
75
+ move_opts = {
76
+ :to_folder_id => {:id => folder},
77
+ :item_ids => item_ids
78
+ }
79
+ resp = ews.move_item(move_opts)
80
+ copy_move_items_parser(resp, :move_item_response_message)
81
+ end
82
+
83
+
84
+ private
85
+
86
+ def get_item_args(item_id, opts)
87
+ opts[:shape] ||= :default
88
+ default_args = {
89
+ :item_shape => {:base_shape => opts[:shape]}
90
+ }
91
+ if item_id.is_a?(Hash)
92
+ default_args[:item_ids] = [{:item_id => item_id}]
93
+ else
94
+ default_args[:item_ids] = [{:item_id => {:id => item_id}}]
95
+ end
96
+ default_args.merge opts
97
+ end
98
+
99
+ def get_item_parser(resp)
100
+ rm = resp.response_messages[0]
101
+
102
+ if(rm && rm.status == 'Success')
103
+ i = rm.items.first
104
+ itype = i.keys.first
105
+ class_by_name(itype).new(ews, i[itype])
106
+ else
107
+ code = rm.respond_to?(:code) ? rm.code : "Unknown"
108
+ text = rm.respond_to?(:message_text) ? rm.message_text : "Unknown"
109
+ raise EwsItemNotFound, "Could not retrieve item. #{rm.code}: #{rm.message_text}"
110
+ end
111
+ end
112
+
113
+ def find_items_args(opts)
114
+ default_args = {
115
+ :traversal => 'Shallow',
116
+ :item_shape => {:base_shape => 'Default'}
117
+ }
118
+
119
+ if opts[:folder_id].is_a?(Hash)
120
+ default_args[:parent_folder_ids] = [opts.delete(:folder_id)]
121
+ else
122
+ default_args[:parent_folder_ids] = [{:id => opts.delete(:folder_id)}]
123
+ end
124
+ default_args.merge(opts)
125
+ end
126
+
127
+ def find_items_parser(resp)
128
+ rm = resp.response_messages[0]
129
+ if rm.success?
130
+ items = []
131
+ rm.root_folder.items.each do |i|
132
+ type = i.keys.first
133
+ items << class_by_name(type).new(ews, i[type])
134
+ end
135
+ items
136
+ else
137
+ raise EwsError, "Could not retrieve folder. #{rm.code}: #{rm.message_text}"
138
+ end
139
+ end
140
+
141
+ def copy_move_items_parser(resp, resp_type = :copy_item_response_message)
142
+ resp.response_messages.collect {|r|
143
+ obj = {}
144
+ if r.success?
145
+ obj[:success] = true
146
+ item = r.items.first
147
+ key = item.keys.first
148
+ obj[:item_id] = item[key][:elems][0][:item_id][:attribs][:id]
149
+ else
150
+ obj[:success] = false
151
+ obj[:error_message] = "#{r.response_code}: #{r.message_text}"
152
+ end
153
+ obj
154
+ }
155
+ end
156
+
157
+ end # Viewpoint::EWS::ItemAccessors
@@ -0,0 +1,87 @@
1
+ =begin
2
+ This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
+
4
+ Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ =end
18
+
19
+ module Viewpoint::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
37
+ end
38
+ else
39
+ raise EwsError, "Find User produced an error: #{resp.code}: #{resp.message}"
40
+ end
41
+ users
42
+ end
43
+
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
+ def get_user_availability(emails, opts)
53
+ opts = opts.clone
54
+ args = get_user_availability_args(emails, opts)
55
+ resp = ews.get_user_availability(args)
56
+ get_user_availability_parser(resp)
57
+ end
58
+
59
+
60
+ private
61
+
62
+ def get_user_availability_args(emails, opts)
63
+ unless opts.has_key?(:start_time) && opts.has_key?(:end_time) && opts.has_key?(:requested_view)
64
+ raise EwsBadArgumentError, "You must specify a start_time, end_time and requested_view."
65
+ end
66
+
67
+ default_args = {
68
+ mailbox_data: (emails.collect{|e| [email: {address: e}]}.flatten),
69
+ free_busy_view_options: {
70
+ time_window: {
71
+ start_time: opts[:start_time],
72
+ end_time: opts[:end_time]
73
+ },
74
+ requested_view: { :requested_free_busy_view => opts[:requested_view] },
75
+ }
76
+ }
77
+ end
78
+
79
+ def get_user_availability_parser(resp)
80
+ if(resp.status == 'Success')
81
+ resp
82
+ else
83
+ raise EwsError, "GetUserAvailability produced an error: #{resp.code}: #{resp.message}"
84
+ end
85
+ end
86
+
87
+ end # Viewpoint::EWS::MailboxAccessors