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.
- checksums.yaml +4 -4
- data/README.md +13 -8
- data/lib/ews/calendar_accessors.rb +37 -33
- data/lib/ews/connection.rb +151 -124
- data/lib/ews/connection_helper.rb +36 -33
- data/lib/ews/convert_accessors.rb +58 -54
- data/lib/ews/errors.rb +59 -53
- data/lib/ews/ews_client.rb +92 -79
- data/lib/ews/exceptions/exceptions.rb +61 -61
- data/lib/ews/folder_accessors.rb +235 -234
- data/lib/ews/impersonation.rb +29 -23
- data/lib/ews/item_accessors.rb +215 -213
- data/lib/ews/mailbox_accessors.rb +82 -79
- data/lib/ews/meeting_accessors.rb +38 -31
- data/lib/ews/message_accessors.rb +83 -81
- data/lib/ews/push_subscription_accessors.rb +29 -27
- data/lib/ews/room_accessors.rb +48 -46
- data/lib/ews/roomlist_accessors.rb +47 -45
- data/lib/ews/soap/builders/ews_builder.rb +1186 -1188
- data/lib/ews/soap/ews_response.rb +68 -73
- data/lib/ews/soap/ews_soap_availability_response.rb +57 -57
- data/lib/ews/soap/ews_soap_free_busy_response.rb +115 -117
- data/lib/ews/soap/ews_soap_response.rb +99 -101
- data/lib/ews/soap/ews_soap_room_response.rb +45 -45
- data/lib/ews/soap/ews_soap_roomlist_response.rb +45 -46
- data/lib/ews/soap/exchange_availability.rb +54 -52
- data/lib/ews/soap/exchange_data_services.rb +693 -711
- data/lib/ews/soap/exchange_notification.rb +123 -128
- data/lib/ews/soap/exchange_synchronization.rb +82 -82
- data/lib/ews/soap/exchange_time_zones.rb +41 -44
- data/lib/ews/soap/exchange_user_configuration.rb +30 -27
- data/lib/ews/soap/exchange_web_service.rb +237 -233
- data/lib/ews/soap/parsers/ews_parser.rb +46 -42
- data/lib/ews/soap/parsers/ews_sax_document.rb +63 -58
- data/lib/ews/soap/response_message.rb +69 -68
- data/lib/ews/soap/responses/create_attachment_response_message.rb +45 -45
- data/lib/ews/soap/responses/create_item_response_message.rb +26 -25
- data/lib/ews/soap/responses/find_item_response_message.rb +76 -78
- data/lib/ews/soap/responses/get_events_response_message.rb +52 -51
- data/lib/ews/soap/responses/send_notification_response_message.rb +53 -51
- data/lib/ews/soap/responses/subscribe_response_message.rb +37 -34
- data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +38 -35
- data/lib/ews/soap/responses/sync_folder_items_response_message.rb +38 -35
- data/lib/ews/soap.rb +27 -26
- data/lib/ews/templates/calendar_item.rb +64 -60
- data/lib/ews/templates/forward_item.rb +19 -17
- data/lib/ews/templates/message.rb +61 -67
- data/lib/ews/templates/reply_to_item.rb +20 -18
- data/lib/ews/templates/task.rb +55 -55
- data/lib/ews/types/attachment.rb +75 -74
- data/lib/ews/types/attendee.rb +27 -25
- data/lib/ews/types/calendar_folder.rb +60 -44
- data/lib/ews/types/calendar_item.rb +134 -116
- data/lib/ews/types/contact.rb +11 -5
- data/lib/ews/types/contacts_folder.rb +10 -5
- data/lib/ews/types/copied_event.rb +47 -48
- data/lib/ews/types/created_event.rb +22 -20
- data/lib/ews/types/deleted_event.rb +22 -20
- data/lib/ews/types/distribution_list.rb +11 -5
- data/lib/ews/types/event.rb +60 -59
- data/lib/ews/types/export_items_response_message.rb +54 -50
- data/lib/ews/types/file_attachment.rb +63 -61
- data/lib/ews/types/folder.rb +58 -57
- data/lib/ews/types/free_busy_changed_event.rb +22 -20
- data/lib/ews/types/generic_folder.rb +348 -372
- data/lib/ews/types/item.rb +401 -397
- data/lib/ews/types/item_attachment.rb +87 -80
- data/lib/ews/types/item_field_uri_map.rb +201 -200
- data/lib/ews/types/mailbox_user.rb +146 -154
- data/lib/ews/types/meeting_cancellation.rb +11 -5
- data/lib/ews/types/meeting_message.rb +11 -5
- data/lib/ews/types/meeting_request.rb +11 -5
- data/lib/ews/types/meeting_response.rb +11 -5
- data/lib/ews/types/message.rb +11 -5
- data/lib/ews/types/modified_event.rb +43 -45
- data/lib/ews/types/moved_event.rb +47 -48
- data/lib/ews/types/new_mail_event.rb +22 -20
- data/lib/ews/types/out_of_office.rb +145 -144
- data/lib/ews/types/post_item.rb +11 -5
- data/lib/ews/types/search_folder.rb +10 -5
- data/lib/ews/types/status_event.rb +37 -36
- data/lib/ews/types/task.rb +39 -33
- data/lib/ews/types/tasks_folder.rb +32 -22
- data/lib/ews/types.rb +134 -139
- data/lib/viewpoint/logging/config.rb +19 -19
- data/lib/viewpoint/logging.rb +23 -17
- data/lib/viewpoint/string_utils.rb +31 -32
- data/lib/viewpoint.rb +18 -18
- metadata +82 -11
- data/Changelog.txt +0 -1004
data/lib/ews/types.rb
CHANGED
|
@@ -1,194 +1,189 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@
|
|
20
|
-
@
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Viewpoint
|
|
4
|
+
module EWS
|
|
5
|
+
# EWS data type models.
|
|
6
|
+
module Types
|
|
7
|
+
include Viewpoint::StringUtils
|
|
8
|
+
|
|
9
|
+
KEY_PATHS = {
|
|
10
|
+
extended_properties: [:extended_property]
|
|
11
|
+
}.freeze
|
|
12
|
+
KEY_TYPES = {
|
|
13
|
+
extended_properties: :build_extended_properties
|
|
14
|
+
}.freeze
|
|
15
|
+
KEY_ALIAS = {}.freeze
|
|
16
|
+
|
|
17
|
+
attr_reader :ews_item
|
|
18
|
+
|
|
19
|
+
# @param [SOAP::ExchangeWebService] ews the EWS reference
|
|
20
|
+
# @param [Hash] ews_item the EWS parsed response document
|
|
21
|
+
def initialize(ews, ews_item)
|
|
22
|
+
@ews = ews
|
|
23
|
+
@ews_item = ews_item
|
|
24
|
+
@shallow = true
|
|
25
|
+
@frozen = false
|
|
26
|
+
end
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
def method_missing(method_sym, *arguments, &block)
|
|
29
|
+
if method_keys.include?(method_sym)
|
|
30
|
+
type_convert(method_sym, resolve_method(method_sym))
|
|
31
|
+
else
|
|
32
|
+
super
|
|
33
|
+
end
|
|
29
34
|
end
|
|
30
|
-
end
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
def respond_to_missing?(method_sym, include_private = false)
|
|
37
|
+
method_keys.include?(method_sym) || super
|
|
38
|
+
end
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
def to_s
|
|
41
|
+
"#{self.class.name}: EWS METHODS: #{ews_methods.sort.join(', ')}"
|
|
42
|
+
end
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
+
def frozen?
|
|
45
|
+
@frozen
|
|
46
|
+
end
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
# @param ronly [Boolean] true to freeze
|
|
49
|
+
def freeze!
|
|
50
|
+
@frozen = true
|
|
51
|
+
end
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
def unfreeze!
|
|
54
|
+
@frozen = false
|
|
55
|
+
end
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
def shallow?
|
|
58
|
+
@shallow
|
|
59
|
+
end
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
def mark_deep!
|
|
62
|
+
@shallow = false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def auto_deepen?
|
|
66
|
+
ews.auto_deepen
|
|
67
|
+
end
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
def deepen!
|
|
70
|
+
return unless shallow?
|
|
71
|
+
|
|
72
|
+
get_all_properties!
|
|
64
73
|
@shallow = false
|
|
65
74
|
true
|
|
66
75
|
end
|
|
67
|
-
|
|
68
|
-
alias_method :enlighten!, :deepen!
|
|
76
|
+
alias enlighten! deepen!
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else
|
|
75
|
-
super
|
|
78
|
+
# @see http://www.ruby-doc.org/core/classes/Object.html#M000333
|
|
79
|
+
# rubocop:disable Style/OptionalBooleanParameter -- must match Ruby's core respond_to? signature
|
|
80
|
+
def respond_to?(method_sym, include_private = false)
|
|
81
|
+
method_keys.include?(method_sym) || super
|
|
76
82
|
end
|
|
77
|
-
|
|
83
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
# rubocop:disable Style/OptionalBooleanParameter -- must match Ruby's core Object#methods signature
|
|
86
|
+
def methods(include_super = true)
|
|
87
|
+
super + ews_methods
|
|
88
|
+
end
|
|
89
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
def ews_methods
|
|
92
|
+
key_paths.keys + key_alias.keys
|
|
93
|
+
end
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
protected # things like OutOfOffice need protected level access
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
def ews
|
|
98
|
+
@ews
|
|
99
|
+
end
|
|
92
100
|
|
|
93
|
-
|
|
101
|
+
private
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
def key_paths
|
|
104
|
+
KEY_PATHS
|
|
105
|
+
end
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
def key_types
|
|
108
|
+
KEY_TYPES
|
|
109
|
+
end
|
|
102
110
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
def key_alias
|
|
112
|
+
KEY_ALIAS
|
|
113
|
+
end
|
|
106
114
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
def class_by_name(cname)
|
|
116
|
+
cname = camel_case(cname) if cname.instance_of? Symbol
|
|
117
|
+
Viewpoint::EWS::Types.const_get(cname)
|
|
110
118
|
end
|
|
111
|
-
Viewpoint::EWS::Types.const_get(cname)
|
|
112
|
-
end
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
begin
|
|
120
|
+
def type_convert(key, str)
|
|
116
121
|
key = key_alias[key] || key
|
|
117
122
|
if key_types[key]
|
|
118
123
|
key_types[key].is_a?(Symbol) ? method(key_types[key]).call(str) : key_types[key].call(str)
|
|
119
124
|
else
|
|
120
125
|
str
|
|
121
126
|
end
|
|
122
|
-
rescue
|
|
127
|
+
rescue StandardError
|
|
123
128
|
nil
|
|
124
129
|
end
|
|
125
|
-
end
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
begin
|
|
131
|
+
def resolve_method(method_sym)
|
|
129
132
|
resolve_key_path(@ews_item, method_path(method_sym))
|
|
130
|
-
rescue
|
|
133
|
+
rescue StandardError
|
|
131
134
|
if shallow?
|
|
132
135
|
if frozen?
|
|
133
136
|
raise EwsFrozenObjectError, "Could not resolve :#{method_sym} on frozen object."
|
|
134
137
|
elsif auto_deepen?
|
|
135
138
|
enlighten!
|
|
136
139
|
retry
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
raise EwsMinimalObjectError, "Could not resolve :#{method_sym}. #auto_deepen set to false"
|
|
141
|
-
else
|
|
142
|
-
nil
|
|
143
|
-
end
|
|
144
|
-
else
|
|
145
|
-
end
|
|
140
|
+
elsif !auto_deepen? && (ews.no_auto_deepen_behavior == :raise)
|
|
141
|
+
raise EwsMinimalObjectError, "Could not resolve :#{method_sym}. #auto_deepen set to false"
|
|
142
|
+
|
|
146
143
|
end
|
|
147
|
-
else
|
|
148
|
-
nil
|
|
149
144
|
end
|
|
150
145
|
end
|
|
151
|
-
end
|
|
152
146
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
resolve_key_path(hsh[k],path[1..-1])
|
|
157
|
-
end
|
|
147
|
+
def resolve_key_path(hsh, path)
|
|
148
|
+
k = path.first
|
|
149
|
+
return hsh[k] if path.length == 1
|
|
158
150
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
end
|
|
151
|
+
resolve_key_path(hsh[k], path[1..])
|
|
152
|
+
end
|
|
162
153
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
end
|
|
154
|
+
def method_keys
|
|
155
|
+
key_paths.keys + key_alias.keys
|
|
156
|
+
end
|
|
167
157
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
eprops
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
# Resolve the method path with or without an alias
|
|
159
|
+
def method_path(sym)
|
|
160
|
+
key_paths[key_alias[sym] || sym]
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def build_extended_properties(eprops)
|
|
164
|
+
h = {}
|
|
165
|
+
# todo
|
|
166
|
+
# the return pattern seems broken in some cases,
|
|
167
|
+
# probably needs fixing via a dedicated response parser
|
|
168
|
+
eprops.each do |e|
|
|
169
|
+
if e.size == 1
|
|
170
|
+
e[:elems].each_cons(2) do |k, v|
|
|
171
|
+
key = k[:extended_field_u_r_i][:attribs][:property_name].downcase.to_sym
|
|
172
|
+
val = v[:value][:text]
|
|
173
|
+
h.store(key, val)
|
|
174
|
+
end
|
|
175
|
+
elsif e.size == 2
|
|
176
|
+
e[1].each_cons(2) do |k, v|
|
|
177
|
+
key = k[:extended_field_u_r_i][:attribs][:property_name].downcase.to_sym
|
|
178
|
+
val = v[:value][:text]
|
|
179
|
+
h.store(key, val)
|
|
180
|
+
end
|
|
181
|
+
else
|
|
182
|
+
raise EwsMinimalObjectError, 'Not prepared to deal with elements greater than 2'
|
|
185
183
|
end
|
|
186
|
-
else
|
|
187
|
-
raise EwsMinimalObjectError, "Not prepared to deal with elements greater than 2"
|
|
188
184
|
end
|
|
185
|
+
h
|
|
189
186
|
end
|
|
190
|
-
h
|
|
191
187
|
end
|
|
192
|
-
|
|
193
188
|
end
|
|
194
189
|
end
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
|
19
19
|
module Viewpoint
|
|
20
|
+
# Exchange Web Services (EWS) client namespace.
|
|
20
21
|
module EWS
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
end # EWS
|
|
22
|
+
root_logger.level = Logger::DEBUG
|
|
23
|
+
end
|
|
24
24
|
end
|
data/lib/viewpoint/logging.rb
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
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.
|
|
5
18
|
|
|
6
|
-
|
|
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
|
|
19
|
+
require 'logger' unless defined?(Logger)
|
|
18
20
|
|
|
19
21
|
module Viewpoint
|
|
22
|
+
# Exchange Web Services (EWS) client namespace.
|
|
20
23
|
module EWS
|
|
21
24
|
attr_reader :logger
|
|
22
25
|
|
|
26
|
+
@root_logger = Logger.new($stdout)
|
|
27
|
+
@root_logger.level = Logger::WARN
|
|
28
|
+
|
|
23
29
|
def self.root_logger
|
|
24
|
-
|
|
30
|
+
@root_logger
|
|
25
31
|
end
|
|
26
|
-
end
|
|
32
|
+
end
|
|
27
33
|
end
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
|
19
19
|
module Viewpoint
|
|
20
|
-
|
|
21
|
-
class StringFormatException < ::Exception; end
|
|
20
|
+
class StringFormatException < ::StandardError; end
|
|
22
21
|
|
|
23
22
|
# Collection of utility methods for working with Strings
|
|
24
23
|
module StringUtils
|
|
25
|
-
|
|
26
24
|
DURATION_RE = /
|
|
27
25
|
(?<start>P)
|
|
28
|
-
((?<weeks>\d+)W)?
|
|
29
|
-
((?<days>\d+)D)?
|
|
26
|
+
(?:(?<weeks>\d+)W)?
|
|
27
|
+
(?:(?<days>\d+)D)?
|
|
30
28
|
(?<time>T
|
|
31
|
-
((?<hours>\d+)H)?
|
|
32
|
-
((?<minutes>\d+)M)?
|
|
33
|
-
((?<seconds>\d+)S)?
|
|
29
|
+
(?:(?<hours>\d+)H)?
|
|
30
|
+
(?:(?<minutes>\d+)M)?
|
|
31
|
+
(?:(?<seconds>\d+)S)?
|
|
34
32
|
)?
|
|
35
33
|
/x
|
|
36
34
|
|
|
@@ -51,7 +49,7 @@ module Viewpoint
|
|
|
51
49
|
# Change a ruby_cased string to CamelCased
|
|
52
50
|
def camel_case(input)
|
|
53
51
|
input.to_s.split(/_/).map { |i|
|
|
54
|
-
i.sub(
|
|
52
|
+
i.sub(/^./, &:upcase)
|
|
55
53
|
}.join
|
|
56
54
|
end
|
|
57
55
|
|
|
@@ -62,15 +60,16 @@ module Viewpoint
|
|
|
62
60
|
# nil if there is no known duration
|
|
63
61
|
def iso8601_duration_to_seconds(input)
|
|
64
62
|
return nil if input.nil? || input.empty?
|
|
63
|
+
|
|
65
64
|
match_data = DURATION_RE.match(input)
|
|
66
|
-
raise(StringFormatException,
|
|
65
|
+
raise(StringFormatException, 'Invalid duration given') if match_data.nil?
|
|
66
|
+
|
|
67
67
|
duration = 0
|
|
68
|
-
duration += match_data[:weeks].to_i *
|
|
69
|
-
duration += match_data[:days].to_i *
|
|
68
|
+
duration += match_data[:weeks].to_i * 604_800
|
|
69
|
+
duration += match_data[:days].to_i * 86_400
|
|
70
70
|
duration += match_data[:hours].to_i * 3600
|
|
71
71
|
duration += match_data[:minutes].to_i * 60
|
|
72
|
-
duration
|
|
72
|
+
duration + match_data[:seconds].to_i
|
|
73
73
|
end
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
end # Viewpoint
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/viewpoint.rb
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
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.
|
|
5
18
|
|
|
6
|
-
|
|
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
|
-
require 'kconv' if(RUBY_VERSION.start_with? '1.9') # bug in rubyntlm with ruby 1.9.x
|
|
19
|
+
require 'kconv' if RUBY_VERSION.start_with? '1.9' # bug in rubyntlm with ruby 1.9.x
|
|
20
20
|
require 'date'
|
|
21
21
|
require 'base64'
|
|
22
22
|
require 'nokogiri'
|
|
23
23
|
require 'ostruct'
|
|
24
|
-
require '
|
|
24
|
+
require 'logger' unless defined?(Logger)
|
|
25
25
|
|
|
26
26
|
# String utilities
|
|
27
27
|
require 'viewpoint/string_utils'
|