viewpoint 0.1.26 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +203 -0
  3. data/lib/ews/calendar_accessors.rb +34 -0
  4. data/lib/ews/connection.rb +140 -0
  5. data/lib/ews/connection_helper.rb +35 -0
  6. data/lib/ews/convert_accessors.rb +56 -0
  7. data/lib/{exceptions/exceptions.rb → ews/errors.rb} +29 -19
  8. data/lib/ews/ews_client.rb +105 -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 +242 -0
  13. data/lib/ews/mailbox_accessors.rb +92 -0
  14. data/lib/ews/meeting_accessors.rb +39 -0
  15. data/lib/ews/message_accessors.rb +93 -0
  16. data/lib/ews/push_subscription_accessors.rb +33 -0
  17. data/lib/ews/room_accessors.rb +48 -0
  18. data/lib/ews/roomlist_accessors.rb +47 -0
  19. data/lib/ews/soap.rb +64 -0
  20. data/lib/ews/soap/builders/ews_builder.rb +1384 -0
  21. data/lib/ews/soap/ews_response.rb +84 -0
  22. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  23. data/lib/ews/soap/ews_soap_free_busy_response.rb +119 -0
  24. data/lib/ews/soap/ews_soap_response.rb +103 -0
  25. data/lib/ews/soap/ews_soap_room_response.rb +53 -0
  26. data/lib/ews/soap/ews_soap_roomlist_response.rb +54 -0
  27. data/lib/ews/soap/exchange_availability.rb +61 -0
  28. data/lib/ews/soap/exchange_data_services.rb +780 -0
  29. data/lib/ews/soap/exchange_notification.rb +146 -0
  30. data/lib/ews/soap/exchange_synchronization.rb +93 -0
  31. data/lib/ews/soap/exchange_time_zones.rb +56 -0
  32. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  33. data/lib/ews/soap/exchange_web_service.rb +264 -0
  34. data/lib/{model/item_attachment.rb → ews/soap/parsers/ews_parser.rb} +24 -14
  35. data/lib/ews/soap/parsers/ews_sax_document.rb +70 -0
  36. data/lib/ews/soap/response_message.rb +80 -0
  37. data/lib/ews/soap/responses/create_attachment_response_message.rb +47 -0
  38. data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
  39. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  40. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  41. data/lib/ews/soap/responses/send_notification_response_message.rb +59 -0
  42. data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
  43. data/lib/{model/attendee.rb → ews/soap/responses/sync_folder_hierarchy_response_message.rb} +14 -15
  44. data/lib/ews/soap/responses/sync_folder_items_response_message.rb +36 -0
  45. data/lib/ews/templates/calendar_item.rb +79 -0
  46. data/lib/ews/templates/forward_item.rb +24 -0
  47. data/lib/ews/templates/message.rb +85 -0
  48. data/lib/ews/templates/reply_to_item.rb +25 -0
  49. data/lib/ews/templates/task.rb +74 -0
  50. data/lib/ews/types.rb +194 -0
  51. data/lib/ews/types/attachment.rb +77 -0
  52. data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
  53. data/lib/ews/types/calendar_folder.rb +50 -0
  54. data/lib/ews/types/calendar_item.rb +130 -0
  55. data/lib/ews/types/contact.rb +7 -0
  56. data/lib/ews/types/contacts_folder.rb +8 -0
  57. data/lib/ews/types/copied_event.rb +51 -0
  58. data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
  59. data/lib/ews/types/deleted_event.rb +24 -0
  60. data/lib/ews/types/distribution_list.rb +7 -0
  61. data/lib/ews/types/event.rb +62 -0
  62. data/lib/ews/types/export_items_response_message.rb +52 -0
  63. data/lib/ews/types/file_attachment.rb +65 -0
  64. data/lib/ews/types/folder.rb +60 -0
  65. data/lib/ews/types/free_busy_changed_event.rb +24 -0
  66. data/lib/ews/types/generic_folder.rb +418 -0
  67. data/lib/ews/types/item.rb +447 -0
  68. data/lib/ews/types/item_attachment.rb +84 -0
  69. data/lib/{model → ews/types}/item_field_uri_map.rb +2 -18
  70. data/lib/ews/types/mailbox_user.rb +156 -0
  71. data/lib/ews/types/meeting_cancellation.rb +7 -0
  72. data/lib/ews/types/meeting_message.rb +7 -0
  73. data/lib/ews/types/meeting_request.rb +7 -0
  74. data/lib/ews/types/meeting_response.rb +7 -0
  75. data/lib/ews/types/message.rb +7 -0
  76. data/lib/ews/types/modified_event.rb +48 -0
  77. data/lib/{extensions/string.rb → ews/types/moved_event.rb} +31 -15
  78. data/lib/ews/types/new_mail_event.rb +24 -0
  79. data/lib/ews/types/out_of_office.rb +147 -0
  80. data/lib/ews/types/post_item.rb +7 -0
  81. data/lib/ews/types/search_folder.rb +8 -0
  82. data/lib/ews/types/status_event.rb +39 -0
  83. data/lib/ews/types/task.rb +41 -0
  84. data/lib/ews/types/tasks_folder.rb +27 -0
  85. data/lib/viewpoint.rb +85 -108
  86. data/lib/{model/distribution_list.rb → viewpoint/logging.rb} +6 -3
  87. data/lib/{model/meeting_response.rb → viewpoint/logging/config.rb} +3 -3
  88. data/lib/viewpoint/string_utils.rb +76 -0
  89. metadata +156 -123
  90. data/README +0 -114
  91. data/lib/model/calendar_folder.rb +0 -67
  92. data/lib/model/calendar_item.rb +0 -267
  93. data/lib/model/contact.rb +0 -238
  94. data/lib/model/contacts_folder.rb +0 -46
  95. data/lib/model/event.rb +0 -116
  96. data/lib/model/file_attachment.rb +0 -53
  97. data/lib/model/folder.rb +0 -47
  98. data/lib/model/generic_folder.rb +0 -461
  99. data/lib/model/item.rb +0 -312
  100. data/lib/model/mailbox_user.rb +0 -146
  101. data/lib/model/meeting_request.rb +0 -39
  102. data/lib/model/message.rb +0 -142
  103. data/lib/model/model.rb +0 -269
  104. data/lib/model/search_folder.rb +0 -48
  105. data/lib/model/task.rb +0 -121
  106. data/lib/model/tasks_folder.rb +0 -44
  107. data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
  108. data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
  109. data/lib/soap/handsoap/ews_service.rb +0 -790
  110. data/lib/soap/handsoap/parser.rb +0 -104
  111. data/lib/soap/handsoap/parsers/ews_parser.rb +0 -245
  112. data/lib/soap/soap_provider.rb +0 -64
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a68b06955c37c1754b683df062fac54eed03b683a9c7a165afac56b99d6ce246
4
+ data.tar.gz: f634063cda62c76cb0c8efc073e9f3ac7af677990212d57f8352fa074402b9af
5
+ SHA512:
6
+ metadata.gz: b8dc96f1b982e96f0b09a421d37f2b93a60e5b89f0d758937c1ce8614521d3b858e7aff40a9b0eefb20be56809d387a34a8431c214df09ab2636aeb6b50db9d1
7
+ data.tar.gz: 9913637dc1c11ce0559cd142564724eec902bfb6463b35d887479f28b5db4f79ea0d6e5f3ca62812e1bfdf5ca074a2bfb5507433f347677b06252b9f20538a33
data/README.md ADDED
@@ -0,0 +1,203 @@
1
+ # Viewpoint for Exchange Web Services
2
+ [![Build Status](https://img.shields.io/travis/WinRb/Viewpoint.svg?branch=master)](https://travis-ci.org/WinRb/Viewpoint)
3
+ [![Gem Version](https://img.shields.io/gem/v/viewpoint.svg)](https://rubygems.org/gems/viewpoint)
4
+ [![License](https://img.shields.io/github/license/WinRb/Viewpoint.svg)](https://github.com/WinRb/Viewpoint/blob/master/LICENSE)
5
+ [![Wiki](https://img.shields.io/badge/docs-wiki-lightgrey.svg)](http://github.com/WinRb/Viewpoint/wiki)
6
+ [![Documentation](https://img.shields.io/badge/docs-rdoc-lightgrey.svg)](http://www.rubydoc.info/github/WinRb/Viewpoint/frames)
7
+
8
+ Viewpoint for EWS provides a thin Ruby layer on top of Microsoft Exchange
9
+ Web Services(EWS). It also includes a bunch of model classes that add an
10
+ additional layer of abstraction on top of EWS for use in implementing
11
+ programs with Viewpoint.
12
+
13
+ BLOG: http://distributed-frostbite.blogspot.com/
14
+
15
+ Add me in LinkedIn: http://www.linkedin.com/in/danwanek
16
+
17
+ Find me on irc.freenode.net in #ruby-lang (zenChild)
18
+
19
+ # Features
20
+
21
+ ## New in 1.0
22
+
23
+ * SOAP backend is now only dependant on Nokogiri. Before version 1.0 Viewpoint
24
+ went through a number of iterations in backends including SOAP4r and Handsoap.
25
+ Each of these approaches had major issues so in the end I decided it was
26
+ easiest to just build the SOAP messages with Nokogiri since I was using it as
27
+ the parser for response messages already.
28
+
29
+ * Viewpoint is no longer built on a Singleton pattern. The reason it was
30
+ previously is because of the Handsoap backend. Handsoap itself uses a
31
+ Singleton pattern for connection to the SOAP endpoint so with authentication
32
+ I was forced to implement Viewpoint as a Singleton as well. Now with Handsoap
33
+ out of the picture this is no longer required. Go crazy ;)
34
+
35
+ ## Enhanced in 1.0
36
+
37
+ * *Delegate access is supported*
38
+ 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.
39
+
40
+ > Inbox example:
41
+ ```inbox = Folder.get_folder(:inbox, opts = {act_as: "user@host.com"})```
42
+
43
+ > 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.
44
+
45
+ > Calendar example:
46
+ ```calendar = cli.get_folder(:calendar, opts = {act_as: "user@host.com"})```
47
+
48
+ > 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.
49
+
50
+
51
+ * There is also some support for manipulation of delegate access itself via
52
+ the methods `MailboxUser#add_delegate!`, `MailboxUser#update_delegate!`, and
53
+ `MailboxUser#get_delegate_info`.
54
+
55
+
56
+ # Using Viewpoint
57
+
58
+ 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.
59
+
60
+ 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).
61
+
62
+ Note the `cli` variable in the setup code directly below. I will use that variable throughout without the setup code.
63
+
64
+ ## The Setup
65
+ ```ruby
66
+ require 'viewpoint'
67
+ include Viewpoint::EWS
68
+
69
+ endpoint = 'https://example.com/ews/Exchange.asmx'
70
+ user = 'username'
71
+ pass = 'password'
72
+
73
+ cli = Viewpoint::EWSClient.new endpoint, user, pass
74
+ ```
75
+
76
+ There are also various options you can pass to EWSClient.
77
+
78
+ 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}`.
79
+
80
+ 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.
81
+
82
+ ## Accessors
83
+
84
+ 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`.
85
+
86
+ ### Folder Accessors
87
+
88
+ #### Listing Folders
89
+ ```ruby
90
+ # Find all folders under :msgfolderroot
91
+ folders = cli.folders
92
+
93
+ # Find all folders under Inbox
94
+ inbox_folders = cli.folders root: :inbox
95
+
96
+ # Find all folders under :root and do a Deep search
97
+ all_folders = cli.folders root: :root, traversal: :deep
98
+ ```
99
+
100
+ #### Finding single folders
101
+ ```ruby
102
+ # If you know the EWS id
103
+ cli.get_folder <folder_id>
104
+ # ... or if it's a standard folder pass its symbol
105
+ cli.get_folder :index
106
+ # or by name
107
+ cli.get_folder_by_name 'test'
108
+ # by name as a subfolder under "Inbox"
109
+ cli.get_folder_by_name 'test', parent: :inbox
110
+ ```
111
+
112
+ #### Creating/Deleting a folder
113
+ ```ruby
114
+ # make a folder under :msgfolderroot
115
+ cli.make_folder 'myfolder'
116
+
117
+ # make a folder under Inbox
118
+ my_folder = cli.make_folder 'My Stuff', parent: :inbox
119
+
120
+ # make a new Tasks folder
121
+ tasks = cli.make_folder 'New Tasks', type: :tasks
122
+
123
+ # delete a folder
124
+ my_folder.delete!
125
+ ```
126
+
127
+ ### Item Accessors
128
+
129
+ #### Finding items
130
+ ```ruby
131
+ items = inbox.items
132
+
133
+ # for today
134
+ inbox.todays_items
135
+
136
+ # since a specific date
137
+ sd = Date.iso8601 '2013-01-01'
138
+ inbox.items_since sd
139
+
140
+ # between 2 dates
141
+ sd = Date.iso8601 '2013-01-01'
142
+ ed = Date.iso8601 '2013-02-01'
143
+ inbox.items_between sd, ed
144
+ ```
145
+ ### Free/Busy Calendar Accessors
146
+
147
+ ```ruby
148
+ # Find when a user is busy
149
+ require 'time'
150
+ start_time = DateTime.parse("2013-02-19").iso8601
151
+ end_time = DateTime.parse("2013-02-20").iso8601
152
+ user_free_busy = cli.get_user_availability(['joe.user@exchange.site.com'],
153
+ start_time: start_time,
154
+ end_time: end_time,
155
+ requested_view: :free_busy)
156
+ busy_times = user_free_busy.calendar_event_array
157
+
158
+ # Parse events from the calendar event array for start/end times and type
159
+ busy_times.each { | event |
160
+ cli.event_busy_type(event)
161
+ cli.event_start_time(event)
162
+ cli.event_end_time(event)
163
+ }
164
+
165
+ # Find the user's working hours
166
+ user_free_busy.working_hours
167
+ ```
168
+
169
+ ### Mailbox Accessors
170
+ - No examples yet
171
+
172
+ ### Message Accessors
173
+ ```ruby
174
+ cli.send_message subject: "Test", body: "Test", to_recipients: ['test@example.com']
175
+
176
+ # or
177
+ cli.send_message do |m|
178
+ m.subject = "Test"
179
+ m.body = "Test"
180
+ m.to_recipients << 'test@example.com'
181
+ m.to_recipients << 'test2@example.com'
182
+ end
183
+
184
+ # set :draft => true or use cli.draft_message to only create a draft and not send.
185
+ ```
186
+
187
+ ## Thanks go out to...
188
+
189
+ * Handl.it for sponsoring a good portion of the development effort.
190
+ * https://www.handle.com/
191
+ * The National Association of REALTORS&reg; for providing a testing account
192
+ and much appreciated input and support.
193
+ * The Holmes Group Limited for providing Exchange 2013 test accounts.
194
+
195
+ ## DISCLAIMER:
196
+ If you see something that could be done better or would like
197
+ to help out in the development of this code please feel free to clone the
198
+ 'git' repository and send me patches:
199
+ `git clone git://github.com/zenchild/Viewpoint.git`
200
+ or add an issue on GitHub:
201
+ http://github.com/zenchild/Viewpoint/issues
202
+
203
+ 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,140 @@
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 [Fixnum] :connect_timeout override the default connect timeout
32
+ # seconds
33
+ # @option opts [Array] :trust_ca an array of hashed dir paths or a file
34
+ # @option opts [String] :user_agent the http user agent to use in all requests
35
+ def initialize(endpoint, opts = {})
36
+ @log = Logging.logger[self.class.name.to_s.to_sym]
37
+ if opts[:user_agent]
38
+ @httpcli = HTTPClient.new(agent_name: opts[:user_agent])
39
+ else
40
+ @httpcli = HTTPClient.new
41
+ end
42
+
43
+ if opts[:trust_ca]
44
+ @httpcli.ssl_config.clear_cert_store
45
+ opts[:trust_ca].each do |ca|
46
+ @httpcli.ssl_config.add_trust_ca ca
47
+ end
48
+ end
49
+
50
+ @httpcli.ssl_config.verify_mode = opts[:ssl_verify_mode] if opts[:ssl_verify_mode]
51
+ @httpcli.ssl_config.ssl_version = opts[:ssl_version] if opts[:ssl_version]
52
+ # Up the keep-alive so we don't have to do the NTLM dance as often.
53
+ @httpcli.keep_alive_timeout = 60
54
+ @httpcli.receive_timeout = opts[:receive_timeout] if opts[:receive_timeout]
55
+ @httpcli.connect_timeout = opts[:connect_timeout] if opts[:connect_timeout]
56
+ @endpoint = endpoint
57
+ end
58
+
59
+ def set_auth(user,pass)
60
+ @httpcli.set_auth(@endpoint.to_s, user, pass)
61
+ end
62
+
63
+ # Authenticate to the web service. You don't have to do this because
64
+ # authentication will happen on the first request if you don't do it here.
65
+ # @return [Boolean] true if authentication is successful, false otherwise
66
+ def authenticate
67
+ self.get && true
68
+ end
69
+
70
+ # Every Connection class must have the dispatch method. It is what sends the
71
+ # SOAP request to the server and calls the parser method on the EWS instance.
72
+ #
73
+ # This was originally in the ExchangeWebService class but it was added here
74
+ # to make the processing chain easier to modify. For example, it allows the
75
+ # reactor pattern to handle the request with a callback.
76
+ # @param ews [Viewpoint::EWS::SOAP::ExchangeWebService] used to call
77
+ # #parse_soap_response
78
+ # @param soapmsg [String]
79
+ # @param opts [Hash] misc opts for handling the Response
80
+ def dispatch(ews, soapmsg, opts)
81
+ respmsg = post(soapmsg)
82
+ @log.debug <<-EOF.gsub(/^ {6}/, '')
83
+ Received SOAP Response:
84
+ ----------------
85
+ #{Nokogiri::XML(respmsg).to_xml}
86
+ ----------------
87
+ EOF
88
+ opts[:raw_response] ? respmsg : ews.parse_soap_response(respmsg, opts)
89
+ end
90
+
91
+ # Send a GET to the web service
92
+ # @return [String] If the request is successful (200) it returns the body of
93
+ # the response.
94
+ def get
95
+ check_response( @httpcli.get(@endpoint) )
96
+ end
97
+
98
+ # Send a POST to the web service
99
+ # @return [String] If the request is successful (200) it returns the body of
100
+ # the response.
101
+ def post(xmldoc)
102
+ headers = {'Content-Type' => 'text/xml'}
103
+ check_response( @httpcli.post(@endpoint, xmldoc, headers) )
104
+ end
105
+
106
+
107
+ private
108
+
109
+ def check_response(resp)
110
+ case resp.status
111
+ when 200
112
+ resp.body
113
+ when 302
114
+ # @todo redirect
115
+ raise Errors::UnhandledResponseError.new("Unhandled HTTP Redirect", resp)
116
+ when 401
117
+ raise Errors::UnauthorizedResponseError.new("Unauthorized request", resp)
118
+ when 500
119
+ if resp.headers['Content-Type'] =~ /xml/
120
+ err_string, err_code = parse_soap_error(resp.body)
121
+ raise Errors::SoapResponseError.new("SOAP Error: Message: #{err_string} Code: #{err_code}", resp, err_code, err_string)
122
+ else
123
+ raise Errors::ServerError.new("Internal Server Error. Message: #{resp.body}", resp)
124
+ end
125
+ else
126
+ raise Errors::ResponseError.new("HTTP Error Code: #{resp.status}, Msg: #{resp.body}", resp)
127
+ end
128
+ end
129
+
130
+ # @param [String] xml to parse the errors from.
131
+ def parse_soap_error(xml)
132
+ ndoc = Nokogiri::XML(xml)
133
+ ns = ndoc.collect_namespaces
134
+ err_string = ndoc.xpath("//faultstring",ns).text
135
+ err_code = ndoc.xpath("//faultcode",ns).text
136
+ @log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
137
+ [err_string, err_code]
138
+ end
139
+
140
+ 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