viewpoint 0.1.4 → 0.1.5fix
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.
- data/Changelog.txt +814 -0
- data/Rakefile +2 -1
- data/TODO +14 -7
- data/VERSION +1 -1
- data/lib/model/file_attachment.rb +1 -0
- data/lib/model/generic_folder.rb +11 -4
- data/lib/model/item.rb +13 -5
- data/lib/model/message.rb +35 -0
- data/lib/model/model.rb +31 -1
- data/lib/soap/handsoap/ews_service.rb +53 -38
- data/lib/viewpoint.rb +11 -1
- metadata +29 -9
data/Rakefile
CHANGED
@@ -33,7 +33,8 @@ GEMSPEC = Gem::Specification.new do |gem|
|
|
33
33
|
gem.add_runtime_dependency 'nokogiri'
|
34
34
|
gem.add_runtime_dependency 'httpclient'
|
35
35
|
gem.add_runtime_dependency 'rubyntlm'
|
36
|
-
gem.add_runtime_dependency 'icalendar'
|
36
|
+
gem.add_runtime_dependency 'icalendar', '>= 1.1.5'
|
37
|
+
gem.add_runtime_dependency 'mail', '>= 2.2.5'
|
37
38
|
end
|
38
39
|
|
39
40
|
Rake::GemPackageTask.new(GEMSPEC) do |pkg|
|
data/TODO
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
h2. TODOS
|
1
2
|
|
2
|
-
|
3
|
-
… if object.is_shallow? && all_methods.index(method)
|
4
|
-
deepen!
|
5
|
-
else
|
6
|
-
raise the NoMethod error
|
3
|
+
* Automate "deepening" of Model objects by over-riding method_missing
|
7
4
|
|
8
|
-
|
5
|
+
<pre>
|
6
|
+
if object.is_shallow? && all_methods.index(method)
|
7
|
+
deepen!
|
8
|
+
else
|
9
|
+
raise the NoMethod error
|
10
|
+
</pre>
|
9
11
|
|
10
|
-
-
|
12
|
+
* Clean-up exceptions. There is exception raising in the Model that will never ocurr because it is already being checked for in the Parser
|
13
|
+
|
14
|
+
* Refactor #find_folders methods. There is a lot of duplicate code right now and it could be simplified quite a bit.
|
15
|
+
|
16
|
+
* Test TODO
|
17
|
+
** Test for undefined methods and make sure the method_missing method isn't causing problems
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5fix
|
@@ -24,6 +24,7 @@ module Viewpoint
|
|
24
24
|
# to a file withthe #save_to_file method.
|
25
25
|
class FileAttachment < Attachment
|
26
26
|
|
27
|
+
attr_reader :file_name, :content
|
27
28
|
# @param [String] attachment_id The unique ID for the attachment.
|
28
29
|
def initialize(attachment_id)
|
29
30
|
@id = attachment_id
|
data/lib/model/generic_folder.rb
CHANGED
@@ -214,20 +214,27 @@ module Viewpoint
|
|
214
214
|
|
215
215
|
def todays_items
|
216
216
|
#opts = {:query_string => ["Received:today"]}
|
217
|
-
|
217
|
+
#This is a bit convoluted for pre-1.9.x ruby versions that don't support to_datetime
|
218
|
+
items_since(DateTime.parse(Date.today.to_s))
|
218
219
|
end
|
219
220
|
|
220
221
|
def items_since(date_time)
|
221
222
|
restr = {:restriction =>
|
222
223
|
{:is_greater_than_or_equal_to =>
|
223
|
-
{:field_uRI => {:field_uRI=>'item:DateTimeReceived'},
|
224
|
+
[{:field_uRI => {:field_uRI=>'item:DateTimeReceived'}},
|
225
|
+
{:field_uRI_or_constant =>{:constant => {:value=>date_time}}}]
|
226
|
+
}}
|
224
227
|
find_items(restr)
|
225
228
|
end
|
226
229
|
|
227
230
|
def items_between(start_date, end_date)
|
228
231
|
restr = {:restriction => {:and => [
|
229
|
-
{:is_greater_than_or_equal_to =>
|
230
|
-
|
232
|
+
{:is_greater_than_or_equal_to =>
|
233
|
+
[{:field_uRI => {:field_uRI=>'item:DateTimeReceived'}},
|
234
|
+
{:field_uRI_or_constant=>{:constant => {:value =>start_date}}}]},
|
235
|
+
{:is_less_than_or_equal_to =>
|
236
|
+
[{:field_uRI => {:field_uRI=>'item:DateTimeReceived'}},
|
237
|
+
{:field_uRI_or_constant=>{:constant => {:value =>end_date}}}]}
|
231
238
|
]}}
|
232
239
|
find_items(restr)
|
233
240
|
end
|
data/lib/model/item.rb
CHANGED
@@ -55,7 +55,7 @@ module Viewpoint
|
|
55
55
|
{:id => resp.items.first[:attachment_id][:root_item_id], :change_key => resp.items.first[:attachment_id][:root_item_change_key]}
|
56
56
|
end
|
57
57
|
|
58
|
-
attr_reader :item_id, :change_key
|
58
|
+
attr_reader :item_id, :change_key
|
59
59
|
alias :id :item_id
|
60
60
|
|
61
61
|
# Initialize an Exchange Web Services item
|
@@ -118,20 +118,26 @@ module Viewpoint
|
|
118
118
|
# Return the attachments for this Item
|
119
119
|
# @return [Array,Attachment] An array of Attachments for this Item
|
120
120
|
def attachments
|
121
|
+
# TODO: should an exception be raised if someone calls this method without first
|
122
|
+
# checking has_attachments?
|
121
123
|
return [] unless has_attachments?
|
124
|
+
|
125
|
+
# If we've already called this don't waste the time to process attachments again.
|
126
|
+
return @attachments if defined?(@attachments)
|
127
|
+
|
122
128
|
deepen!
|
123
|
-
|
129
|
+
@attachments = []
|
124
130
|
@ews_item[:attachments].each_pair do |k,v|
|
125
131
|
# k should be file_attachment or item_attachment
|
126
132
|
if(v.is_a?(Hash))
|
127
|
-
|
133
|
+
@attachments << (eval "#{k.to_s.camel_case}.new(v[:attachment_id][:id])")
|
128
134
|
else
|
129
135
|
v.each do |att|
|
130
|
-
|
136
|
+
@attachments << (eval "#{k.to_s.camel_case}.new(att[:attachment_id][:id])")
|
131
137
|
end
|
132
138
|
end
|
133
139
|
end
|
134
|
-
|
140
|
+
@attachments
|
135
141
|
end
|
136
142
|
|
137
143
|
# Delete this item
|
@@ -181,6 +187,7 @@ module Viewpoint
|
|
181
187
|
define_str_var :subject, :sensitivity, :body, :item_class, :importance, :in_reply_to, :unique_body
|
182
188
|
define_str_var :display_cc, :display_to, :culture, :last_modified_name, :mime_content
|
183
189
|
define_str_var :web_client_read_form_query_string, :web_client_edit_form_query_string
|
190
|
+
define_attr_str_var :body, :body_type
|
184
191
|
define_int_var :size, :reminder_minutes_before_start
|
185
192
|
define_bool_var :has_attachments, :is_submitted, :is_draft, :is_from_me, :is_resend, :is_unmodified, :reminder_is_set, :is_associated
|
186
193
|
define_datetime_var :date_time_sent, :date_time_created, :date_time_received, :reminder_due_by, :last_modified_time
|
@@ -192,6 +199,7 @@ module Viewpoint
|
|
192
199
|
send(m, *args, &block)
|
193
200
|
else
|
194
201
|
warn "!!! No such method: #{m}"
|
202
|
+
nil
|
195
203
|
end
|
196
204
|
end
|
197
205
|
|
data/lib/model/message.rb
CHANGED
@@ -73,6 +73,7 @@ module Viewpoint
|
|
73
73
|
def headers
|
74
74
|
deepen! if @shallow
|
75
75
|
return @headers if defined?(@headers) && !@headers.empty?
|
76
|
+
return nil unless @ews_item.has_key?(:internet_message_headers)
|
76
77
|
@headers = {}
|
77
78
|
# @todo When ruby 1.9 becomes more pervasive the Enumerator#each_with_object
|
78
79
|
#@headers ||= @ews_item[:internet_message_headers][:internet_message_header].each_with_object({}) do |h,obj|
|
@@ -82,6 +83,40 @@ module Viewpoint
|
|
82
83
|
@headers
|
83
84
|
end
|
84
85
|
|
86
|
+
|
87
|
+
# This creates an object of type Mail (mail gem) and allows us to
|
88
|
+
# manipulate and output Message Items in standards compliant ways.
|
89
|
+
# @see http://www.ietf.org/rfc/rfc2822.txt
|
90
|
+
def to_mail
|
91
|
+
mail = Mail.new
|
92
|
+
unless(headers.nil?)
|
93
|
+
mail.received headers['Received']
|
94
|
+
mail.content_type headers['Content-Type']
|
95
|
+
mail.content_transfer_encoding headers['Content-Transfer-Encoding']
|
96
|
+
end
|
97
|
+
mail.message_id internet_message_id unless internet_message_id.nil?
|
98
|
+
mail.in_reply_to in_reply_to unless in_reply_to.nil?
|
99
|
+
mail.references references unless references.nil?
|
100
|
+
mail.subject subject unless subject.nil?
|
101
|
+
mail.return_path = sender.email_address unless sender.nil?
|
102
|
+
mail.to to_recipients.map {|r| r.email_address} unless to_recipients.nil?
|
103
|
+
mail.cc cc_recipients.map {|r| r.email_address} unless cc_recipients.nil?
|
104
|
+
mail.from from.email_address unless from.nil?
|
105
|
+
# Because the mail gem does not pass an object to the block there are some issues with using self
|
106
|
+
msg = self
|
107
|
+
if(body_type == "HTML")
|
108
|
+
mail.html_part do
|
109
|
+
body msg.body
|
110
|
+
end
|
111
|
+
else
|
112
|
+
mail.text_part do
|
113
|
+
body msg.body
|
114
|
+
end
|
115
|
+
end
|
116
|
+
mail
|
117
|
+
end
|
118
|
+
|
119
|
+
|
85
120
|
private
|
86
121
|
|
87
122
|
def init_methods
|
data/lib/model/model.rb
CHANGED
@@ -44,12 +44,19 @@ module Viewpoint
|
|
44
44
|
|
45
45
|
protected
|
46
46
|
|
47
|
+
# Define a method that returns a string. The vars are the keys in the
|
48
|
+
# hash that contain a :text key. In the original SOAP packet this would
|
49
|
+
# look something like this:
|
50
|
+
# @example
|
51
|
+
# <method_name>
|
52
|
+
# This is the text
|
53
|
+
# </method_name>
|
47
54
|
def define_str_var(*vars)
|
48
55
|
vars.each do |var|
|
49
56
|
if(@ews_item[var])
|
50
57
|
@ews_methods << var
|
51
58
|
self.instance_eval <<-EOF
|
52
|
-
def #{var
|
59
|
+
def #{var}
|
53
60
|
@ews_item[:#{var}][:text]
|
54
61
|
end
|
55
62
|
EOF
|
@@ -58,7 +65,30 @@ module Viewpoint
|
|
58
65
|
end
|
59
66
|
end
|
60
67
|
end
|
68
|
+
|
69
|
+
# This is similar to the #define_str_var method except of the text value
|
70
|
+
# is from an XML attribute in the original SOAP so the text won't be pointed
|
71
|
+
# to by :text. In the orignal SOAP it may have looked like this:
|
72
|
+
# @example
|
73
|
+
# <node my_method='this is the text'/>
|
74
|
+
# @param
|
75
|
+
def define_attr_str_var(parent, *vars)
|
76
|
+
return unless @ews_item[parent]
|
77
|
+
vars.each do |var|
|
78
|
+
if(@ews_item[parent][var])
|
79
|
+
@ews_methods << var
|
80
|
+
self.instance_eval <<-EOF
|
81
|
+
def #{var}
|
82
|
+
@ews_item[:#{parent}][:#{var}]
|
83
|
+
end
|
84
|
+
EOF
|
85
|
+
else
|
86
|
+
@ews_methods_undef << var
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
61
90
|
|
91
|
+
|
62
92
|
def define_int_var(*vars)
|
63
93
|
vars.each do |var|
|
64
94
|
if(@ews_item[var])
|
@@ -32,6 +32,7 @@ module Viewpoint
|
|
32
32
|
SOAP_ACTION_PREFIX = "http://schemas.microsoft.com/exchange/services/2006/messages"
|
33
33
|
|
34
34
|
@@raw_soap = false
|
35
|
+
@@http_options = nil
|
35
36
|
|
36
37
|
def initialize()
|
37
38
|
if $DEBUG
|
@@ -50,6 +51,15 @@ module Viewpoint
|
|
50
51
|
@@raw_soap = true
|
51
52
|
end
|
52
53
|
|
54
|
+
# Set various HTTP options like ssl_ca_trust, etc
|
55
|
+
def self.set_http_options(option_hash)
|
56
|
+
if @@http_options.nil?
|
57
|
+
@@http_options = option_hash
|
58
|
+
else
|
59
|
+
@@http_options.merge!(option_hash)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
# ********* Begin Hooks *********
|
54
64
|
|
55
65
|
|
@@ -94,7 +104,7 @@ module Viewpoint
|
|
94
104
|
# it's numerical ID. @see http://msdn.microsoft.com/en-us/library/aa565998.aspx
|
95
105
|
def resolve_names(name, full_contact_data = true, opts = {})
|
96
106
|
action = "#{SOAP_ACTION_PREFIX}/ResolveNames"
|
97
|
-
resp = invoke("#{NS_EWS_MESSAGES}:ResolveNames",
|
107
|
+
resp = invoke("#{NS_EWS_MESSAGES}:ResolveNames", action) do |root|
|
98
108
|
build!(root) do
|
99
109
|
root.set_attr('ReturnFullContactData',full_contact_data)
|
100
110
|
root.add("#{NS_EWS_MESSAGES}:UnresolvedEntry",name)
|
@@ -112,7 +122,7 @@ module Viewpoint
|
|
112
122
|
# taking an e-mail address as an argument
|
113
123
|
def expand_dl(dist_email)
|
114
124
|
action = "#{SOAP_ACTION_PREFIX}/ExpandDL"
|
115
|
-
resp = invoke("#{NS_EWS_MESSAGES}:ExpandDL",
|
125
|
+
resp = invoke("#{NS_EWS_MESSAGES}:ExpandDL", action) do |root|
|
116
126
|
build!(root) do
|
117
127
|
mailbox!(root, {:email_address => {:text => dist_email}})
|
118
128
|
end
|
@@ -134,7 +144,7 @@ module Viewpoint
|
|
134
144
|
# @param [Hash] opts optional parameters to this method
|
135
145
|
def find_folder(parent_folder_ids = [:root], traversal = 'Shallow', folder_shape = {:base_shape => 'Default'}, opts = {})
|
136
146
|
action = "#{SOAP_ACTION_PREFIX}/FindFolder"
|
137
|
-
resp = invoke("#{NS_EWS_MESSAGES}:FindFolder",
|
147
|
+
resp = invoke("#{NS_EWS_MESSAGES}:FindFolder", action) do |root|
|
138
148
|
build!(root) do
|
139
149
|
restriction = opts.delete(:restriction)
|
140
150
|
root.set_attr('Traversal', traversal)
|
@@ -164,7 +174,7 @@ module Viewpoint
|
|
164
174
|
# {:calendar_view => {:max_entries_returned => 2, :start => <DateTime Obj>, :end => <DateTime Obj>}}
|
165
175
|
def find_item(parent_folder_ids, traversal = 'Shallow', item_shape = {:base_shape => 'Default'}, opts = {})
|
166
176
|
action = "#{SOAP_ACTION_PREFIX}/FindItem"
|
167
|
-
resp = invoke("#{NS_EWS_MESSAGES}:FindItem",
|
177
|
+
resp = invoke("#{NS_EWS_MESSAGES}:FindItem", action) do |root|
|
168
178
|
build!(root) do
|
169
179
|
root.set_attr('Traversal', traversal)
|
170
180
|
item_shape!(root, item_shape)
|
@@ -202,7 +212,7 @@ module Viewpoint
|
|
202
212
|
# @param [Hash] opts optional parameters to this method
|
203
213
|
def get_folder(folder_ids, folder_shape = {:base_shape => 'Default'}, act_as = nil)
|
204
214
|
action = "#{SOAP_ACTION_PREFIX}/GetFolder"
|
205
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetFolder",
|
215
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetFolder", action) do |root|
|
206
216
|
build!(root) do
|
207
217
|
folder_shape!(root, folder_shape)
|
208
218
|
folder_ids!(root, folder_ids, act_as)
|
@@ -213,7 +223,7 @@ module Viewpoint
|
|
213
223
|
|
214
224
|
def convert_id
|
215
225
|
action = "#{SOAP_ACTION_PREFIX}/ConvertId"
|
216
|
-
resp = invoke("#{NS_EWS_MESSAGES}:ConvertId",
|
226
|
+
resp = invoke("#{NS_EWS_MESSAGES}:ConvertId", action) do |convert_id|
|
217
227
|
build_convert_id!(convert_id)
|
218
228
|
end
|
219
229
|
parse_convert_id(resp)
|
@@ -227,7 +237,7 @@ module Viewpoint
|
|
227
237
|
# @param [Array,String] folder_name The display name for the new folder or folders
|
228
238
|
def create_folder(parent_folder_id, folder_name)
|
229
239
|
action = "#{SOAP_ACTION_PREFIX}/CreateFolder"
|
230
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateFolder",
|
240
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateFolder", action) do |root|
|
231
241
|
build!(root) do
|
232
242
|
root.add("#{NS_EWS_MESSAGES}:ParentFolderId") do |pfid|
|
233
243
|
folder_id!(pfid, parent_folder_id)
|
@@ -251,7 +261,7 @@ module Viewpoint
|
|
251
261
|
# @param [String,nil] delete_type Type of delete to do: HardDelete/SoftDelete/MoveToDeletedItems
|
252
262
|
def delete_folder(folder_id, delete_type = 'MoveToDeletedItems')
|
253
263
|
action = "#{SOAP_ACTION_PREFIX}/DeleteFolder"
|
254
|
-
resp = invoke("#{NS_EWS_MESSAGES}:DeleteFolder",
|
264
|
+
resp = invoke("#{NS_EWS_MESSAGES}:DeleteFolder", action) do |root|
|
255
265
|
build!(root) do
|
256
266
|
root.set_attr('DeleteType', delete_type)
|
257
267
|
folder_id = (folder_id.is_a?(Array)) ? folder_id : [folder_id]
|
@@ -263,7 +273,7 @@ module Viewpoint
|
|
263
273
|
|
264
274
|
def update_folder
|
265
275
|
action = "#{SOAP_ACTION_PREFIX}/UpdateFolder"
|
266
|
-
resp = invoke("#{NS_EWS_MESSAGES}:UpdateFolder",
|
276
|
+
resp = invoke("#{NS_EWS_MESSAGES}:UpdateFolder", action) do |update_folder|
|
267
277
|
build_update_folder!(update_folder)
|
268
278
|
end
|
269
279
|
parse_update_folder(resp)
|
@@ -271,7 +281,7 @@ module Viewpoint
|
|
271
281
|
|
272
282
|
def move_folder
|
273
283
|
action = "#{SOAP_ACTION_PREFIX}/MoveFolder"
|
274
|
-
resp = invoke("#{NS_EWS_MESSAGES}:MoveFolder",
|
284
|
+
resp = invoke("#{NS_EWS_MESSAGES}:MoveFolder", action) do |move_folder|
|
275
285
|
build_move_folder!(move_folder)
|
276
286
|
end
|
277
287
|
parse_move_folder(resp)
|
@@ -279,7 +289,7 @@ module Viewpoint
|
|
279
289
|
|
280
290
|
def copy_folder
|
281
291
|
action = "#{SOAP_ACTION_PREFIX}/CopyFolder"
|
282
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CopyFolder",
|
292
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CopyFolder", action) do |copy_folder|
|
283
293
|
build_copy_folder!(copy_folder)
|
284
294
|
end
|
285
295
|
parse_copy_folder(resp)
|
@@ -299,7 +309,7 @@ module Viewpoint
|
|
299
309
|
# the PullSubscriptionRequest element.
|
300
310
|
def subscribe(folder_ids, event_types, timeout = 10)
|
301
311
|
action = "#{SOAP_ACTION_PREFIX}/Subscribe"
|
302
|
-
resp = invoke("#{NS_EWS_MESSAGES}:Subscribe",
|
312
|
+
resp = invoke("#{NS_EWS_MESSAGES}:Subscribe", action) do |root|
|
303
313
|
build!(root) do
|
304
314
|
pull_subscription_request!(folder_ids, event_types, timeout)
|
305
315
|
end
|
@@ -311,7 +321,7 @@ module Viewpoint
|
|
311
321
|
# @see http://msdn.microsoft.com/en-us/library/aa566188.aspx Subscribe on MSDN
|
312
322
|
def push_subscribe(folder_ids, event_types, url, watermark=nil, status_frequency=5)
|
313
323
|
action = "#{SOAP_ACTION_PREFIX}/Subscribe"
|
314
|
-
resp = invoke("#{NS_EWS_MESSAGES}:Subscribe",
|
324
|
+
resp = invoke("#{NS_EWS_MESSAGES}:Subscribe", action) do |root|
|
315
325
|
build!(root) do
|
316
326
|
push_subscription_request!(folder_ids, event_types, url, watermark, status_frequency)
|
317
327
|
end
|
@@ -326,7 +336,7 @@ module Viewpoint
|
|
326
336
|
# @param [String] subscription_id The Id of the subscription
|
327
337
|
def unsubscribe(subscription_id)
|
328
338
|
action = "#{SOAP_ACTION_PREFIX}/Unsubscribe"
|
329
|
-
resp = invoke("#{NS_EWS_MESSAGES}:Unsubscribe",
|
339
|
+
resp = invoke("#{NS_EWS_MESSAGES}:Unsubscribe", action) do |root|
|
330
340
|
build!(root) do
|
331
341
|
subscription_id!(root, subscription_id)
|
332
342
|
end
|
@@ -341,7 +351,7 @@ module Viewpoint
|
|
341
351
|
# @param [String] watermark Event bookmark in the events queue
|
342
352
|
def get_events(subscription_id, watermark)
|
343
353
|
action = "#{SOAP_ACTION_PREFIX}/GetEvents"
|
344
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetEvents",
|
354
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetEvents", action) do |root|
|
345
355
|
build!(root) do
|
346
356
|
subscription_id!(root, subscription_id)
|
347
357
|
watermark!(root, watermark)
|
@@ -352,7 +362,7 @@ module Viewpoint
|
|
352
362
|
|
353
363
|
def sync_folder_hierarchy
|
354
364
|
action = "#{SOAP_ACTION_PREFIX}/SyncFolderHierarchy"
|
355
|
-
resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderHierarchy",
|
365
|
+
resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderHierarchy", action) do |sync_folder_hierarchy|
|
356
366
|
build_sync_folder_hierarchy!(sync_folder_hierarchy)
|
357
367
|
end
|
358
368
|
parse_sync_folder_hierarchy(resp)
|
@@ -375,7 +385,7 @@ module Viewpoint
|
|
375
385
|
# @param [Hash] opts optional parameters to this method
|
376
386
|
def sync_folder_items(folder_id, sync_state = nil, max_changes = 256, item_shape = {:base_shape => 'Default'}, opts = {})
|
377
387
|
action = "#{SOAP_ACTION_PREFIX}/SyncFolderItems"
|
378
|
-
resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderItems",
|
388
|
+
resp = invoke("#{NS_EWS_MESSAGES}:SyncFolderItems", action) do |root|
|
379
389
|
build!(root) do
|
380
390
|
item_shape!(root, item_shape)
|
381
391
|
root.add("#{NS_EWS_MESSAGES}:SyncFolderId") do |sfid|
|
@@ -400,7 +410,7 @@ module Viewpoint
|
|
400
410
|
# @param [Hash] opts optional parameters to this method
|
401
411
|
def get_item(item_ids, item_shape = {:base_shape => 'Default'})
|
402
412
|
action = "#{SOAP_ACTION_PREFIX}/GetItem"
|
403
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetItem",
|
413
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetItem", action) do |root|
|
404
414
|
build!(root) do
|
405
415
|
item_shape!(root, item_shape)
|
406
416
|
item_ids!(root, item_ids)
|
@@ -423,7 +433,7 @@ module Viewpoint
|
|
423
433
|
# See: http://msdn.microsoft.com/en-us/library/aa565209.aspx
|
424
434
|
def create_message_item(folder_id, items, message_disposition = 'SaveOnly')
|
425
435
|
action = "#{SOAP_ACTION_PREFIX}/CreateItem"
|
426
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem",
|
436
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
|
427
437
|
build!(node) do
|
428
438
|
create_item!(folder_id, items, message_disposition, send_invites=false, 'message')
|
429
439
|
end
|
@@ -442,7 +452,7 @@ module Viewpoint
|
|
442
452
|
# @param [String] send_invites "SendToNone/SendOnlyToAll/SendToAllAndSaveCopy"
|
443
453
|
def create_calendar_item(folder_id, items, send_invites = 'SendToAllAndSaveCopy')
|
444
454
|
action = "#{SOAP_ACTION_PREFIX}/CreateItem"
|
445
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem",
|
455
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
|
446
456
|
build!(node) do
|
447
457
|
create_item!(folder_id, items, message_disposition=false, send_invites, 'calendar')
|
448
458
|
end
|
@@ -464,7 +474,7 @@ module Viewpoint
|
|
464
474
|
# See: http://msdn.microsoft.com/en-us/library/aa565209.aspx
|
465
475
|
def create_task_item(folder_id, items, message_disposition = 'SaveOnly')
|
466
476
|
action = "#{SOAP_ACTION_PREFIX}/CreateItem"
|
467
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem",
|
477
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
|
468
478
|
build!(node) do
|
469
479
|
create_item!(folder_id, items, message_disposition, false, 'task')
|
470
480
|
end
|
@@ -484,7 +494,7 @@ module Viewpoint
|
|
484
494
|
# This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
|
485
495
|
def create_contact_item(folder_id, items)
|
486
496
|
action = "#{SOAP_ACTION_PREFIX}/CreateItem"
|
487
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem",
|
497
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateItem", action) do |node|
|
488
498
|
build!(node) do
|
489
499
|
create_item!(folder_id, items, nil, false, 'contact')
|
490
500
|
end
|
@@ -502,7 +512,7 @@ module Viewpoint
|
|
502
512
|
# This is really only related to tasks and can be nil otherwise, which is the default.
|
503
513
|
def delete_item(item_ids, delete_type, send_meeting_cancellations = nil, affected_task_occurrences = nil)
|
504
514
|
action = "#{SOAP_ACTION_PREFIX}/DeleteItem"
|
505
|
-
resp = invoke("#{NS_EWS_MESSAGES}:DeleteItem",
|
515
|
+
resp = invoke("#{NS_EWS_MESSAGES}:DeleteItem", action) do |root|
|
506
516
|
build!(root) do
|
507
517
|
root.set_attr('DeleteType', delete_type)
|
508
518
|
root.set_attr('SendMeetingCancellations', send_meeting_cancellations) unless send_meeting_cancellations.nil?
|
@@ -515,7 +525,7 @@ module Viewpoint
|
|
515
525
|
|
516
526
|
def update_item
|
517
527
|
action = "#{SOAP_ACTION_PREFIX}/UpdateItem"
|
518
|
-
resp = invoke("#{NS_EWS_MESSAGES}:UpdateItem",
|
528
|
+
resp = invoke("#{NS_EWS_MESSAGES}:UpdateItem", action) do |root|
|
519
529
|
build!(root) do
|
520
530
|
end
|
521
531
|
end
|
@@ -533,7 +543,7 @@ module Viewpoint
|
|
533
543
|
# it blank for the default :sentitems
|
534
544
|
def send_item(item_ids, save_item=true, saved_item_folder=nil)
|
535
545
|
action = "#{SOAP_ACTION_PREFIX}/SendItem"
|
536
|
-
resp = invoke("#{NS_EWS_MESSAGES}:SendItem",
|
546
|
+
resp = invoke("#{NS_EWS_MESSAGES}:SendItem", action) do |root|
|
537
547
|
build!(root) do
|
538
548
|
root.set_attr('SaveItemToFolder', save_item)
|
539
549
|
item_ids!(root,item_ids)
|
@@ -550,7 +560,7 @@ module Viewpoint
|
|
550
560
|
# (must me a Symbol) or a FolderId (String)
|
551
561
|
def move_item(item_ids, folder_id)
|
552
562
|
action = "#{SOAP_ACTION_PREFIX}/MoveItem"
|
553
|
-
resp = invoke("#{NS_EWS_MESSAGES}:MoveItem",
|
563
|
+
resp = invoke("#{NS_EWS_MESSAGES}:MoveItem", action) do |root|
|
554
564
|
build!(root) do
|
555
565
|
to_folder_id!(root, folder_id)
|
556
566
|
item_ids!(root, item_ids)
|
@@ -566,7 +576,7 @@ module Viewpoint
|
|
566
576
|
# (must me a Symbol) or a FolderId (String)
|
567
577
|
def copy_item(item_ids, folder_id)
|
568
578
|
action = "#{SOAP_ACTION_PREFIX}/CopyItem"
|
569
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CopyItem",
|
579
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CopyItem", action) do |root|
|
570
580
|
build!(root) do
|
571
581
|
to_folder_id!(root, folder_id)
|
572
582
|
item_ids!(root, item_ids)
|
@@ -587,7 +597,7 @@ module Viewpoint
|
|
587
597
|
# @todo Need to implement attachment of Item types
|
588
598
|
def create_attachment(parent_id, files = [], items = [])
|
589
599
|
action = "#{SOAP_ACTION_PREFIX}/CreateAttachment"
|
590
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateAttachment",
|
600
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateAttachment", action) do |root|
|
591
601
|
build!(root) do
|
592
602
|
item_id!(root, parent_id, "#{NS_EWS_MESSAGES}:ParentItemId")
|
593
603
|
attachments!(root, files, items)
|
@@ -598,7 +608,7 @@ module Viewpoint
|
|
598
608
|
|
599
609
|
def delete_attachment
|
600
610
|
action = "#{SOAP_ACTION_PREFIX}/DeleteAttachment"
|
601
|
-
resp = invoke("#{NS_EWS_MESSAGES}:DeleteAttachment",
|
611
|
+
resp = invoke("#{NS_EWS_MESSAGES}:DeleteAttachment", action) do |delete_attachment|
|
602
612
|
build_delete_attachment!(delete_attachment)
|
603
613
|
end
|
604
614
|
parse_delete_attachment(resp)
|
@@ -609,7 +619,7 @@ module Viewpoint
|
|
609
619
|
# @param [Array] attachment_ids Attachment Ids to fetch
|
610
620
|
def get_attachment(attachment_ids)
|
611
621
|
action = "#{SOAP_ACTION_PREFIX}/GetAttachment"
|
612
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetAttachment",
|
622
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetAttachment", action) do |root|
|
613
623
|
build!(root) do
|
614
624
|
attachment_shape!(root)
|
615
625
|
attachment_ids!(root, attachment_ids)
|
@@ -620,7 +630,7 @@ module Viewpoint
|
|
620
630
|
|
621
631
|
def create_managed_folder
|
622
632
|
action = "#{SOAP_ACTION_PREFIX}/CreateManagedFolder"
|
623
|
-
resp = invoke("#{NS_EWS_MESSAGES}:CreateManagedFolder",
|
633
|
+
resp = invoke("#{NS_EWS_MESSAGES}:CreateManagedFolder", action) do |create_managed_folder|
|
624
634
|
build_create_managed_folder!(create_managed_folder)
|
625
635
|
end
|
626
636
|
parse_create_managed_folder(resp)
|
@@ -632,7 +642,7 @@ module Viewpoint
|
|
632
642
|
# @param [String] owner The user that is delegating permissions
|
633
643
|
def get_delegate(owner)
|
634
644
|
action = "#{SOAP_ACTION_PREFIX}/GetDelegate"
|
635
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetDelegate",
|
645
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetDelegate", action) do |root|
|
636
646
|
root.set_attr('IncludePermissions', 'true')
|
637
647
|
build!(root) do
|
638
648
|
mailbox!(root, {:email_address => {:text => owner}})
|
@@ -650,7 +660,7 @@ module Viewpoint
|
|
650
660
|
# This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
|
651
661
|
def add_delegate(owner, delegate, permissions)
|
652
662
|
action = "#{SOAP_ACTION_PREFIX}/AddDelegate"
|
653
|
-
resp = invoke("#{NS_EWS_MESSAGES}:AddDelegate",
|
663
|
+
resp = invoke("#{NS_EWS_MESSAGES}:AddDelegate", action) do |root|
|
654
664
|
build!(root) do
|
655
665
|
add_delegate!(owner, delegate, permissions)
|
656
666
|
end
|
@@ -665,7 +675,7 @@ module Viewpoint
|
|
665
675
|
# @param [String] delegate The user that is being given delegate permission
|
666
676
|
def remove_delegate(owner, delegate)
|
667
677
|
action = "#{SOAP_ACTION_PREFIX}/RemoveDelegate"
|
668
|
-
resp = invoke("#{NS_EWS_MESSAGES}:RemoveDelegate",
|
678
|
+
resp = invoke("#{NS_EWS_MESSAGES}:RemoveDelegate", action) do |root|
|
669
679
|
build!(root) do
|
670
680
|
remove_delegate!(owner, delegate)
|
671
681
|
end
|
@@ -682,7 +692,7 @@ module Viewpoint
|
|
682
692
|
# This Hash will eventually be passed to add_hierarchy! in the builder so it is in that format.
|
683
693
|
def update_delegate(owner, delegate, permissions)
|
684
694
|
action = "#{SOAP_ACTION_PREFIX}/UpdateDelegate"
|
685
|
-
resp = invoke("#{NS_EWS_MESSAGES}:UpdateDelegate",
|
695
|
+
resp = invoke("#{NS_EWS_MESSAGES}:UpdateDelegate", action) do |root|
|
686
696
|
build!(root) do
|
687
697
|
add_delegate!(owner, delegate, permissions)
|
688
698
|
end
|
@@ -695,7 +705,7 @@ module Viewpoint
|
|
695
705
|
# @see http://msdn.microsoft.com/en-us/library/aa564001.aspx
|
696
706
|
def get_user_availability
|
697
707
|
action = "#{SOAP_ACTION_PREFIX}/GetUserAvailability"
|
698
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetUserAvailability",
|
708
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetUserAvailability", action) do |get_user_availability|
|
699
709
|
build_get_user_availability!(get_user_availability)
|
700
710
|
end
|
701
711
|
parse_get_user_availability(resp)
|
@@ -705,7 +715,7 @@ module Viewpoint
|
|
705
715
|
# @see http://msdn.microsoft.com/en-us/library/aa563465.aspx
|
706
716
|
def get_user_oof_settings(mailbox)
|
707
717
|
action = "#{SOAP_ACTION_PREFIX}/GetUserOofSettings"
|
708
|
-
resp = invoke("#{NS_EWS_MESSAGES}:GetUserOofSettingsRequest",
|
718
|
+
resp = invoke("#{NS_EWS_MESSAGES}:GetUserOofSettingsRequest", action) do |root|
|
709
719
|
build!(root) do
|
710
720
|
mailbox!(root,mailbox[:mailbox],NS_EWS_TYPES)
|
711
721
|
end
|
@@ -717,7 +727,7 @@ module Viewpoint
|
|
717
727
|
# @see http://msdn.microsoft.com/en-us/library/aa580294.aspx
|
718
728
|
def set_user_oof_settings(mailbox, oof_state, ext_audience, dt_start, dt_end, int_msg, ext_mg)
|
719
729
|
action = "#{SOAP_ACTION_PREFIX}/SetUserOofSettings"
|
720
|
-
resp = invoke("#{NS_EWS_MESSAGES}:SetUserOofSettings",
|
730
|
+
resp = invoke("#{NS_EWS_MESSAGES}:SetUserOofSettings", action) do |root|
|
721
731
|
build!(root)
|
722
732
|
end
|
723
733
|
parse!(resp)
|
@@ -736,6 +746,11 @@ module Viewpoint
|
|
736
746
|
EwsParser.new(response).parse(opts)
|
737
747
|
end
|
738
748
|
|
749
|
+
# Override the superclasses' invoke so we can add http_options to each request
|
750
|
+
def invoke(msg, action)
|
751
|
+
super(msg, {:soap_action => action, :http_options => @@http_options})
|
752
|
+
end
|
753
|
+
|
739
754
|
end # class ExchangeWebService
|
740
755
|
end # module SOAP
|
741
756
|
end # EWS
|
data/lib/viewpoint.rb
CHANGED
@@ -55,6 +55,9 @@ require 'model/task'
|
|
55
55
|
require 'model/attachment'
|
56
56
|
require 'model/file_attachment'
|
57
57
|
require 'model/item_attachment'
|
58
|
+
# Third Party Libraries
|
59
|
+
require 'mail' # used to convert Message items to RFC822 compliant messages
|
60
|
+
require 'icalendar' # used to convert Calendar items to iCalendar objects
|
58
61
|
|
59
62
|
# Load the Exception classes
|
60
63
|
require 'exceptions/exceptions'
|
@@ -107,13 +110,20 @@ module Viewpoint
|
|
107
110
|
Handsoap.http_driver = driver
|
108
111
|
end
|
109
112
|
|
113
|
+
# Sets the CA path to a certificate or hashed certificate directory.
|
114
|
+
# This is the same as HTTPClient::SSLConfig.set_trust_ca
|
115
|
+
# @param [String] ca_path A path to an OpenSSL::X509::Certificate or a 'c-rehash'ed directory
|
116
|
+
def self.set_trust_ca(ca_path)
|
117
|
+
SOAP::ExchangeWebService.set_http_options(:trust_ca_file => ca_path) && true
|
118
|
+
end
|
119
|
+
|
110
120
|
def initialize
|
111
121
|
@ews = SOAP::ExchangeWebService.new
|
112
122
|
end
|
113
123
|
|
114
124
|
# The MailboxUser object that represents the user connected to EWS.
|
115
125
|
def me
|
116
|
-
@me ||= MailboxUser.find_user("#{@@user}@")
|
126
|
+
@me ||= MailboxUser.find_user((@@user.include?('@') ? @@user : "#{@@user}@"))
|
117
127
|
end
|
118
128
|
|
119
129
|
end # class EWS
|