viewpoint2 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +216 -0
  3. data/lib/ews/calendar_accessors.rb +34 -0
  4. data/lib/ews/connection.rb +130 -0
  5. data/lib/ews/connection_helper.rb +35 -0
  6. data/lib/ews/convert_accessors.rb +56 -0
  7. data/lib/ews/errors.rb +56 -0
  8. data/lib/ews/ews_client.rb +103 -0
  9. data/lib/ews/exceptions/exceptions.rb +61 -0
  10. data/lib/ews/folder_accessors.rb +264 -0
  11. data/lib/ews/impersonation.rb +30 -0
  12. data/lib/ews/item_accessors.rb +231 -0
  13. data/lib/ews/mailbox_accessors.rb +99 -0
  14. data/lib/ews/message_accessors.rb +93 -0
  15. data/lib/ews/push_subscription_accessors.rb +33 -0
  16. data/lib/ews/room_accessors.rb +48 -0
  17. data/lib/ews/roomlist_accessors.rb +47 -0
  18. data/lib/ews/soap.rb +64 -0
  19. data/lib/ews/soap/builders/ews_builder.rb +1351 -0
  20. data/lib/ews/soap/ews_response.rb +84 -0
  21. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  22. data/lib/ews/soap/ews_soap_free_busy_response.rb +119 -0
  23. data/lib/ews/soap/ews_soap_response.rb +103 -0
  24. data/lib/ews/soap/ews_soap_room_response.rb +53 -0
  25. data/lib/ews/soap/ews_soap_roomlist_response.rb +54 -0
  26. data/lib/ews/soap/exchange_availability.rb +61 -0
  27. data/lib/ews/soap/exchange_data_services.rb +780 -0
  28. data/lib/ews/soap/exchange_notification.rb +146 -0
  29. data/lib/ews/soap/exchange_synchronization.rb +93 -0
  30. data/lib/ews/soap/exchange_time_zones.rb +56 -0
  31. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  32. data/lib/ews/soap/exchange_web_service.rb +264 -0
  33. data/lib/ews/soap/parsers/ews_parser.rb +43 -0
  34. data/lib/ews/soap/parsers/ews_sax_document.rb +70 -0
  35. data/lib/ews/soap/response_message.rb +80 -0
  36. data/lib/ews/soap/responses/create_attachment_response_message.rb +47 -0
  37. data/lib/ews/soap/responses/create_item_response_message.rb +25 -0
  38. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  39. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  40. data/lib/ews/soap/responses/send_notification_response_message.rb +59 -0
  41. data/lib/ews/soap/responses/subscribe_response_message.rb +35 -0
  42. data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +36 -0
  43. data/lib/ews/soap/responses/sync_folder_items_response_message.rb +36 -0
  44. data/lib/ews/templates/calendar_item.rb +79 -0
  45. data/lib/ews/templates/forward_item.rb +24 -0
  46. data/lib/ews/templates/message.rb +76 -0
  47. data/lib/ews/templates/reply_to_item.rb +25 -0
  48. data/lib/ews/templates/task.rb +74 -0
  49. data/lib/ews/types.rb +194 -0
  50. data/lib/ews/types/attachment.rb +77 -0
  51. data/lib/ews/types/attendee.rb +41 -0
  52. data/lib/ews/types/calendar_folder.rb +50 -0
  53. data/lib/ews/types/calendar_item.rb +133 -0
  54. data/lib/ews/types/contact.rb +7 -0
  55. data/lib/ews/types/contacts_folder.rb +8 -0
  56. data/lib/ews/types/copied_event.rb +51 -0
  57. data/lib/ews/types/created_event.rb +24 -0
  58. data/lib/ews/types/deleted_event.rb +24 -0
  59. data/lib/ews/types/distribution_list.rb +7 -0
  60. data/lib/ews/types/event.rb +62 -0
  61. data/lib/ews/types/export_items_response_message.rb +52 -0
  62. data/lib/ews/types/file_attachment.rb +65 -0
  63. data/lib/ews/types/folder.rb +60 -0
  64. data/lib/ews/types/free_busy_changed_event.rb +24 -0
  65. data/lib/ews/types/generic_folder.rb +418 -0
  66. data/lib/ews/types/item.rb +450 -0
  67. data/lib/ews/types/item_attachment.rb +84 -0
  68. data/lib/ews/types/item_field_uri_map.rb +208 -0
  69. data/lib/ews/types/mailbox_user.rb +156 -0
  70. data/lib/ews/types/meeting_cancellation.rb +7 -0
  71. data/lib/ews/types/meeting_message.rb +7 -0
  72. data/lib/ews/types/meeting_request.rb +7 -0
  73. data/lib/ews/types/meeting_response.rb +7 -0
  74. data/lib/ews/types/message.rb +7 -0
  75. data/lib/ews/types/modified_event.rb +48 -0
  76. data/lib/ews/types/moved_event.rb +51 -0
  77. data/lib/ews/types/new_mail_event.rb +24 -0
  78. data/lib/ews/types/out_of_office.rb +147 -0
  79. data/lib/ews/types/post_item.rb +7 -0
  80. data/lib/ews/types/search_folder.rb +8 -0
  81. data/lib/ews/types/status_event.rb +39 -0
  82. data/lib/ews/types/task.rb +104 -0
  83. data/lib/ews/types/tasks_folder.rb +27 -0
  84. data/lib/viewpoint/logging.rb +27 -0
  85. data/lib/viewpoint/logging/config.rb +24 -0
  86. data/lib/viewpoint/string_utils.rb +76 -0
  87. data/lib/viewpoint2.rb +111 -0
  88. metadata +191 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7c6bc7ab0a66ba5048d00c1b970c55f46547818
4
+ data.tar.gz: dfc1d33439763b8fd8d11b729e6440a2565de503
5
+ SHA512:
6
+ metadata.gz: a7903209dff406fdd9fb9eb68bb2b8c1b9586394cde6a8f59dc1e64c383bed4e54115284e9a52b2e3adf4bb27ba26d62059ed2efac1eccf5c164b6cabcc0b931
7
+ data.tar.gz: aba3ad47e9951fc7a2c247c3fc28133fddac8180f7d2315ce9099fb104bdfb66050a3c019e20640b7c72ee4cbec6bd9c8d2cb96a7fd9bace536d5886ff613e62
@@ -0,0 +1,216 @@
1
+ ## Tests
2
+
3
+ You can run the tests with `geordi rspec spec/`.
4
+
5
+ ## Debugging
6
+
7
+ Add `require 'pry'` before calling `binding.pry`.
8
+
9
+
10
+ The following is a copy of the original README.md:
11
+
12
+ # Viewpoint for Exchange Web Services
13
+ [![Build Status](https://img.shields.io/travis/WinRb/Viewpoint.svg?branch=master)](https://travis-ci.org/WinRb/Viewpoint)
14
+ [![Gem Version](https://img.shields.io/gem/v/viewpoint.svg)](https://rubygems.org/gems/viewpoint)
15
+ [![License](https://img.shields.io/github/license/WinRb/Viewpoint.svg)](https://github.com/WinRb/Viewpoint/blob/master/LICENSE)
16
+ [![Wiki](https://img.shields.io/badge/docs-wiki-lightgrey.svg)](http://github.com/WinRb/Viewpoint/wiki)
17
+ [![Documentation](https://img.shields.io/badge/docs-rdoc-lightgrey.svg)](http://www.rubydoc.info/github/WinRb/Viewpoint/frames)
18
+
19
+ http://github.com/zenchild/Viewpoint/wiki
20
+
21
+ Viewpoint for EWS provides a thin Ruby layer on top of Microsoft Exchange
22
+ Web Services(EWS). It also includes a bunch of model classes that add an
23
+ additional layer of abstraction on top of EWS for use in implementing
24
+ programs with Viewpoint.
25
+
26
+ BLOG: http://distributed-frostbite.blogspot.com/
27
+
28
+ Add me in LinkedIn: http://www.linkedin.com/in/danwanek
29
+
30
+ Find me on irc.freenode.net in #ruby-lang (zenChild)
31
+
32
+ # Features
33
+
34
+ ## New in 1.0
35
+
36
+ * SOAP backend is now only dependant on Nokogiri. Before version 1.0 Viewpoint
37
+ went through a number of iterations in backends including SOAP4r and Handsoap.
38
+ Each of these approaches had major issues so in the end I decided it was
39
+ easiest to just build the SOAP messages with Nokogiri since I was using it as
40
+ the parser for response messages already.
41
+
42
+ * Viewpoint is no longer built on a Singleton pattern. The reason it was
43
+ previously is because of the Handsoap backend. Handsoap itself uses a
44
+ Singleton pattern for connection to the SOAP endpoint so with authentication
45
+ I was forced to implement Viewpoint as a Singleton as well. Now with Handsoap
46
+ out of the picture this is no longer required. Go crazy ;)
47
+
48
+ ## Enhanced in 1.0
49
+
50
+ * *Delegate access is supported*
51
+ One thing that was often asked for, but missing from the previous version was delegate access to mailboxes and calendars. This is now supported via the `act_as` parameter to the `GenericFolder::get_folder` method.
52
+
53
+ > Inbox example:
54
+ ```inbox = Folder.get_folder(:inbox, opts = {act_as: "user@host.com"})```
55
+
56
+ > If your user has delegate access to the Inbox for user@host.com this operation will retrieve their inbox and allow you to manipulate it as you would with your own Inbox.
57
+
58
+ > Calendar example:
59
+ ```calendar = cli.get_folder(:calendar, opts = {act_as: "user@host.com"})```
60
+
61
+ > If your user has delegate access to the Calendar for user@host.com this operation will retrieve their calendar and allow you to manipulate it as you would with your own Calendar, depending on the permissions the other user has granted you.
62
+
63
+
64
+ * There is also some support for manipulation of delegate access itself via
65
+ the methods `MailboxUser#add_delegate!`, `MailboxUser#update_delegate!`, and
66
+ `MailboxUser#get_delegate_info`.
67
+
68
+
69
+ # Using Viewpoint
70
+
71
+ The version 1.0 API is quite a departure from the 0.1.x code base. If you have a lot of legacy code and aren't suffering from performance issues, think twice about upgrading. That said, I hope you'll find the new API much clean and more intuitive than previous versions.
72
+
73
+ I also try and document the code to the base of my ability. Included in that code are links to the official Microsoft EWS documentation that might be helpful when troubleshooting "interesting" issues. You can either generate the documentation yourself with yard or check it out on [rdoc.info](http://rdoc.info/github/zenchild/Viewpoint/frames).
74
+
75
+ Note the `cli` variable in the setup code directly below. I will use that variable throughout without the setup code.
76
+
77
+ ## The Setup
78
+ ```ruby
79
+ require 'viewpoint'
80
+ include Viewpoint::EWS
81
+
82
+ endpoint = 'https://example.com/ews/Exchange.asmx'
83
+ user = 'username'
84
+ pass = 'password'
85
+
86
+ cli = Viewpoint::EWSClient.new endpoint, user, pass
87
+ ```
88
+
89
+ There are also various options you can pass to EWSClient.
90
+
91
+ If you are testing in an environment using a self-signed certificate you can pass a connection parameter to ignore SSL verification by passing `http_opts: {ssl_verify_mode: 0}`.
92
+
93
+ If you want to target a specific version of Exchange you can pass `server_version: SOAP::ExchangeWebService::VERSION_2010_SP1`. You really shouldn't have to use this unless you know why. If you are interacting with servers which you do not know the version(s) of, an incorrect version may manifest as a `SoapResponseError` or a HTTP 400 `ResponseError`. Note that different versions are particular; for example, `VERSION_2007` may not work against a `VERSION_2007_SP1` system.
94
+
95
+ ## Accessors
96
+
97
+ There are some basic accessors available on the `Viewpoint::EWSClient` instance. In prior versions these were typically class methods off of the models themselves (ex: `Folder.get_folder(id)`). Now all accessors are available through `EWSClient`.
98
+
99
+ ### Folder Accessors
100
+
101
+ #### Listing Folders
102
+ ```ruby
103
+ # Find all folders under :msgfolderroot
104
+ folders = cli.folders
105
+
106
+ # Find all folders under Inbox
107
+ inbox_folders = cli.folders root: :inbox
108
+
109
+ # Find all folders under :root and do a Deep search
110
+ all_folders = cli.folders root: :root, traversal: :deep
111
+ ```
112
+
113
+ #### Finding single folders
114
+ ```ruby
115
+ # If you know the EWS id
116
+ cli.get_folder <folder_id>
117
+ # ... or if it's a standard folder pass its symbol
118
+ cli.get_folder :index
119
+ # or by name
120
+ cli.get_folder_by_name 'test'
121
+ # by name as a subfolder under "Inbox"
122
+ cli.get_folder_by_name 'test', parent: :inbox
123
+ ```
124
+
125
+ #### Creating/Deleting a folder
126
+ ```ruby
127
+ # make a folder under :msgfolderroot
128
+ cli.make_folder 'myfolder'
129
+
130
+ # make a folder under Inbox
131
+ my_folder = cli.make_folder 'My Stuff', parent: :inbox
132
+
133
+ # make a new Tasks folder
134
+ tasks = cli.make_folder 'New Tasks', type: :tasks
135
+
136
+ # delete a folder
137
+ my_folder.delete!
138
+ ```
139
+
140
+ ### Item Accessors
141
+
142
+ #### Finding items
143
+ ```ruby
144
+ items = inbox.items
145
+
146
+ # for today
147
+ inbox.todays_items
148
+
149
+ # since a specific date
150
+ sd = Date.iso8601 '2013-01-01'
151
+ inbox.items_since sd
152
+
153
+ # between 2 dates
154
+ sd = Date.iso8601 '2013-01-01'
155
+ ed = Date.iso8601 '2013-02-01'
156
+ inbox.items_between sd, ed
157
+ ```
158
+ ### Free/Busy Calendar Accessors
159
+
160
+ ```ruby
161
+ # Find when a user is busy
162
+ require 'time'
163
+ start_time = DateTime.parse("2013-02-19").iso8601
164
+ end_time = DateTime.parse("2013-02-20").iso8601
165
+ user_free_busy = cli.get_user_availability(['joe.user@exchange.site.com'],
166
+ start_time: start_time,
167
+ end_time: end_time,
168
+ requested_view: :free_busy)
169
+ busy_times = user_free_busy.calendar_event_array
170
+
171
+ # Parse events from the calendar event array for start/end times and type
172
+ busy_times.each { | event |
173
+ cli.event_busy_type(event)
174
+ cli.event_start_time(event)
175
+ cli.event_end_time(event)
176
+ }
177
+
178
+ # Find the user's working hours
179
+ user_free_busy.working_hours
180
+ ```
181
+
182
+ ### Mailbox Accessors
183
+ - No examples yet
184
+
185
+ ### Message Accessors
186
+ ```ruby
187
+ cli.send_message subject: "Test", body: "Test", to_recipients: ['test@example.com']
188
+
189
+ # or
190
+ cli.send_message do |m|
191
+ m.subject = "Test"
192
+ m.body = "Test"
193
+ m.to_recipients << 'test@example.com'
194
+ m.to_recipients << 'test2@example.com'
195
+ end
196
+
197
+ # set :draft => true or use cli.draft_message to only create a draft and not send.
198
+ ```
199
+
200
+ ## Thanks go out to...
201
+
202
+ * Handl.it for sponsoring a good portion of the development effort.
203
+ * https://www.handle.com/
204
+ * The National Association of REALTORS&reg; for providing a testing account
205
+ and much appreciated input and support.
206
+ * The Holmes Group Limited for providing Exchange 2013 test accounts.
207
+
208
+ ## DISCLAIMER:
209
+ If you see something that could be done better or would like
210
+ to help out in the development of this code please feel free to clone the
211
+ 'git' repository and send me patches:
212
+ `git clone git://github.com/zenchild/Viewpoint.git`
213
+ or add an issue on GitHub:
214
+ http://github.com/zenchild/Viewpoint/issues
215
+
216
+ Cheers!
@@ -0,0 +1,34 @@
1
+ =begin
2
+ This file is a cotribution to Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
+
4
+ Copyright © 2013 Mark McCahill <mark.mccahill@duke.edu>
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::CalendarAccessors
20
+ include Viewpoint::EWS
21
+
22
+ def event_busy_type( the_event )
23
+ the_event[:calendar_event][:elems][2][:busy_type][:text]
24
+ end
25
+
26
+ def event_start_time( the_event )
27
+ the_event[:calendar_event][:elems][0][:start_time][:text]
28
+ end
29
+
30
+ def event_end_time( the_event )
31
+ the_event[:calendar_event][:elems][1][:end_time][:text]
32
+ end
33
+
34
+ end # Viewpoint::EWS::CalendarAccessors
@@ -0,0 +1,130 @@
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
+ require 'httpclient'
19
+
20
+ class Viewpoint::EWS::Connection
21
+ include Viewpoint::EWS::ConnectionHelper
22
+ include Viewpoint::EWS
23
+
24
+ attr_reader :endpoint
25
+ # @param [String] endpoint the URL of the web service.
26
+ # @example https://<site>/ews/Exchange.asmx
27
+ # @param [Hash] opts Misc config options (mostly for developement)
28
+ # @option opts [Fixnum] :ssl_verify_mode
29
+ # @option opts [Fixnum] :receive_timeout override the default receive timeout
30
+ # seconds
31
+ # @option opts [Array] :trust_ca an array of hashed dir paths or a file
32
+ def initialize(endpoint, opts = {})
33
+ @log = Logging.logger[self.class.name.to_s.to_sym]
34
+ @httpcli = HTTPClient.new
35
+ if opts[:trust_ca]
36
+ @httpcli.ssl_config.clear_cert_store
37
+ opts[:trust_ca].each do |ca|
38
+ @httpcli.ssl_config.add_trust_ca ca
39
+ end
40
+ end
41
+ @httpcli.ssl_config.verify_mode = opts[:ssl_verify_mode] if opts[:ssl_verify_mode]
42
+ @httpcli.ssl_config.ssl_version = opts[:ssl_version] if opts[:ssl_version]
43
+ # Up the keep-alive so we don't have to do the NTLM dance as often.
44
+ @httpcli.keep_alive_timeout = 60
45
+ @httpcli.receive_timeout = opts[:receive_timeout] if opts[:receive_timeout]
46
+ @endpoint = endpoint
47
+ end
48
+
49
+ def set_auth(user,pass)
50
+ @httpcli.set_auth(@endpoint.to_s, user, pass)
51
+ end
52
+
53
+ # Authenticate to the web service. You don't have to do this because
54
+ # authentication will happen on the first request if you don't do it here.
55
+ # @return [Boolean] true if authentication is successful, false otherwise
56
+ def authenticate
57
+ self.get && true
58
+ end
59
+
60
+ # Every Connection class must have the dispatch method. It is what sends the
61
+ # SOAP request to the server and calls the parser method on the EWS instance.
62
+ #
63
+ # This was originally in the ExchangeWebService class but it was added here
64
+ # to make the processing chain easier to modify. For example, it allows the
65
+ # reactor pattern to handle the request with a callback.
66
+ # @param ews [Viewpoint::EWS::SOAP::ExchangeWebService] used to call
67
+ # #parse_soap_response
68
+ # @param soapmsg [String]
69
+ # @param opts [Hash] misc opts for handling the Response
70
+ def dispatch(ews, soapmsg, opts)
71
+ respmsg = post(soapmsg)
72
+ @log.debug <<-EOF.gsub(/^ {6}/, '')
73
+ Received SOAP Response:
74
+ ----------------
75
+ #{Nokogiri::XML(respmsg).to_xml}
76
+ ----------------
77
+ EOF
78
+ opts[:raw_response] ? respmsg : ews.parse_soap_response(respmsg, opts)
79
+ end
80
+
81
+ # Send a GET to the web service
82
+ # @return [String] If the request is successful (200) it returns the body of
83
+ # the response.
84
+ def get
85
+ check_response( @httpcli.get(@endpoint) )
86
+ end
87
+
88
+ # Send a POST to the web service
89
+ # @return [String] If the request is successful (200) it returns the body of
90
+ # the response.
91
+ def post(xmldoc)
92
+ headers = {'Content-Type' => 'text/xml'}
93
+ check_response( @httpcli.post(@endpoint, xmldoc, headers) )
94
+ end
95
+
96
+
97
+ private
98
+
99
+ def check_response(resp)
100
+ case resp.status
101
+ when 200
102
+ resp.body
103
+ when 302
104
+ # @todo redirect
105
+ raise Errors::UnhandledResponseError.new("Unhandled HTTP Redirect", resp)
106
+ when 401
107
+ raise Errors::UnauthorizedResponseError.new("Unauthorized request", resp)
108
+ when 500
109
+ if resp.headers['Content-Type'] =~ /xml/
110
+ err_string, err_code = parse_soap_error(resp.body)
111
+ raise Errors::SoapResponseError.new("SOAP Error: Message: #{err_string} Code: #{err_code}", resp, err_code, err_string)
112
+ else
113
+ raise Errors::ServerError.new("Internal Server Error. Message: #{resp.body}", resp)
114
+ end
115
+ else
116
+ raise Errors::ResponseError.new("HTTP Error Code: #{resp.status}, Msg: #{resp.body}", resp)
117
+ end
118
+ end
119
+
120
+ # @param [String] xml to parse the errors from.
121
+ def parse_soap_error(xml)
122
+ ndoc = Nokogiri::XML(xml)
123
+ ns = ndoc.collect_namespaces
124
+ err_string = ndoc.xpath("//faultstring",ns).text
125
+ err_code = ndoc.xpath("//faultcode",ns).text
126
+ @log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
127
+ [err_string, err_code]
128
+ end
129
+
130
+ end
@@ -0,0 +1,35 @@
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::ConnectionHelper
20
+
21
+ def init_logging!
22
+ @log = Logging.logger[self.class.name.to_s.to_sym]
23
+ end
24
+
25
+ # @param [String] xml to parse the errors from.
26
+ def parse_soap_error(xml)
27
+ ndoc = Nokogiri::XML(xml)
28
+ ns = ndoc.collect_namespaces
29
+ err_string = ndoc.xpath("//faultstring",ns).text
30
+ err_code = ndoc.xpath("//faultcode",ns).text
31
+ @log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
32
+ [err_string, err_code]
33
+ end
34
+
35
+ end
@@ -0,0 +1,56 @@
1
+ =begin
2
+ This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
3
+
4
+ Copyright © 2013 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::ConvertAccessors
19
+ include Viewpoint::EWS
20
+
21
+ # This is a class method that converts identifiers between formats.
22
+ # @param [String] id The id to be converted
23
+ # @param [Hash] opts Misc options to control request
24
+ # @option opts [Symbol] :format :ews_legacy_id/:ews_id/:entry_id/:hex_entry_id/:store_id/:owa_id
25
+ # @option opts [Symbol] :destination_format :ews_legacy_id/:ews_id/:entry_id/:hex_entry_id/:store_id/:owa_id
26
+ # @option opts [String] :mailbox Mailbox, if required
27
+ # @return [EwsResponse] Returns an EwsResponse containing the convert response message
28
+
29
+ def convert_id(id, opts = {})
30
+ args = convert_id_args(id, opts.clone)
31
+ obj = OpenStruct.new(opts: args)
32
+ yield obj if block_given?
33
+ resp = ews.convert_id(args)
34
+ convert_id_parser(resp)
35
+ end
36
+
37
+ private
38
+
39
+ def convert_id_args(id, opts)
40
+ { id: id }.merge opts
41
+ end
42
+
43
+ def convert_id_parser(resp)
44
+ rm = resp.response_messages[0]
45
+
46
+ if(rm && rm.status == 'Success')
47
+ # @todo create custom response class
48
+ rm
49
+ else
50
+ code = rm.respond_to?(:code) ? rm.code : "Unknown"
51
+ text = rm.respond_to?(:message_text) ? rm.message_text : "Unknown"
52
+ raise EwsError, "Could not convert id. #{rm.code}: #{rm.message_text}"
53
+ end
54
+ end
55
+
56
+ end # Viewpoint::EWS::ItemAccessors