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.
- data/README.md +196 -0
- data/lib/ews/calendar_accessors.rb +34 -0
- data/lib/ews/connection.rb +117 -0
- data/lib/ews/connection_helper.rb +35 -0
- data/lib/ews/ews_client.rb +71 -0
- data/lib/ews/exceptions/exceptions.rb +59 -0
- data/lib/ews/folder_accessors.rb +199 -0
- data/lib/ews/item_accessors.rb +157 -0
- data/lib/ews/mailbox_accessors.rb +87 -0
- data/lib/ews/message_accessors.rb +86 -0
- data/lib/ews/push_subscription_accessors.rb +33 -0
- data/lib/ews/soap.rb +63 -0
- data/lib/ews/soap/builders/ews_builder.rb +1011 -0
- data/lib/ews/soap/ews_response.rb +83 -0
- data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
- data/lib/ews/soap/ews_soap_free_busy_response.rb +109 -0
- data/lib/ews/soap/ews_soap_response.rb +103 -0
- data/lib/ews/soap/exchange_availability.rb +61 -0
- data/lib/ews/soap/exchange_data_services.rb +742 -0
- data/lib/ews/soap/exchange_notification.rb +146 -0
- data/lib/ews/soap/exchange_user_configuration.rb +33 -0
- data/lib/ews/soap/exchange_web_service.rb +294 -0
- data/lib/{model/attendee.rb → ews/soap/parsers/ews_parser.rb} +20 -14
- data/lib/ews/soap/parsers/ews_sax_document.rb +66 -0
- data/lib/ews/soap/response_message.rb +78 -0
- data/lib/ews/soap/responses/create_attachment_response_message.rb +46 -0
- data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
- data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
- data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
- data/lib/ews/soap/responses/send_notification_response_message.rb +58 -0
- data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
- data/lib/ews/templates/forward_item.rb +24 -0
- data/lib/ews/templates/message.rb +66 -0
- data/lib/ews/templates/reply_to_item.rb +25 -0
- data/lib/ews/types.rb +146 -0
- data/lib/ews/types/attachment.rb +77 -0
- data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
- data/lib/ews/types/calendar_folder.rb +8 -0
- data/lib/ews/types/calendar_item.rb +37 -0
- data/lib/ews/types/contact.rb +7 -0
- data/lib/ews/types/contacts_folder.rb +8 -0
- data/lib/ews/types/copied_event.rb +51 -0
- data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
- data/lib/{model/meeting_response.rb → ews/types/deleted_event.rb} +6 -6
- data/lib/ews/types/distribution_list.rb +7 -0
- data/lib/ews/types/event.rb +62 -0
- data/lib/ews/types/file_attachment.rb +65 -0
- data/lib/ews/types/folder.rb +60 -0
- data/lib/{model/distribution_list.rb → ews/types/free_busy_changed_event.rb} +6 -6
- data/lib/ews/types/generic_folder.rb +352 -0
- data/lib/ews/types/item.rb +381 -0
- data/lib/ews/types/item_attachment.rb +46 -0
- data/lib/{model → ews/types}/item_field_uri_map.rb +2 -2
- data/lib/ews/types/mailbox_user.rb +156 -0
- data/lib/ews/types/meeting_cancellation.rb +7 -0
- data/lib/ews/types/meeting_message.rb +7 -0
- data/lib/ews/types/meeting_request.rb +7 -0
- data/lib/ews/types/meeting_response.rb +7 -0
- data/lib/ews/types/message.rb +7 -0
- data/lib/ews/types/modified_event.rb +48 -0
- data/lib/{model/item_attachment.rb → ews/types/moved_event.rb} +33 -15
- data/lib/ews/types/new_mail_event.rb +24 -0
- data/lib/ews/types/out_of_office.rb +147 -0
- data/lib/ews/types/search_folder.rb +8 -0
- data/lib/ews/types/status_event.rb +39 -0
- data/lib/ews/types/task.rb +7 -0
- data/lib/ews/types/tasks_folder.rb +8 -0
- data/lib/viewpoint.rb +82 -106
- metadata +99 -67
- data/README +0 -114
- data/lib/exceptions/exceptions.rb +0 -46
- data/lib/model/calendar_folder.rb +0 -67
- data/lib/model/calendar_item.rb +0 -267
- data/lib/model/contact.rb +0 -238
- data/lib/model/contacts_folder.rb +0 -46
- data/lib/model/event.rb +0 -116
- data/lib/model/file_attachment.rb +0 -53
- data/lib/model/folder.rb +0 -47
- data/lib/model/generic_folder.rb +0 -471
- data/lib/model/item.rb +0 -313
- data/lib/model/mailbox_user.rb +0 -146
- data/lib/model/meeting_request.rb +0 -39
- data/lib/model/message.rb +0 -142
- data/lib/model/model.rb +0 -269
- data/lib/model/search_folder.rb +0 -48
- data/lib/model/task.rb +0 -121
- data/lib/model/tasks_folder.rb +0 -44
- data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
- data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
- data/lib/soap/handsoap/ews_service.rb +0 -813
- data/lib/soap/handsoap/parser.rb +0 -104
- data/lib/soap/handsoap/parsers/ews_parser.rb +0 -246
- data/lib/soap/soap_provider.rb +0 -64
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
**ATTENTION:** If you want to fix a bug in the currently released gem please use the 0.1.x-support branch. The master is the current development branch and is not ready for prime-time just yet.
|
2
|
+
|
3
|
+
# Viewpoint for Exchange Web Services 1.0
|
4
|
+
http://github.com/zenchild/Viewpoint/wiki
|
5
|
+
|
6
|
+
Viewpoint for EWS provides a thin Ruby layer on top of Microsoft Exchange
|
7
|
+
Web Services(EWS). It also includes a bunch of model classes that add an
|
8
|
+
additional layer of abstraction on top of EWS for use in implementing
|
9
|
+
programs with Viewpoint.
|
10
|
+
|
11
|
+
BLOG: http://distributed-frostbite.blogspot.com/
|
12
|
+
|
13
|
+
Add me in LinkedIn: http://www.linkedin.com/in/danwanek
|
14
|
+
|
15
|
+
Find me on irc.freenode.net in #ruby-lang (zenChild)
|
16
|
+
|
17
|
+
# Features
|
18
|
+
|
19
|
+
## New in 1.0
|
20
|
+
|
21
|
+
* SOAP backend is now only dependant on Nokogiri. Before version 1.0 Viewpoint
|
22
|
+
went through a number of iterations in backends including SOAP4r and Handsoap.
|
23
|
+
Each of these approaches had major issues so in the end I decided it was
|
24
|
+
easiest to just build the SOAP messages with Nokogiri since I was using it as
|
25
|
+
the parser for response messages already.
|
26
|
+
|
27
|
+
* Viewpoint is no longer built on a Singleton pattern. The reason it was
|
28
|
+
previously is because of the Handsoap backend. Handsoap itself uses a
|
29
|
+
Singleton pattern for connection to the SOAP endpoint so with authentication
|
30
|
+
I was forced to implement Viewpoint as a Singleton as well. Now with Handsoap
|
31
|
+
out of the picture this is no longer required. Go crazy ;)
|
32
|
+
|
33
|
+
## Enhanced in 1.0
|
34
|
+
|
35
|
+
* *Delegate access is supported*
|
36
|
+
One thing that was often asked for, but missing from the previous version
|
37
|
+
was delegate access to mailboxes and calendars. This is now supported via
|
38
|
+
the 'act_as' parameter to the GenericFolder::get_folder method. For example:
|
39
|
+
ofolder = Folder.get_folder(:inbox,'otheruser@test.com')
|
40
|
+
If your user has delegate access to the Inbox for otheruser@test.com this
|
41
|
+
operation will retrieve their inbox and allow you to manipulate it as you
|
42
|
+
would with your own Inbox.
|
43
|
+
|
44
|
+
* There is also some support for manipulation of delegate access itself via
|
45
|
+
the methods MailboxUser#add_delegate!, MailboxUser#update_delegate!, and
|
46
|
+
MailboxUser#get_delegate_info.
|
47
|
+
|
48
|
+
|
49
|
+
# Using Viewpoint
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
Note the `cli` variable in the setup code directly below. I will use that variable throughout without the setup code.
|
56
|
+
|
57
|
+
## The Setup
|
58
|
+
```ruby
|
59
|
+
require 'viewpoint'
|
60
|
+
include Viewpoint::EWS
|
61
|
+
|
62
|
+
endpoint = 'https://example.com/ews/Exchange.asmx'
|
63
|
+
user = 'username'
|
64
|
+
pass = 'password'
|
65
|
+
|
66
|
+
cli = Viewpoint::EWSClient.new endpoint, user, pass
|
67
|
+
```
|
68
|
+
|
69
|
+
There are also various options you can pass to EWSClient.
|
70
|
+
|
71
|
+
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}`.
|
72
|
+
|
73
|
+
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.
|
74
|
+
|
75
|
+
## Accessors
|
76
|
+
|
77
|
+
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.
|
78
|
+
|
79
|
+
### Folder Accessors
|
80
|
+
|
81
|
+
#### Listing Folders
|
82
|
+
```ruby
|
83
|
+
# Find all folders under :msgfolderroot
|
84
|
+
folders = cli.folders
|
85
|
+
|
86
|
+
# Find all folders under Inbox
|
87
|
+
inbox_folders = cli.folders root: :inbox
|
88
|
+
|
89
|
+
# Find all folders under :root and do a Deep search
|
90
|
+
all_folders = cli.folders root: :root, traversal: :deep
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Finding single folders
|
94
|
+
```ruby
|
95
|
+
# If you know the EWS id
|
96
|
+
cli.get_folder <folder_id>
|
97
|
+
# ... or if it's a standard folder pass its symbol
|
98
|
+
cli.get_folder :index
|
99
|
+
# or by name
|
100
|
+
cli.get_folder_by_name 'test'
|
101
|
+
# by name as a subfolder under "Inbox"
|
102
|
+
cli.get_folder_by_name 'test', parent: :inbox
|
103
|
+
```
|
104
|
+
|
105
|
+
#### Creating/Deleting a folder
|
106
|
+
```ruby
|
107
|
+
# make a folder under :msgfolderroot
|
108
|
+
cli.make_folder 'myfolder'
|
109
|
+
|
110
|
+
# make a folder under Inbox
|
111
|
+
my_folder = cli.make_folder 'My Stuff', parent: :inbox
|
112
|
+
|
113
|
+
# make a new Tasks folder
|
114
|
+
tasks = cli.make_folder 'New Tasks', type: :tasks
|
115
|
+
|
116
|
+
# delete a folder
|
117
|
+
my_folder.delete!
|
118
|
+
```
|
119
|
+
|
120
|
+
### Item Accessors
|
121
|
+
|
122
|
+
#### Finding items
|
123
|
+
```ruby
|
124
|
+
items = inbox.items
|
125
|
+
|
126
|
+
# for today
|
127
|
+
inbox.todays_items
|
128
|
+
|
129
|
+
# since a specific date
|
130
|
+
sd = Date.iso8061 '2013-01-01'
|
131
|
+
inbox.items_since sd
|
132
|
+
|
133
|
+
# between 2 dates
|
134
|
+
sd = Date.iso8061 '2013-01-01'
|
135
|
+
ed = Date.iso8061 '2013-02-01'
|
136
|
+
inbox.items_between sd, ed
|
137
|
+
```
|
138
|
+
### Free/Busy Calendar Accessors
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
# Find when a user is busy
|
142
|
+
require 'time'
|
143
|
+
start_time = DateTime.parse("2013-02-19").iso8601
|
144
|
+
end_time = DateTime.parse("2013-02-20").iso8601
|
145
|
+
user_free_busy = cli.get_user_availability(['joe.user@exchange.site.com'],
|
146
|
+
start_time: start_time,
|
147
|
+
end_time: end_time,
|
148
|
+
requested_view: :free_busy)
|
149
|
+
busy_times = user_free_busy.calendar_event_array
|
150
|
+
|
151
|
+
# Parse events from the calendar event array for start/end times and type
|
152
|
+
busy_times.each { | event |
|
153
|
+
cli.event_busy_type(event)
|
154
|
+
cli.event_start_time(event)
|
155
|
+
cli.event_end_time(event)
|
156
|
+
}
|
157
|
+
|
158
|
+
# Find the user's working hours
|
159
|
+
user_free_busy.working_hours
|
160
|
+
```
|
161
|
+
|
162
|
+
|
163
|
+
### Mailbox Accessors
|
164
|
+
### Message Accessors
|
165
|
+
```ruby
|
166
|
+
cli.send_message subject: "Test", body: "Test", to_recipients: ['test@example.com']
|
167
|
+
|
168
|
+
# or
|
169
|
+
cli.send_message do |m|
|
170
|
+
m.subject = "Test"
|
171
|
+
m.body = "Test"
|
172
|
+
m.to_recipients << 'test@example.com'
|
173
|
+
m.to_recipients << 'test2@example.com'
|
174
|
+
end
|
175
|
+
|
176
|
+
# set :draft => true or use cli.draft_message to only create a draft and not send.
|
177
|
+
```
|
178
|
+
|
179
|
+
## Thanks go out to...
|
180
|
+
|
181
|
+
* Handl.it for sponsoring a good portion of the development effort.
|
182
|
+
** https://www.handle.com/
|
183
|
+
* The National Association of REALTORS® for providing a testing account
|
184
|
+
and much appreciated input and support.
|
185
|
+
* The Holmes Group Limited for providing Exchange 2013 test accounts.
|
186
|
+
|
187
|
+
---
|
188
|
+
DISCLAIMER: If you see something that could be done better or would like
|
189
|
+
to help out in the development of this code please feel free to clone the
|
190
|
+
'git' repository and send me patches:
|
191
|
+
git clone git://github.com/zenchild/Viewpoint.git
|
192
|
+
or add an issue on GitHub:
|
193
|
+
http://github.com/zenchild/Viewpoint/issues
|
194
|
+
|
195
|
+
Cheers!
|
196
|
+
---
|
@@ -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,117 @@
|
|
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
|
+
def initialize(endpoint, opts = {})
|
30
|
+
@log = Logging.logger[self.class.name.to_s.to_sym]
|
31
|
+
@httpcli = HTTPClient.new
|
32
|
+
@httpcli.ssl_config.verify_mode = opts[:ssl_verify_mode] if opts[:ssl_verify_mode]
|
33
|
+
# Up the keep-alive so we don't have to do the NTLM dance as often.
|
34
|
+
@httpcli.keep_alive_timeout = 60
|
35
|
+
@endpoint = endpoint
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_auth(user,pass)
|
39
|
+
@httpcli.set_auth(@endpoint.to_s, user, pass)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Authenticate to the web service. You don't have to do this because
|
43
|
+
# authentication will happen on the first request if you don't do it here.
|
44
|
+
# @return [Boolean] true if authentication is successful, false otherwise
|
45
|
+
def authenticate
|
46
|
+
self.get && true
|
47
|
+
end
|
48
|
+
|
49
|
+
# Every Connection class must have the dispatch method. It is what sends the
|
50
|
+
# SOAP request to the server and calls the parser method on the EWS instance.
|
51
|
+
#
|
52
|
+
# This was originally in the ExchangeWebService class but it was added here
|
53
|
+
# to make the processing chain easier to modify. For example, it allows the
|
54
|
+
# reactor pattern to handle the request with a callback.
|
55
|
+
# @param ews [Viewpoint::EWS::SOAP::ExchangeWebService] used to call
|
56
|
+
# #parse_soap_response
|
57
|
+
# @param soapmsg [String]
|
58
|
+
# @param opts [Hash] misc opts for handling the Response
|
59
|
+
def dispatch(ews, soapmsg, opts)
|
60
|
+
respmsg = post(soapmsg)
|
61
|
+
@log.debug <<-EOF.gsub(/^ {6}/, '')
|
62
|
+
Received SOAP Response:
|
63
|
+
----------------
|
64
|
+
#{Nokogiri::XML(respmsg).to_xml}
|
65
|
+
----------------
|
66
|
+
EOF
|
67
|
+
opts[:raw_response] ? respmsg : ews.parse_soap_response(respmsg, opts)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Send a GET to the web service
|
71
|
+
# @return [String] If the request is successful (200) it returns the body of
|
72
|
+
# the response.
|
73
|
+
def get
|
74
|
+
check_response( @httpcli.get(@endpoint) )
|
75
|
+
end
|
76
|
+
|
77
|
+
# Send a POST to the web service
|
78
|
+
# @return [String] If the request is successful (200) it returns the body of
|
79
|
+
# the response.
|
80
|
+
def post(xmldoc)
|
81
|
+
headers = {'Content-Type' => 'text/xml'}
|
82
|
+
check_response( @httpcli.post(@endpoint, xmldoc, headers) )
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def check_response(resp)
|
89
|
+
case resp.status
|
90
|
+
when 200
|
91
|
+
resp.body
|
92
|
+
when 302
|
93
|
+
# @todo redirect
|
94
|
+
raise "Unhandled HTTP Redirect"
|
95
|
+
when 500
|
96
|
+
if resp.headers['Content-Type'].include?('xml')
|
97
|
+
err_string, err_code = parse_soap_error(resp.body)
|
98
|
+
raise "SOAP Error: Message: #{err_string} Code: #{err_code}"
|
99
|
+
else
|
100
|
+
raise "Internal Server Error. Message: #{resp.body}"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
raise "HTTP Error Code: #{resp.status}, Msg: #{resp.body}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param [String] xml to parse the errors from.
|
108
|
+
def parse_soap_error(xml)
|
109
|
+
ndoc = Nokogiri::XML(xml)
|
110
|
+
ns = ndoc.collect_namespaces
|
111
|
+
err_string = ndoc.xpath("//faultstring",ns).text
|
112
|
+
err_code = ndoc.xpath("//faultcode",ns).text
|
113
|
+
@log.debug "Internal SOAP error. Message: #{err_string}, Code: #{err_code}"
|
114
|
+
[err_string, err_code]
|
115
|
+
end
|
116
|
+
|
117
|
+
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,71 @@
|
|
1
|
+
require 'ews/folder_accessors'
|
2
|
+
require 'ews/item_accessors'
|
3
|
+
require 'ews/message_accessors'
|
4
|
+
require 'ews/mailbox_accessors'
|
5
|
+
require 'ews/push_subscription_accessors'
|
6
|
+
require 'ews/calendar_accessors'
|
7
|
+
|
8
|
+
# This class is the glue between the Models and the Web Service.
|
9
|
+
class Viewpoint::EWSClient
|
10
|
+
include Viewpoint::EWS
|
11
|
+
include Viewpoint::EWS::FolderAccessors
|
12
|
+
include Viewpoint::EWS::ItemAccessors
|
13
|
+
include Viewpoint::EWS::MessageAccessors
|
14
|
+
include Viewpoint::EWS::MailboxAccessors
|
15
|
+
include Viewpoint::EWS::PushSubscriptionAccessors
|
16
|
+
include Viewpoint::EWS::CalendarAccessors
|
17
|
+
|
18
|
+
# The instance of Viewpoint::EWS::SOAP::ExchangeWebService
|
19
|
+
attr_reader :ews
|
20
|
+
|
21
|
+
# Initialize the EWSClient instance.
|
22
|
+
# @param [String] endpoint The EWS endpoint we will be connecting to
|
23
|
+
# @param [String] user The user to authenticate as. If you are using
|
24
|
+
# NTLM or Negotiate authentication you do not need to pass this parameter.
|
25
|
+
# @param [String] pass The user password. If you are using NTLM or
|
26
|
+
# Negotiate authentication you do not need to pass this parameter.
|
27
|
+
# @param [Hash] opts Various options to pass to the backends
|
28
|
+
# @option opts [String] :server_version The Exchange server version to
|
29
|
+
# target. See the VERSION_* constants in
|
30
|
+
# Viewpoint::EWS::SOAP::ExchangeWebService.
|
31
|
+
# @option opts [Object] :http_class specify an alternate HTTP connection class.
|
32
|
+
# @option opts [Hash] :http_opts options to pass to the connection
|
33
|
+
def initialize(endpoint, user = nil, pass = nil, opts = {})
|
34
|
+
http_klass = opts[:http_class] || Viewpoint::EWS::Connection
|
35
|
+
con = http_klass.new(endpoint, opts[:http_opts] || {})
|
36
|
+
con.set_auth(user,pass) if(user && pass)
|
37
|
+
@ews = SOAP::ExchangeWebService.new(con, opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def auto_deepen=(deepen)
|
41
|
+
@ews.auto_deepen = (deepen ? true : false)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
|
48
|
+
# This method also exists in EWS::Types, but there is a lot of other stuff
|
49
|
+
# in there that I didn't want to include directly in this class.
|
50
|
+
def class_by_name(cname)
|
51
|
+
if(cname.instance_of? Symbol)
|
52
|
+
cname = cname.to_s.camel_case
|
53
|
+
end
|
54
|
+
Viewpoint::EWS::Types.const_get(cname)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Used for multiple accessors
|
58
|
+
def merge_restrictions!(obj, merge_type = :and)
|
59
|
+
if obj.opts[:restriction] && !obj.opts[:restriction].empty? && !obj.restriction.empty?
|
60
|
+
obj.opts[:restriction] = {
|
61
|
+
merge_type => [
|
62
|
+
obj.opts.delete(:restriction),
|
63
|
+
obj.restriction
|
64
|
+
]
|
65
|
+
}
|
66
|
+
elsif !obj.restriction.empty?
|
67
|
+
obj.opts[:restriction] = obj.restriction
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|