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
@@ -1,77 +1,78 @@
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::Types
20
- # A generic Attachment. This class should not be instantiated directly. You
21
- # should use one of the subclasses like FileAttachment or ItemAttachment.
22
- class Attachment
23
- include Viewpoint::EWS
24
- include Viewpoint::EWS::Types
25
- include Viewpoint::EWS::Types::Item
26
-
27
- ATTACH_KEY_PATHS = {
28
- :id => [:attachment_id, :attribs, :id],
29
- :parent_item_id => [:attachment_id, :attribs, :root_item_id],
30
- :parent_change_key => [:attachment_id, :attribs, :root_item_change_key],
31
- :name => [:name, :text],
32
- :content_type => [:content_type, :text],
33
- :content_id => [:content_id],
34
- :size => [:size, :text],
35
- :last_modified_time => [:last_modified_time, :text],
36
- :is_inline? => [:is_inline, :text],
37
- }
38
-
39
- ATTACH_KEY_TYPES = {
40
- is_inline?: ->(str){str.downcase == 'true'},
41
- last_modified_type: ->(str){DateTime.parse(str)},
42
- size: ->(str){str.to_i},
43
- content_id: :fix_content_id,
44
- }
45
-
46
- ATTACH_KEY_ALIAS = { }
47
-
48
- # @param [Hash] attachment The attachment ews_item
49
- def initialize(item, attachment)
50
- @item = item
51
- super(item.ews, attachment)
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
+ module Types
22
+ # A generic Attachment. This class should not be instantiated directly. You
23
+ # should use one of the subclasses like FileAttachment or ItemAttachment.
24
+ class Attachment
25
+ include Viewpoint::EWS
26
+ include Viewpoint::EWS::Types
27
+ include Viewpoint::EWS::Types::Item
28
+
29
+ ATTACH_KEY_PATHS = {
30
+ id: %i[attachment_id attribs id],
31
+ parent_item_id: %i[attachment_id attribs root_item_id],
32
+ parent_change_key: %i[attachment_id attribs root_item_change_key],
33
+ name: %i[name text],
34
+ content_type: %i[content_type text],
35
+ content_id: [:content_id],
36
+ size: %i[size text],
37
+ last_modified_time: %i[last_modified_time text],
38
+ is_inline?: %i[is_inline text]
39
+ }.freeze
40
+
41
+ ATTACH_KEY_TYPES = {
42
+ is_inline?: ->(str) { str.downcase == 'true' },
43
+ last_modified_type: ->(str) { DateTime.parse(str) },
44
+ size: lambda(&:to_i),
45
+ content_id: :fix_content_id
46
+ }.freeze
47
+
48
+ ATTACH_KEY_ALIAS = {}.freeze
49
+
50
+ # @param [Hash] attachment The attachment ews_item
51
+ def initialize(item, attachment)
52
+ @item = item
53
+ super(item.ews, attachment)
54
+ end
55
+
56
+ private
57
+
58
+ def key_paths
59
+ @key_paths ||= ATTACH_KEY_PATHS
60
+ end
61
+
62
+ def key_types
63
+ @key_types ||= ATTACH_KEY_TYPES
64
+ end
65
+
66
+ def key_alias
67
+ @key_alias ||= ATTACH_KEY_ALIAS
68
+ end
69
+
70
+ # Sometimes the SOAP response comes back with two identical content_ids.
71
+ # This method fishes them out no matter which way them come.
72
+ def fix_content_id(content_id)
73
+ content_id.is_a?(Array) ? content_id.last[:text] : content_id[:text]
74
+ end
75
+ end
52
76
  end
53
-
54
-
55
- private
56
-
57
-
58
- def key_paths
59
- @key_paths ||= ATTACH_KEY_PATHS
60
- end
61
-
62
- def key_types
63
- @key_types ||= ATTACH_KEY_TYPES
64
- end
65
-
66
- def key_alias
67
- @key_alias ||= ATTACH_KEY_ALIAS
68
- end
69
-
70
- # Sometimes the SOAP response comes back with two identical content_ids.
71
- # This method fishes them out no matter which way them come.
72
- def fix_content_id(content_id)
73
- content_id.is_a?(Array) ? content_id.last[:text] : content_id[:text]
74
- end
75
-
76
77
  end
77
78
  end
@@ -1,27 +1,29 @@
1
- =begin
2
- This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
1
+ # frozen_string_literal: true
3
2
 
4
- Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
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
- 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::Types
20
-
21
- # This represents a Mailbox object in the Exchange data store
22
- # @see http://msdn.microsoft.com/en-us/library/aa565036.aspx MSDN docs
23
- # @todo Design a Class method that resolves to an Array of MailboxUsers
24
- class Attendee < MailboxUser
25
- end # Attendee
26
-
27
- end # Viewpoint::EWS::Types
19
+ module Viewpoint
20
+ module EWS
21
+ module Types
22
+ # This represents a Mailbox object in the Exchange data store
23
+ # @see http://msdn.microsoft.com/en-us/library/aa565036.aspx MSDN docs
24
+ # @todo Design a Class method that resolves to an Array of MailboxUsers
25
+ class Attendee < MailboxUser
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,50 +1,66 @@
1
- module Viewpoint::EWS::Types
2
- class CalendarFolder
3
- include Viewpoint::EWS
4
- include Viewpoint::EWS::Types
5
- include Viewpoint::EWS::Types::GenericFolder
1
+ # frozen_string_literal: true
6
2
 
7
- # Fetch items between a given time period
8
- # @param [DateTime] start_date the time to start fetching Items from
9
- # @param [DateTime] end_date the time to stop fetching Items from
10
- def items_between(start_date, end_date, opts={})
11
- items do |obj|
12
- obj.restriction = { :and =>
13
- [
14
- {:is_greater_than_or_equal_to =>
15
- [
16
- {:field_uRI => {:field_uRI=>'calendar:Start'}},
17
- {:field_uRI_or_constant=>{:constant => {:value =>start_date}}}
18
- ]
19
- },
20
- {:is_less_than_or_equal_to =>
21
- [
22
- {:field_uRI => {:field_uRI=>'calendar:End'}},
23
- {:field_uRI_or_constant=>{:constant => {:value =>end_date}}}
24
- ]
25
- }
26
- ]
27
- }
28
- end
29
- end
3
+ module Viewpoint
4
+ module EWS
5
+ module Types
6
+ # Calendar Folder EWS data type.
7
+ class CalendarFolder
8
+ include Viewpoint::EWS
9
+ include Viewpoint::EWS::Types
10
+ include Viewpoint::EWS::Types::GenericFolder
11
+
12
+ # Fetch items between a given time period
13
+ # @param [DateTime] start_date the time to start fetching Items from
14
+ # @param [DateTime] end_date the time to stop fetching Items from
15
+ def items_between(start_date, end_date, _opts = {})
16
+ items do |obj|
17
+ obj.restriction = { and: [
18
+ { is_greater_than_or_equal_to: [
19
+ { field_uRI: { field_uRI: 'calendar:Start' } },
20
+ { field_uRI_or_constant: { constant: { value: start_date } } }
21
+ ] },
22
+ { is_less_than_or_equal_to: [
23
+ { field_uRI: { field_uRI: 'calendar:End' } },
24
+ { field_uRI_or_constant: { constant: { value: end_date } } }
25
+ ] }
26
+ ] }
27
+ end
28
+ end
29
+
30
+ # Fetch items between a given time period using a calendar view.
31
+ # The calendar view will include occurences of recurring calendar items
32
+ # next to the regular single calendar items.
33
+ # @param [DateTime] start_date the time to start fetching Items from
34
+ # @param [DateTime] end_date the time to stop fetching Items from
35
+ # @param opts [Hash]
36
+ # @option opts :max_entries_returned [Integer] the maximum number of entries to return
37
+ def items_between_calendar_view(start_date, end_date, opts = {})
38
+ view_opts = { start_date: start_date, end_date: end_date }
39
+ view_opts[:max_entries_returned] = opts.delete(:max_entries_returned) if opts[:max_entries_returned]
40
+ items(opts.merge(calendar_view: view_opts))
41
+ end
30
42
 
31
- # Creates a new appointment
32
- # @param attributes [Hash] Parameters of the calendar item. Some example attributes are listed below.
33
- # @option attributes :subject [String]
34
- # @option attributes :start [Time]
35
- # @option attributes :end [Time]
36
- # @return [CalendarItem]
37
- # @see Template::CalendarItem
38
- def create_item(attributes, to_ews_create_opts = {})
39
- template = Viewpoint::EWS::Template::CalendarItem.new attributes
40
- template.saved_item_folder_id = {id: self.id, change_key: self.change_key}
41
- rm = ews.create_item(template.to_ews_create(to_ews_create_opts)).response_messages.first
42
- if rm && rm.success?
43
- CalendarItem.new ews, rm.items.first[:calendar_item][:elems].first
44
- else
45
- raise EwsCreateItemError, "Could not create item in folder. #{rm.code}: #{rm.message_text}" unless rm
43
+ # Creates a new appointment
44
+ # @param attributes [Hash] Parameters of the calendar item. Some example attributes are listed below.
45
+ # @option attributes :subject [String]
46
+ # @option attributes :start [Time]
47
+ # @option attributes :end [Time]
48
+ # @return [CalendarItem]
49
+ # @see Template::CalendarItem
50
+ def create_item(attributes, to_ews_create_opts = {})
51
+ template = Viewpoint::EWS::Template::CalendarItem.new attributes
52
+ template.saved_item_folder_id = { id: id, change_key: change_key }
53
+ rm = ews.create_item(template.to_ews_create(to_ews_create_opts)).response_messages.first
54
+ if rm&.success?
55
+ CalendarItem.new ews, rm.items.first[:calendar_item][:elems].first
56
+ else
57
+ raise EwsCreateItemError, "Could not create item in folder. #{rm.code}: #{rm.message_text}" if rm
58
+
59
+ raise EwsCreateItemError, 'Could not create item in folder.'
60
+
61
+ end
62
+ end
46
63
  end
47
64
  end
48
-
49
65
  end
50
66
  end
@@ -1,130 +1,148 @@
1
- module Viewpoint::EWS::Types
2
- class CalendarItem
3
- include Viewpoint::EWS
4
- include Viewpoint::EWS::Types
5
- include Viewpoint::EWS::Types::Item
6
- include Viewpoint::StringUtils
7
-
8
- CALENDAR_ITEM_KEY_PATHS = {
9
- recurring?: [:is_recurring, :text],
10
- meeting?: [:is_meeting, :text],
11
- cancelled?: [:is_cancelled, :text],
12
- duration: [:duration, :text],
13
- time_zone: [:time_zone, :text],
14
- start: [:start, :text],
15
- end: [:end, :text],
16
- location: [:location, :text],
17
- all_day?: [:is_all_day_event, :text],
18
- legacy_free_busy_status: [:legacy_free_busy_status, :text],
19
- my_response_type: [:my_response_type, :text],
20
- organizer: [:organizer, :elems, 0, :mailbox, :elems],
21
- optional_attendees: [:optional_attendees, :elems ],
22
- required_attendees: [:required_attendees, :elems ],
23
- recurrence: [:recurrence, :elems ],
24
- deleted_occurrences: [:deleted_occurrences, :elems ],
25
- modified_occurrences: [:modified_occurrences, :elems ]
26
- }
27
-
28
- CALENDAR_ITEM_KEY_TYPES = {
29
- start: ->(str){DateTime.parse(str)},
30
- end: ->(str){DateTime.parse(str)},
31
- recurring?: ->(str){str.downcase == 'true'},
32
- meeting?: ->(str){str.downcase == 'true'},
33
- cancelled?: ->(str){str.downcase == 'true'},
34
- all_day?: ->(str){str.downcase == 'true'},
35
- organizer: :build_mailbox_user,
36
- optional_attendees: :build_attendees_users,
37
- required_attendees: :build_attendees_users,
38
- deleted_occurrences: :build_deleted_occurrences,
39
- modified_occurrences: :build_modified_occurrences
40
- }
41
- CALENDAR_ITEM_KEY_ALIAS = {}
42
-
43
- # Updates the specified item attributes
44
- #
45
- # Uses `SetItemField` if value is present and `DeleteItemField` if value is nil
46
- # @param updates [Hash] with (:attribute => value)
47
- # @param options [Hash]
48
- # @option options :conflict_resolution [String] one of 'NeverOverwrite', 'AutoResolve' (default) or 'AlwaysOverwrite'
49
- # @option options :send_meeting_invitations_or_cancellations [String] one of 'SendToNone' (default), 'SendOnlyToAll',
50
- # 'SendOnlyToChanged', 'SendToAllAndSaveCopy' or 'SendToChangedAndSaveCopy'
51
- # @return [CalendarItem, false]
52
- # @example Update Subject and Body
53
- # item = #...
54
- # item.update_item!(subject: 'New subject', body: 'New Body')
55
- # @see http://msdn.microsoft.com/en-us/library/exchange/aa580254.aspx
56
- # @todo AppendToItemField updates not implemented
57
- def update_item!(updates, options = {})
58
- item_updates = []
59
- updates.each do |attribute, value|
60
- item_field = FIELD_URIS[attribute][:text] if FIELD_URIS.include? attribute
61
- field = {field_uRI: {field_uRI: item_field}}
62
-
63
- if value.nil? && item_field
64
- # Build DeleteItemField Change
65
- item_updates << {delete_item_field: field}
66
- elsif item_field
67
- # Build SetItemField Change
68
- item = Viewpoint::EWS::Template::CalendarItem.new(attribute => value)
69
-
70
- # Remap attributes because ews_builder #dispatch_field_item! uses #build_xml!
71
- item_attributes = item.to_ews_item.map do |name, value|
72
- if value.is_a? String
73
- {name => {text: value}}
74
- elsif value.is_a? Hash
75
- node = {name => {}}
76
- value.each do |attrib_key, attrib_value|
77
- attrib_key = camel_case(attrib_key) unless attrib_key == :text
78
- node[name][attrib_key] = attrib_value
79
- end
80
- node
81
- else
82
- {name => value}
1
+ # frozen_string_literal: true
2
+
3
+ module Viewpoint
4
+ module EWS
5
+ module Types
6
+ # Calendar Item EWS data type.
7
+ class CalendarItem
8
+ include Viewpoint::EWS
9
+ include Viewpoint::EWS::Types
10
+ include Viewpoint::EWS::Types::Item
11
+ include Viewpoint::StringUtils
12
+
13
+ CALENDAR_ITEM_KEY_PATHS = {
14
+ recurring?: %i[is_recurring text],
15
+ meeting?: %i[is_meeting text],
16
+ cancelled?: %i[is_cancelled text],
17
+ duration: %i[duration text],
18
+ time_zone: %i[time_zone text],
19
+ start: %i[start text],
20
+ end: %i[end text],
21
+ location: %i[location text],
22
+ all_day?: %i[is_all_day_event text],
23
+ legacy_free_busy_status: %i[legacy_free_busy_status text],
24
+ my_response_type: %i[my_response_type text],
25
+ organizer: [:organizer, :elems, 0, :mailbox, :elems],
26
+ optional_attendees: %i[optional_attendees elems],
27
+ required_attendees: %i[required_attendees elems],
28
+ recurrence: %i[recurrence elems],
29
+ deleted_occurrences: %i[deleted_occurrences elems],
30
+ modified_occurrences: %i[modified_occurrences elems]
31
+ }.freeze
32
+
33
+ CALENDAR_ITEM_KEY_TYPES = {
34
+ start: ->(str) { DateTime.parse(str) },
35
+ end: ->(str) { DateTime.parse(str) },
36
+ recurring?: ->(str) { str.downcase == 'true' },
37
+ meeting?: ->(str) { str.downcase == 'true' },
38
+ cancelled?: ->(str) { str.downcase == 'true' },
39
+ all_day?: ->(str) { str.downcase == 'true' },
40
+ organizer: :build_mailbox_user,
41
+ optional_attendees: :build_attendees_users,
42
+ required_attendees: :build_attendees_users,
43
+ deleted_occurrences: :build_deleted_occurrences,
44
+ modified_occurrences: :build_modified_occurrences
45
+ }.freeze
46
+ CALENDAR_ITEM_KEY_ALIAS = {}.freeze
47
+
48
+ # Delete this calendar item
49
+ # @param deltype [Symbol] The delete type; must be :hard, :soft, or :recycle.
50
+ # By default EWS will do a hard delete of this calendar item. See the=
51
+ # MSDN docs for more info: http://msdn.microsoft.com/en-us/library/aa562961.aspx
52
+ # @param cancel_type [String] 'SendToNone'/'SendOnlyToAll'/'SendToAllAndSaveCopy'
53
+ # Default is 'SendOnlyToAll'
54
+ # @return [Boolean] Whether or not the calendar item was deleted
55
+ def delete!(deltype = :hard, cancel_type = 'SendOnlyToAll', opts = {})
56
+ opts = opts.merge(send_meeting_cancellations: cancel_type)
57
+ super(deltype, opts)
58
+ end
59
+
60
+ # Updates the specified item attributes
61
+ #
62
+ # Uses `SetItemField` if value is present and `DeleteItemField` if value is nil
63
+ # @param updates [Hash] with (:attribute => value)
64
+ # @param options [Hash]
65
+ # @option options :conflict_resolution [String] one of 'NeverOverwrite', 'AutoResolve' (default)
66
+ # or 'AlwaysOverwrite'
67
+ # @option options :send_meeting_invitations_or_cancellations [String] one of 'SendToNone' (default),
68
+ # 'SendOnlyToAll',
69
+ # 'SendOnlyToChanged', 'SendToAllAndSaveCopy' or 'SendToChangedAndSaveCopy'
70
+ # @return [CalendarItem, false]
71
+ # @example Update Subject and Body
72
+ # item = #...
73
+ # item.update_item!(subject: 'New subject', body: 'New Body')
74
+ # @see http://msdn.microsoft.com/en-us/library/exchange/aa580254.aspx
75
+ # @todo AppendToItemField updates not implemented
76
+ def update_item!(updates, options = {})
77
+ item_updates = []
78
+ updates.each do |attribute, value|
79
+ item_field = FIELD_URIS[attribute][:text] if FIELD_URIS.include? attribute
80
+ field = { field_uRI: { field_uRI: item_field } }
81
+
82
+ if value.nil? && item_field
83
+ # Build DeleteItemField Change
84
+ item_updates << { delete_item_field: field }
85
+ elsif item_field
86
+ # Build SetItemField Change
87
+ item = Viewpoint::EWS::Template::CalendarItem.new(attribute => value)
88
+
89
+ # Remap attributes because ews_builder #dispatch_field_item! uses #build_xml!
90
+ item_attributes = item.to_ews_item.map { |name, value|
91
+ if value.is_a? String
92
+ { name => { text: value } }
93
+ elsif value.is_a? Hash
94
+ node = { name => {} }
95
+ value.each do |attrib_key, attrib_value|
96
+ attrib_key = camel_case(attrib_key) unless attrib_key == :text
97
+ node[name][attrib_key] = attrib_value
98
+ end
99
+ node
100
+ else
101
+ { name => value }
102
+ end
103
+ }
104
+
105
+ item_updates << { set_item_field: field.merge(calendar_item: { sub_elements: item_attributes }) }
83
106
  end
84
107
  end
85
108
 
86
- item_updates << {set_item_field: field.merge(calendar_item: {sub_elements: item_attributes})}
87
- else
88
- # Ignore unknown attribute
89
- end
90
- end
91
-
92
- if item_updates.any?
93
- data = {}
94
- data[:conflict_resolution] = options[:conflict_resolution] || 'AutoResolve'
95
- data[:send_meeting_invitations_or_cancellations] = options[:send_meeting_invitations_or_cancellations] || 'SendToNone'
96
- data[:item_changes] = [{item_id: self.item_id, updates: item_updates}]
97
- rm = ews.update_item(data).response_messages.first
98
- if rm && rm.success?
99
- self.get_all_properties!
100
- self
101
- else
102
- raise EwsCreateItemError, "Could not update calendar item. #{rm.code}: #{rm.message_text}" unless rm
103
- end
104
- end
109
+ return unless item_updates.any?
105
110
 
106
- end
111
+ data = {}
112
+ data[:conflict_resolution] = options[:conflict_resolution] || 'AutoResolve'
113
+ data[:send_meeting_invitations_or_cancellations] =
114
+ options[:send_meeting_invitations_or_cancellations] || 'SendToNone'
115
+ data[:item_changes] = [{ item_id: item_id, updates: item_updates }]
116
+ rm = ews.update_item(data).response_messages.first
117
+ if rm&.success?
118
+ get_all_properties!
119
+ self
120
+ else
121
+ raise EwsCreateItemError, "Could not update calendar item. #{rm.code}: #{rm.message_text}" if rm
107
122
 
108
- def duration_in_seconds
109
- iso8601_duration_to_seconds(duration)
110
- end
123
+ raise EwsCreateItemError, 'Could not update calendar item.'
111
124
 
125
+ end
126
+ end
112
127
 
113
- private
128
+ def duration_in_seconds
129
+ iso8601_duration_to_seconds(duration)
130
+ end
114
131
 
132
+ private
115
133
 
116
- def key_paths
117
- super.merge(CALENDAR_ITEM_KEY_PATHS)
118
- end
134
+ def key_paths
135
+ super.merge(CALENDAR_ITEM_KEY_PATHS)
136
+ end
119
137
 
120
- def key_types
121
- super.merge(CALENDAR_ITEM_KEY_TYPES)
122
- end
138
+ def key_types
139
+ super.merge(CALENDAR_ITEM_KEY_TYPES)
140
+ end
123
141
 
124
- def key_alias
125
- super.merge(CALENDAR_ITEM_KEY_ALIAS)
142
+ def key_alias
143
+ super.merge(CALENDAR_ITEM_KEY_ALIAS)
144
+ end
145
+ end
126
146
  end
127
-
128
-
129
147
  end
130
148
  end
@@ -1,7 +1,13 @@
1
- module Viewpoint::EWS::Types
2
- class Contact
3
- include Viewpoint::EWS
4
- include Viewpoint::EWS::Types
5
- include Viewpoint::EWS::Types::Item
1
+ # frozen_string_literal: true
2
+
3
+ module Viewpoint
4
+ module EWS
5
+ module Types
6
+ class Contact
7
+ include Viewpoint::EWS
8
+ include Viewpoint::EWS::Types
9
+ include Viewpoint::EWS::Types::Item
10
+ end
11
+ end
6
12
  end
7
13
  end
@@ -1,8 +1,13 @@
1
- module Viewpoint::EWS::Types
2
- class ContactsFolder
3
- include Viewpoint::EWS
4
- include Viewpoint::EWS::Types
5
- include Viewpoint::EWS::Types::GenericFolder
1
+ # frozen_string_literal: true
6
2
 
3
+ module Viewpoint
4
+ module EWS
5
+ module Types
6
+ class ContactsFolder
7
+ include Viewpoint::EWS
8
+ include Viewpoint::EWS::Types
9
+ include Viewpoint::EWS::Types::GenericFolder
10
+ end
11
+ end
7
12
  end
8
13
  end