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
@@ -1,104 +0,0 @@
1
- =begin
2
- This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
-
4
- Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- =end
18
-
19
- module Viewpoint
20
- module EWS
21
- module SOAP
22
- module Parser
23
-
24
- def initialize(response)
25
- # Unwrap SOAP Envelope
26
- @response = response
27
- @response_type = (response/"//#{NS_SOAP}:Body/*").first.node_name
28
-
29
- rmsg = (response/'//*[@ResponseClass]').first
30
- @response_message = EwsSoapResponse.new(rmsg['ResponseClass'],
31
- (rmsg/'m:ResponseCode/text()').first.to_s,
32
- (rmsg/'m:MessageText/text()').first.to_s)
33
-
34
- @response_message.set_soap_resp(response)
35
- end
36
-
37
- # This is the main parser method. It takes the response type and tries to
38
- # call a Ruby method of the same name.
39
- # @todo Decide on an appropriate response if a method does not exist.
40
- def parse(opts)
41
- resp_method = @response_type.ruby_case
42
- if(respond_to?(resp_method))
43
- puts "Method Exists: #{resp_method}" if $DEBUG
44
- method(resp_method).call(opts)
45
- else
46
- puts "No Method: #{resp_method}" if $DEBUG
47
- end
48
- @response_message
49
- end
50
-
51
- private
52
-
53
- def method_exists?(method_name)
54
- return self.methods.include?(method_name)
55
- end
56
-
57
- # Create a Hash from a Nokogiri element tree
58
- # @param [Nokogiri::XML::Element, Nokogiri::XML::Text] nokoelem The Nokogiri element passed to this method
59
- # @example XML
60
- # <tiptop>
61
- # <top Id="32fss">TestText</top>
62
- # <middle Id='TestTestMiddle' />
63
- # <bottom />
64
- # </tiptop>
65
- # becomes...
66
- # {:tiptop=>{:top=>{:id=>"32fss", :text=>"TestText"}, :middle=>{:id=>"TestTestMiddle"}}}
67
- def xml_to_hash!(nokoelem)
68
- e_hash = {}
69
- node_name = nokoelem.name.ruby_case.to_sym
70
-
71
- if nokoelem.is_a? Nokogiri::XML::Element
72
- nokoelem.attributes.each_pair do |k, v|
73
- e_hash[k.ruby_case.to_sym] = v.value
74
- end
75
- nokoelem.children.each do |c|
76
- new_hash = xml_to_hash!(c)
77
- unless new_hash.nil?
78
- e_hash.merge!(new_hash) do |k,v1,v2|
79
- if(v1.is_a?(Array))
80
- v1 << v2
81
- else
82
- [v1, v2]
83
- end
84
- end
85
- end
86
- end
87
- return e_hash.empty? ? nil : {node_name => e_hash}
88
- elsif nokoelem.is_a? Nokogiri::XML::Text
89
- # Return a :text to value hash or nil if the text is empty
90
- return {node_name => nokoelem.text} if nokoelem.text != "\n"
91
- nil
92
- else
93
- # If something strange gets passed just return nil
94
- return nil
95
- end
96
- end
97
-
98
-
99
- end # Parser
100
- end # SOAP
101
- end # SPWS
102
- end # Viewpoint
103
-
104
- require 'soap/handsoap/parsers/ews_parser'
@@ -1,246 +0,0 @@
1
- =begin
2
- This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
-
4
- Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- =end
18
-
19
- module Viewpoint
20
- module EWS
21
- module SOAP
22
- class EwsParser
23
- include Parser
24
-
25
- # Parsing Methods
26
- # ---------------
27
-
28
- def resolve_names_response(opts)
29
- @response_message.items = resolution_set
30
- end
31
-
32
- def get_folder_response(opts)
33
- @response_message.items = folders
34
- end
35
-
36
- def find_folder_response(opts)
37
- folders = []
38
- (@response/"//#{NS_EWS_MESSAGES}:FindFolderResponseMessage//#{NS_EWS_TYPES}:Folders/*").each do |f|
39
- folders << xml_to_hash!(f.native_element)
40
- end
41
- @response_message.items = folders
42
- end
43
-
44
- def create_folder_response(opts)
45
- if(@response_message.status == 'Success')
46
- folders = []
47
- (@response/"//#{NS_EWS_MESSAGES}:Folders/*").each do |f|
48
- folders << xml_to_hash!(f.native_element)
49
- end
50
- @response_message.items = folders
51
- else
52
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
53
- end
54
- end
55
-
56
- def delete_folder_response(opts)
57
- raise EwsError, "#{@response_message.code}: #{@response_message.message}" unless @response_message.status == 'Success'
58
- end
59
-
60
- def get_events_response(opts)
61
- if @response_message.status == 'Success'
62
- events = []
63
- events << {}
64
- events.first[:subscription_id] = (@response/"//#{NS_EWS_MESSAGES}:Notification/#{NS_EWS_TYPES}:SubscriptionId").first.to_s
65
- events.first[:more_events] = (@response/"//#{NS_EWS_MESSAGES}:Notification/#{NS_EWS_TYPES}:SubscriptionId").first.to_boolean
66
-
67
- (@response/"//#{NS_EWS_MESSAGES}:Notification/*[position()>3]").each do |e|
68
- events << xml_to_hash!(e.native_element)
69
- events.first[:watermark] = events.last[events.last.keys.first][:watermark][:text]
70
- end
71
-
72
- @response_message.items = events
73
- else
74
- raise EwsSubscriptionTimeout.new("#{@response_message.code}: #{@response_message.message}")
75
- end
76
- end
77
-
78
- def find_item_response(opts)
79
- items = []
80
- items << {}
81
- items.first[:total_items_in_view] = (@response/"//#{NS_EWS_MESSAGES}:FindItemResponseMessage/#{NS_EWS_MESSAGES}:RootFolder/@TotalItemsInView").first.to_i
82
-
83
- (@response/"//#{NS_EWS_MESSAGES}:FindItemResponseMessage//#{NS_EWS_TYPES}:Items/*").each do |i|
84
- items << xml_to_hash!(i.native_element)
85
- end
86
-
87
- @response_message.items = items
88
- end
89
-
90
- # Parsers the response from the SOAP Subscribe operation
91
- # @see http://msdn.microsoft.com/en-us/library/aa566188.aspx
92
- #
93
- # @return [Hash] A hash with the keys :watermark and :subscription_id
94
- # @raise [EwsError] Raise an error if the ResponseClass is not Success
95
- def subscribe_response(opts)
96
- subscription = []
97
- sid = xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:SubscriptionId").first.native_element)
98
- wmk = xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Watermark").first.native_element)
99
- subscription << sid.merge(wmk)
100
- @response_message.items = subscription
101
- end
102
-
103
- # @todo Better handle error messages
104
- def unsubscribe_response(opts)
105
- @response_message
106
- end
107
-
108
- def get_item_response(opts)
109
- if(@response_message.status == 'Success')
110
- (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |item|
111
- @response_message.items << xml_to_hash!(item.native_element)
112
- end
113
- else
114
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
115
- end
116
- end
117
-
118
- def copy_item_response(opts)
119
- if(@response_message.status == 'Success')
120
- @response_message.items << xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Items/*").first.native_element)
121
- else
122
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
123
- end
124
- end
125
-
126
- def move_item_response(opts)
127
- if(@response_message.status == 'Success')
128
- @response_message.items << xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Items/*").first.native_element)
129
- else
130
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
131
- end
132
- end
133
-
134
- # @todo need to find out out to us XPath to get ItemId. It doesn't seem to work now.
135
- def create_item_response(opts)
136
- if(@response_message.status == 'Success')
137
- items = []
138
- (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |i|
139
- items << xml_to_hash!(i.native_element)
140
- end
141
- @response_message.items = items
142
- else
143
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
144
- end
145
- end
146
-
147
- def update_item_response(opts)
148
- create_item_response(opts)
149
- end
150
-
151
- def send_item_response(opts)
152
- if(@response_message.status == 'Success')
153
- items = []
154
- (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |i|
155
- items << xml_to_hash!(i.native_element)
156
- end
157
- @response_message.items = items
158
- else
159
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
160
- end
161
- end
162
-
163
- def get_attachment_response(opts)
164
- atts = []
165
- if(@response_message.status == 'Success')
166
- att_id = (@response/"//#{NS_EWS_MESSAGES}:Attachments/*").each do |a|
167
- atts << xml_to_hash!(a.native_element)
168
- end
169
- @response_message.items = atts
170
- #@response_message.items = @response
171
- else
172
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
173
- end
174
- end
175
-
176
- def create_attachment_response(opts)
177
- if(@response_message.status == 'Success')
178
- att_id = (@response/"//#{NS_EWS_TYPES}:FileAttachment/*").last
179
- att_id = xml_to_hash!(att_id.native_element)
180
- @response_message.items = [att_id]
181
- else
182
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
183
- end
184
- end
185
-
186
- def sync_folder_items_response(opts)
187
- if(@response_message.status == 'Success')
188
- sync = []
189
- sync << {}
190
- sync.first[:sync_state] = (@response/"//#{NS_EWS_MESSAGES}:SyncState").first.to_s
191
- sync.first[:includes_last_item_in_range] = (@response/"//#{NS_EWS_MESSAGES}:IncludesLastItemInRange").first.to_boolean
192
- (@response/"//m:Changes/*").each do |c|
193
- sync << xml_to_hash!(c.native_element)
194
- end
195
- @response_message.items = sync
196
- else
197
- raise EwsError, "#{@response_message.code}: #{@response_message.message}"
198
- end
199
- end
200
-
201
- def get_user_oof_settings_response(opts)
202
- @response_message.items = xml_to_hash!((@response/"//#{NS_EWS_TYPES}:OofSettings").first.native_element)
203
- end
204
-
205
- # Parse out the free/busy time.
206
- # @see http://msdn.microsoft.com/en-us/library/aa494212.aspx
207
- def get_user_availability_response(opts)
208
- @response_message.items = xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:FreeBusyView").first.native_element)
209
- end
210
-
211
- # Parse out a Mailbox element
212
- # @param [XML] mbox The <t:Mailbox> element
213
- # @return [Hash] Values of EWS Mailbox type :name, :email_address, :routing_type, :mailbox_type, :item_id
214
- def mailbox(mbox_xml)
215
- xml_to_hash!(mbox_xml.native_element)
216
- end
217
-
218
- def contact(contact_xml)
219
- xml_to_hash!(contact_xml.native_element)
220
- end
221
-
222
- # Parse out Resolutions from a ResolutionSet from the ResolveNames operation
223
- # @return [Array] An array of :mailbox,:contact Hashes that resolved.
224
- def resolution_set
225
- resolution_set = []
226
- (@response/"//#{NS_EWS_MESSAGES}:ResolutionSet/*").each do |r|
227
- mbox_hash = mailbox((r/"#{NS_EWS_TYPES}:Mailbox").first)
228
- contact_xml = (r/"#{NS_EWS_TYPES}:Contact").first
229
- next if !contact_xml
230
- resolution_set << mbox_hash.merge(contact(contact_xml))
231
- end
232
- resolution_set
233
- end
234
-
235
- def folders
236
- folders = []
237
- (@response/"//#{NS_EWS_MESSAGES}:Folders/*").each do |f|
238
- folders << xml_to_hash!(f.native_element)
239
- end
240
- folders
241
- end
242
-
243
- end # EwsParser
244
- end # SOAP
245
- end # EWS
246
- end # Viewpoint
@@ -1,64 +0,0 @@
1
- =begin
2
- This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
-
4
- Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License.
8
- You may obtain a copy of the License at
9
-
10
- http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- Unless required by applicable law or agreed to in writing, software
13
- distributed under the License is distributed on an "AS IS" BASIS,
14
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- See the License for the specific language governing permissions and
16
- limitations under the License.
17
- =end
18
-
19
- # This file requires the appropriate SOAP Library (Handsoap today) and also
20
- # defines certain contants that SOAP methods may use.
21
- module Viewpoint
22
- module EWS
23
- module SOAP
24
-
25
- # CONSTANTS
26
-
27
- NS_SOAP = 'soap' # http://schemas.xmlsoap.org/soap/envelope/
28
- NS_EWS_TYPES = 't' # http://schemas.microsoft.com/exchange/services/2006/types
29
- NS_EWS_MESSAGES = 'm' # http://schemas.microsoft.com/exchange/services/2006/messages
30
-
31
- # used in ResolveNames to determine where names are resolved
32
- ActiveDirectory = 'ActiveDirectory'
33
- ActiveDirectoryContacts = 'ActiveDirectoryContacts'
34
- Contacts = 'Contacts'
35
- ContactsActiveDirectory = 'ContactsActiveDirectory'
36
-
37
-
38
-
39
- # A Generic Class for SOAP returns.
40
- # @attr_reader [String] :message The text from the EWS element <m:ResponseCode>
41
- class EwsSoapResponse
42
-
43
- attr_reader :status, :code, :message, :soap_response
44
- attr_accessor :items
45
-
46
- def initialize(status, code, message)
47
- @status, @code, @message = status, code, message
48
-
49
- # Items is an array where hash types get stored for return
50
- @items = []
51
- end
52
-
53
- def set_soap_resp(response)
54
- @soap_response = response
55
- end
56
-
57
- end # EwsSoapResponse
58
-
59
-
60
- end # SOAP
61
- end # EWS
62
- end # Viewpoint
63
-
64
- require 'soap/handsoap/ews_service'