viewpoint 1.1.1 → 2.0.0

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -8
  3. data/lib/ews/calendar_accessors.rb +37 -33
  4. data/lib/ews/connection.rb +151 -124
  5. data/lib/ews/connection_helper.rb +36 -33
  6. data/lib/ews/convert_accessors.rb +58 -54
  7. data/lib/ews/errors.rb +59 -53
  8. data/lib/ews/ews_client.rb +92 -79
  9. data/lib/ews/exceptions/exceptions.rb +61 -61
  10. data/lib/ews/folder_accessors.rb +235 -234
  11. data/lib/ews/impersonation.rb +29 -23
  12. data/lib/ews/item_accessors.rb +215 -213
  13. data/lib/ews/mailbox_accessors.rb +82 -79
  14. data/lib/ews/meeting_accessors.rb +38 -31
  15. data/lib/ews/message_accessors.rb +83 -81
  16. data/lib/ews/push_subscription_accessors.rb +29 -27
  17. data/lib/ews/room_accessors.rb +48 -46
  18. data/lib/ews/roomlist_accessors.rb +47 -45
  19. data/lib/ews/soap/builders/ews_builder.rb +1186 -1188
  20. data/lib/ews/soap/ews_response.rb +68 -73
  21. data/lib/ews/soap/ews_soap_availability_response.rb +57 -57
  22. data/lib/ews/soap/ews_soap_free_busy_response.rb +115 -117
  23. data/lib/ews/soap/ews_soap_response.rb +99 -101
  24. data/lib/ews/soap/ews_soap_room_response.rb +45 -45
  25. data/lib/ews/soap/ews_soap_roomlist_response.rb +45 -46
  26. data/lib/ews/soap/exchange_availability.rb +54 -52
  27. data/lib/ews/soap/exchange_data_services.rb +693 -711
  28. data/lib/ews/soap/exchange_notification.rb +123 -128
  29. data/lib/ews/soap/exchange_synchronization.rb +82 -82
  30. data/lib/ews/soap/exchange_time_zones.rb +41 -44
  31. data/lib/ews/soap/exchange_user_configuration.rb +30 -27
  32. data/lib/ews/soap/exchange_web_service.rb +237 -233
  33. data/lib/ews/soap/parsers/ews_parser.rb +46 -42
  34. data/lib/ews/soap/parsers/ews_sax_document.rb +63 -58
  35. data/lib/ews/soap/response_message.rb +69 -68
  36. data/lib/ews/soap/responses/create_attachment_response_message.rb +45 -45
  37. data/lib/ews/soap/responses/create_item_response_message.rb +26 -25
  38. data/lib/ews/soap/responses/find_item_response_message.rb +76 -78
  39. data/lib/ews/soap/responses/get_events_response_message.rb +52 -51
  40. data/lib/ews/soap/responses/send_notification_response_message.rb +53 -51
  41. data/lib/ews/soap/responses/subscribe_response_message.rb +37 -34
  42. data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +38 -35
  43. data/lib/ews/soap/responses/sync_folder_items_response_message.rb +38 -35
  44. data/lib/ews/soap.rb +27 -26
  45. data/lib/ews/templates/calendar_item.rb +64 -60
  46. data/lib/ews/templates/forward_item.rb +19 -17
  47. data/lib/ews/templates/message.rb +61 -67
  48. data/lib/ews/templates/reply_to_item.rb +20 -18
  49. data/lib/ews/templates/task.rb +55 -55
  50. data/lib/ews/types/attachment.rb +75 -74
  51. data/lib/ews/types/attendee.rb +27 -25
  52. data/lib/ews/types/calendar_folder.rb +60 -44
  53. data/lib/ews/types/calendar_item.rb +134 -116
  54. data/lib/ews/types/contact.rb +11 -5
  55. data/lib/ews/types/contacts_folder.rb +10 -5
  56. data/lib/ews/types/copied_event.rb +47 -48
  57. data/lib/ews/types/created_event.rb +22 -20
  58. data/lib/ews/types/deleted_event.rb +22 -20
  59. data/lib/ews/types/distribution_list.rb +11 -5
  60. data/lib/ews/types/event.rb +60 -59
  61. data/lib/ews/types/export_items_response_message.rb +54 -50
  62. data/lib/ews/types/file_attachment.rb +63 -61
  63. data/lib/ews/types/folder.rb +58 -57
  64. data/lib/ews/types/free_busy_changed_event.rb +22 -20
  65. data/lib/ews/types/generic_folder.rb +348 -372
  66. data/lib/ews/types/item.rb +401 -397
  67. data/lib/ews/types/item_attachment.rb +87 -80
  68. data/lib/ews/types/item_field_uri_map.rb +201 -200
  69. data/lib/ews/types/mailbox_user.rb +146 -154
  70. data/lib/ews/types/meeting_cancellation.rb +11 -5
  71. data/lib/ews/types/meeting_message.rb +11 -5
  72. data/lib/ews/types/meeting_request.rb +11 -5
  73. data/lib/ews/types/meeting_response.rb +11 -5
  74. data/lib/ews/types/message.rb +11 -5
  75. data/lib/ews/types/modified_event.rb +43 -45
  76. data/lib/ews/types/moved_event.rb +47 -48
  77. data/lib/ews/types/new_mail_event.rb +22 -20
  78. data/lib/ews/types/out_of_office.rb +145 -144
  79. data/lib/ews/types/post_item.rb +11 -5
  80. data/lib/ews/types/search_folder.rb +10 -5
  81. data/lib/ews/types/status_event.rb +37 -36
  82. data/lib/ews/types/task.rb +39 -33
  83. data/lib/ews/types/tasks_folder.rb +32 -22
  84. data/lib/ews/types.rb +134 -139
  85. data/lib/viewpoint/logging/config.rb +19 -19
  86. data/lib/viewpoint/logging.rb +23 -17
  87. data/lib/viewpoint/string_utils.rb +31 -32
  88. data/lib/viewpoint.rb +18 -18
  89. metadata +82 -11
  90. data/Changelog.txt +0 -1004
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a68b06955c37c1754b683df062fac54eed03b683a9c7a165afac56b99d6ce246
4
- data.tar.gz: f634063cda62c76cb0c8efc073e9f3ac7af677990212d57f8352fa074402b9af
3
+ metadata.gz: 1bd4e910abc2cfbe08db2972b5903dfb283c4e9a8d98bd804b93f094709ae7b2
4
+ data.tar.gz: d6cd479428246450510e96931a72fb84eb50d148cbd33d95fd0278db24931d71
5
5
  SHA512:
6
- metadata.gz: b8dc96f1b982e96f0b09a421d37f2b93a60e5b89f0d758937c1ce8614521d3b858e7aff40a9b0eefb20be56809d387a34a8431c214df09ab2636aeb6b50db9d1
7
- data.tar.gz: 9913637dc1c11ce0559cd142564724eec902bfb6463b35d887479f28b5db4f79ea0d6e5f3ca62812e1bfdf5ca074a2bfb5507433f347677b06252b9f20538a33
6
+ metadata.gz: 1f2a594e47277ccf9b74756ce63f6f9c25c43569db772109b0c7a5616719018b83f5d1de774f3c1afbe8253df8541275b737b69ae25c3e43e431fa525aa05849
7
+ data.tar.gz: c2588831f25737a7e57968295c3d75f64c50b7780b83f6f93826a0c03b98fec2d13af93e95504ccbe63b674fa74b19563d9218231a4488af0964d7b337ce4863
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
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)
2
+ [![CI](https://github.com/WinRb/Viewpoint/actions/workflows/ci.yml/badge.svg)](https://github.com/WinRb/Viewpoint/actions/workflows/ci.yml)
3
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)
4
+ [![License](https://img.shields.io/github/license/WinRb/Viewpoint.svg)](https://github.com/WinRb/Viewpoint/blob/main/LICENSE)
5
+ [![Wiki](https://img.shields.io/badge/docs-wiki-lightgrey.svg)](https://github.com/WinRb/Viewpoint/wiki)
6
+ [![Documentation](https://img.shields.io/badge/docs-rdoc-lightgrey.svg)](https://www.rubydoc.info/github/WinRb/Viewpoint/frames)
7
7
 
8
8
  Viewpoint for EWS provides a thin Ruby layer on top of Microsoft Exchange
9
9
  Web Services(EWS). It also includes a bunch of model classes that add an
@@ -57,7 +57,7 @@ out of the picture this is no longer required. Go crazy ;)
57
57
 
58
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
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).
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](https://www.rubydoc.info/github/WinRb/Viewpoint/frames).
61
61
 
62
62
  Note the `cli` variable in the setup code directly below. I will use that variable throughout without the setup code.
63
63
 
@@ -70,7 +70,12 @@ endpoint = 'https://example.com/ews/Exchange.asmx'
70
70
  user = 'username'
71
71
  pass = 'password'
72
72
 
73
- cli = Viewpoint::EWSClient.new endpoint, user, pass
73
+ # Basic authentication
74
+ cli = Viewpoint::EWSClient.new({ endpoint: endpoint, type: 'basic', user: user, password: pass })
75
+
76
+ # OAuth bearer-token authentication
77
+ token = 'your-oauth-bearer-token'
78
+ cli = Viewpoint::EWSClient.new({ endpoint: endpoint, type: 'oauth', token: token })
74
79
  ```
75
80
 
76
81
  There are also various options you can pass to EWSClient.
@@ -196,8 +201,8 @@ end
196
201
  If you see something that could be done better or would like
197
202
  to help out in the development of this code please feel free to clone the
198
203
  'git' repository and send me patches:
199
- `git clone git://github.com/zenchild/Viewpoint.git`
204
+ `git clone https://github.com/WinRb/Viewpoint.git`
200
205
  or add an issue on GitHub:
201
- http://github.com/zenchild/Viewpoint/issues
206
+ https://github.com/WinRb/Viewpoint/issues
202
207
 
203
208
  Cheers!
@@ -1,34 +1,38 @@
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]
1
+ # frozen_string_literal: true
2
+
3
+ # This file is a cotribution to Viewpoint; the Ruby library for Microsoft Exchange Web Services.
4
+ #
5
+ # Copyright © 2013 Mark McCahill <mark.mccahill@duke.edu>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Viewpoint
20
+ module EWS
21
+ # Calendar operations mixed into the EWS client.
22
+ module CalendarAccessors
23
+ include Viewpoint::EWS
24
+
25
+ def event_busy_type(the_event)
26
+ the_event[:calendar_event][:elems][2][:busy_type][:text]
27
+ end
28
+
29
+ def event_start_time(the_event)
30
+ the_event[:calendar_event][:elems][0][:start_time][:text]
31
+ end
32
+
33
+ def event_end_time(the_event)
34
+ the_event[:calendar_event][:elems][1][:end_time][:text]
35
+ end
36
+ end
24
37
  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
38
+ end
@@ -1,140 +1,167 @@
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
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
4
+ #
5
+ # Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
18
  require 'httpclient'
19
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
20
+ module Viewpoint
21
+ module EWS
22
+ # HTTP connection to the Exchange server.
23
+ class Connection
24
+ include Viewpoint::EWS::ConnectionHelper
25
+ include Viewpoint::EWS
26
+
27
+ attr_reader :endpoint
28
+
29
+ SUPPORTED_HTTPCLIENT_OPTS = %i[agent_name default_header].freeze
30
+
31
+ # @param [Hash] auth authentication details
32
+ # @option auth [String] :endpoint the URL of the web service.
33
+ # @example https://<site>/ews/Exchange.asmx
34
+ # @option auth [String] :type the authentication type: 'basic' or 'oauth'
35
+ # @option auth [String] :user the user to authenticate as (basic auth)
36
+ # @option auth [String] :password the user password (basic auth)
37
+ # @option auth [String] :token the OAuth bearer token (oauth auth)
38
+ # @param [Hash] opts Misc config options (mostly for development)
39
+ # @option opts [Fixnum] :ssl_verify_mode
40
+ # @option opts [Fixnum] :receive_timeout override the default receive timeout
41
+ # seconds
42
+ # @option opts [Fixnum] :connect_timeout override the default connect timeout
43
+ # seconds
44
+ # @option opts [OpenSSL::X509::Store] :cert_store a custom cert store
45
+ # @option opts [Array] :trust_ca an array of hashed dir paths or a file
46
+ # @option opts [String] :user_agent the http user agent to use in all requests
47
+ def initialize(auth, opts = {})
48
+ @log = Viewpoint::EWS.root_logger
49
+
50
+ @auth_type = auth[:type]
51
+ @auth_token = auth[:token]
52
+
53
+ httpclient_opts = opts.slice(*SUPPORTED_HTTPCLIENT_OPTS)
54
+ @httpcli = HTTPClient.new(**httpclient_opts)
55
+
56
+ if opts[:cert_store].is_a?(OpenSSL::X509::Store)
57
+ @log.debug 'Applying custom cert_store provided via opts[:cert_store]'
58
+ # Assign the provided store directly
59
+ @httpcli.ssl_config.cert_store = opts[:cert_store]
60
+
61
+ @log.debug 'Skipping original :trust_ca handling due to provided :cert_store.'
62
+ elsif opts[:trust_ca]
63
+ @httpcli.ssl_config.clear_cert_store
64
+ opts[:trust_ca].each do |ca|
65
+ @httpcli.ssl_config.add_trust_ca ca
66
+ end
67
+ end
68
+
69
+ @httpcli.ssl_config.verify_mode = opts[:ssl_verify_mode] if opts[:ssl_verify_mode]
70
+ @httpcli.ssl_config.ssl_version = opts[:ssl_version] if opts[:ssl_version]
71
+ # Up the keep-alive so we don't have to do the NTLM dance as often.
72
+ @httpcli.keep_alive_timeout = 60
73
+ @httpcli.receive_timeout = opts[:receive_timeout] if opts[:receive_timeout]
74
+ @httpcli.connect_timeout = opts[:connect_timeout] if opts[:connect_timeout]
75
+ @endpoint = auth[:endpoint]
76
+ end
42
77
 
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
78
+ def set_auth(user, pass)
79
+ @httpcli.set_auth(@endpoint.to_s, user, pass)
47
80
  end
48
- end
49
81
 
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
82
+ # Authenticate to the web service. You don't have to do this because
83
+ # authentication will happen on the first request if you don't do it here.
84
+ # @return [Boolean] true if authentication is successful, false otherwise
85
+ def authenticate
86
+ get && true
87
+ end
58
88
 
59
- def set_auth(user,pass)
60
- @httpcli.set_auth(@endpoint.to_s, user, pass)
61
- end
89
+ # Every Connection class must have the dispatch method. It is what sends the
90
+ # SOAP request to the server and calls the parser method on the EWS instance.
91
+ #
92
+ # This was originally in the ExchangeWebService class but it was added here
93
+ # to make the processing chain easier to modify. For example, it allows the
94
+ # reactor pattern to handle the request with a callback.
95
+ # @param ews [Viewpoint::EWS::SOAP::ExchangeWebService] used to call
96
+ # #parse_soap_response
97
+ # @param soapmsg [String]
98
+ # @param opts [Hash] misc opts for handling the Response
99
+ def dispatch(ews, soapmsg, opts)
100
+ respmsg = post(soapmsg)
101
+ @log.debug <<~LOG
102
+ Received SOAP Response:
103
+ ----------------
104
+ #{Nokogiri::XML(respmsg).to_xml}
105
+ ----------------
106
+ LOG
107
+ opts[:raw_response] ? respmsg : ews.parse_soap_response(respmsg, opts)
108
+ end
62
109
 
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
110
+ # Send a GET to the web service
111
+ # @return [String] If the request is successful (200) it returns the body of
112
+ # the response.
113
+ def get
114
+ check_response(@httpcli.get(@endpoint))
115
+ end
69
116
 
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
117
+ # Send a POST to the web service
118
+ # @return [String] If the request is successful (200) it returns the body of
119
+ # the response.
120
+ def post(xmldoc)
121
+ headers = { 'Content-Type' => 'text/xml' }
122
+ headers['Authorization'] = "Bearer #{@auth_token}" if oauth_token?
123
+ check_response(@httpcli.post(@endpoint, xmldoc, headers))
124
+ end
90
125
 
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
126
+ private
97
127
 
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
128
+ # True when a non-empty OAuth bearer token was supplied.
129
+ def oauth_token?
130
+ @auth_type == 'oauth' && @auth_token.is_a?(String) && !@auth_token.empty?
131
+ end
105
132
 
133
+ def check_response(resp)
134
+ case resp.status
135
+ when 200
136
+ resp.body
137
+ when 302
138
+ # @todo redirect
139
+ raise Errors::UnhandledResponseError.new('Unhandled HTTP Redirect', resp)
140
+ when 401
141
+ raise Errors::UnauthorizedResponseError.new('Unauthorized request', resp)
142
+ when 500
143
+ unless resp.headers['Content-Type'] =~ /xml/
144
+ raise Errors::ServerError.new("Internal Server Error. Message: #{resp.body}", resp)
145
+ end
146
+
147
+ err_string, err_code = parse_soap_error(resp.body)
148
+ raise Errors::SoapResponseError.new("SOAP Error: Message: #{err_string} Code: #{err_code}", resp, err_code,
149
+ err_string)
150
+
151
+ else
152
+ raise Errors::ResponseError.new("HTTP Error Code: #{resp.status}, Msg: #{resp.body}", resp)
153
+ end
154
+ end
106
155
 
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)
156
+ # @param [String] xml to parse the errors from.
157
+ def parse_soap_error(xml)
158
+ ndoc = Nokogiri::XML(xml)
159
+ ns = ndoc.collect_namespaces
160
+ err_string = ndoc.xpath('//faultstring', ns).text
161
+ err_code = ndoc.xpath('//faultcode', ns).text
162
+ @log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
163
+ [err_string, err_code]
124
164
  end
125
- else
126
- raise Errors::ResponseError.new("HTTP Error Code: #{resp.status}, Msg: #{resp.body}", resp)
127
165
  end
128
166
  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
167
  end
@@ -1,35 +1,38 @@
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]
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
4
+ #
5
+ # Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Viewpoint
20
+ module EWS
21
+ # Helpers for building authenticated HTTP connections.
22
+ module ConnectionHelper
23
+ def init_logging!
24
+ @log = Viewpoint::EWS.root_logger
25
+ end
26
+
27
+ # @param [String] xml to parse the errors from.
28
+ def parse_soap_error(xml)
29
+ ndoc = Nokogiri::XML(xml)
30
+ ns = ndoc.collect_namespaces
31
+ err_string = ndoc.xpath('//faultstring', ns).text
32
+ err_code = ndoc.xpath('//faultcode', ns).text
33
+ @log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
34
+ [err_string, err_code]
35
+ end
36
+ end
33
37
  end
34
-
35
38
  end
@@ -1,56 +1,60 @@
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}"
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
4
+ #
5
+ # Copyright © 2013 Dan Wanek <dan.wanek@gmail.com>
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ module Viewpoint
19
+ module EWS
20
+ # Convert operations mixed into the EWS client.
21
+ module ConvertAccessors
22
+ include Viewpoint::EWS
23
+
24
+ # This is a class method that converts identifiers between formats.
25
+ # @param [String] id The id to be converted
26
+ # @param [Hash] opts Misc options to control request
27
+ # @option opts [Symbol] :format :ews_legacy_id/:ews_id/:entry_id/:hex_entry_id/:store_id/:owa_id
28
+ # @option opts [Symbol] :destination_format :ews_legacy_id/:ews_id/:entry_id/:hex_entry_id/:store_id/:owa_id
29
+ # @option opts [String] :mailbox Mailbox, if required
30
+ # @return [EwsResponse] Returns an EwsResponse containing the convert response message
31
+
32
+ def convert_id(id, opts = {})
33
+ args = convert_id_args(id, opts.clone)
34
+ obj = OpenStruct.new(opts: args)
35
+ yield obj if block_given?
36
+ resp = ews.convert_id(args)
37
+ convert_id_parser(resp)
38
+ end
39
+
40
+ private
41
+
42
+ def convert_id_args(id, opts)
43
+ { id: id }.merge opts
44
+ end
45
+
46
+ def convert_id_parser(resp)
47
+ rm = resp.response_messages[0]
48
+
49
+ if rm && rm.status == 'Success'
50
+ # @todo create custom response class
51
+ rm
52
+ else
53
+ rm.respond_to?(:code) ? rm.code : 'Unknown'
54
+ rm.respond_to?(:message_text) ? rm.message_text : 'Unknown'
55
+ raise EwsError, "Could not convert id. #{rm.code}: #{rm.message_text}"
56
+ end
57
+ end
53
58
  end
54
59
  end
55
-
56
- end # Viewpoint::EWS::ItemAccessors
60
+ end