viewpoint2 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +216 -0
  3. data/lib/ews/calendar_accessors.rb +34 -0
  4. data/lib/ews/connection.rb +130 -0
  5. data/lib/ews/connection_helper.rb +35 -0
  6. data/lib/ews/convert_accessors.rb +56 -0
  7. data/lib/ews/errors.rb +56 -0
  8. data/lib/ews/ews_client.rb +103 -0
  9. data/lib/ews/exceptions/exceptions.rb +61 -0
  10. data/lib/ews/folder_accessors.rb +264 -0
  11. data/lib/ews/impersonation.rb +30 -0
  12. data/lib/ews/item_accessors.rb +231 -0
  13. data/lib/ews/mailbox_accessors.rb +99 -0
  14. data/lib/ews/message_accessors.rb +93 -0
  15. data/lib/ews/push_subscription_accessors.rb +33 -0
  16. data/lib/ews/room_accessors.rb +48 -0
  17. data/lib/ews/roomlist_accessors.rb +47 -0
  18. data/lib/ews/soap.rb +64 -0
  19. data/lib/ews/soap/builders/ews_builder.rb +1351 -0
  20. data/lib/ews/soap/ews_response.rb +84 -0
  21. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  22. data/lib/ews/soap/ews_soap_free_busy_response.rb +119 -0
  23. data/lib/ews/soap/ews_soap_response.rb +103 -0
  24. data/lib/ews/soap/ews_soap_room_response.rb +53 -0
  25. data/lib/ews/soap/ews_soap_roomlist_response.rb +54 -0
  26. data/lib/ews/soap/exchange_availability.rb +61 -0
  27. data/lib/ews/soap/exchange_data_services.rb +780 -0
  28. data/lib/ews/soap/exchange_notification.rb +146 -0
  29. data/lib/ews/soap/exchange_synchronization.rb +93 -0
  30. data/lib/ews/soap/exchange_time_zones.rb +56 -0
  31. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  32. data/lib/ews/soap/exchange_web_service.rb +264 -0
  33. data/lib/ews/soap/parsers/ews_parser.rb +43 -0
  34. data/lib/ews/soap/parsers/ews_sax_document.rb +70 -0
  35. data/lib/ews/soap/response_message.rb +80 -0
  36. data/lib/ews/soap/responses/create_attachment_response_message.rb +47 -0
  37. data/lib/ews/soap/responses/create_item_response_message.rb +25 -0
  38. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  39. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  40. data/lib/ews/soap/responses/send_notification_response_message.rb +59 -0
  41. data/lib/ews/soap/responses/subscribe_response_message.rb +35 -0
  42. data/lib/ews/soap/responses/sync_folder_hierarchy_response_message.rb +36 -0
  43. data/lib/ews/soap/responses/sync_folder_items_response_message.rb +36 -0
  44. data/lib/ews/templates/calendar_item.rb +79 -0
  45. data/lib/ews/templates/forward_item.rb +24 -0
  46. data/lib/ews/templates/message.rb +76 -0
  47. data/lib/ews/templates/reply_to_item.rb +25 -0
  48. data/lib/ews/templates/task.rb +74 -0
  49. data/lib/ews/types.rb +194 -0
  50. data/lib/ews/types/attachment.rb +77 -0
  51. data/lib/ews/types/attendee.rb +41 -0
  52. data/lib/ews/types/calendar_folder.rb +50 -0
  53. data/lib/ews/types/calendar_item.rb +133 -0
  54. data/lib/ews/types/contact.rb +7 -0
  55. data/lib/ews/types/contacts_folder.rb +8 -0
  56. data/lib/ews/types/copied_event.rb +51 -0
  57. data/lib/ews/types/created_event.rb +24 -0
  58. data/lib/ews/types/deleted_event.rb +24 -0
  59. data/lib/ews/types/distribution_list.rb +7 -0
  60. data/lib/ews/types/event.rb +62 -0
  61. data/lib/ews/types/export_items_response_message.rb +52 -0
  62. data/lib/ews/types/file_attachment.rb +65 -0
  63. data/lib/ews/types/folder.rb +60 -0
  64. data/lib/ews/types/free_busy_changed_event.rb +24 -0
  65. data/lib/ews/types/generic_folder.rb +418 -0
  66. data/lib/ews/types/item.rb +450 -0
  67. data/lib/ews/types/item_attachment.rb +84 -0
  68. data/lib/ews/types/item_field_uri_map.rb +208 -0
  69. data/lib/ews/types/mailbox_user.rb +156 -0
  70. data/lib/ews/types/meeting_cancellation.rb +7 -0
  71. data/lib/ews/types/meeting_message.rb +7 -0
  72. data/lib/ews/types/meeting_request.rb +7 -0
  73. data/lib/ews/types/meeting_response.rb +7 -0
  74. data/lib/ews/types/message.rb +7 -0
  75. data/lib/ews/types/modified_event.rb +48 -0
  76. data/lib/ews/types/moved_event.rb +51 -0
  77. data/lib/ews/types/new_mail_event.rb +24 -0
  78. data/lib/ews/types/out_of_office.rb +147 -0
  79. data/lib/ews/types/post_item.rb +7 -0
  80. data/lib/ews/types/search_folder.rb +8 -0
  81. data/lib/ews/types/status_event.rb +39 -0
  82. data/lib/ews/types/task.rb +104 -0
  83. data/lib/ews/types/tasks_folder.rb +27 -0
  84. data/lib/viewpoint/logging.rb +27 -0
  85. data/lib/viewpoint/logging/config.rb +24 -0
  86. data/lib/viewpoint/string_utils.rb +76 -0
  87. data/lib/viewpoint2.rb +111 -0
  88. metadata +191 -0
@@ -0,0 +1,51 @@
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
+
21
+ class MovedEvent < Event
22
+
23
+ MOVED_EVENT_KEY_PATHS = {
24
+ :old_item_id => [:old_item_id, :attribs],
25
+ :old_folder_id => [:old_folder_id, :attribs],
26
+ :old_parent_folder_id => [:old_parent_folder_id, :attribs],
27
+ }
28
+
29
+ MOVED_EVENT_KEY_TYPES = {
30
+ }
31
+
32
+ MOVED_EVENT_KEY_ALIAS = { }
33
+
34
+
35
+ private
36
+
37
+
38
+ def key_paths
39
+ @key_paths ||= super.merge MOVED_EVENT_KEY_PATHS
40
+ end
41
+
42
+ def key_types
43
+ @key_types ||= super.merge MOVED_EVENT_KEY_TYPES
44
+ end
45
+
46
+ def key_alias
47
+ @key_alias ||= super.merge MOVED_EVENT_KEY_ALIAS
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,24 @@
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
+
21
+ class NewMailEvent < Event
22
+
23
+ end
24
+ end
@@ -0,0 +1,147 @@
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
+
21
+ OOF_KEY_PATHS = {
22
+ :enabled? => [:oof_settings, :oof_state],
23
+ :scheduled? => [:oof_settings, :oof_state],
24
+ :duration => [:oof_settings, :duration],
25
+ }
26
+
27
+ OOF_KEY_TYPES = {
28
+ :enabled? => ->(str){str == :enabled},
29
+ :scheduled? => ->(str){str == :scheduled},
30
+ :duration => ->(hsh){ hsh[:start_time]..hsh[:end_time] },
31
+ }
32
+
33
+ OOF_KEY_ALIAS = {}
34
+
35
+ # This represents OutOfOffice settings
36
+ # @see http://msdn.microsoft.com/en-us/library/aa563465.aspx
37
+ class OutOfOffice
38
+ include Viewpoint::EWS
39
+ include Viewpoint::EWS::Types
40
+
41
+ attr_reader :user
42
+
43
+ # @param [MailboxUser] user
44
+ # @param [Hash] ews_item
45
+ def initialize(user, ews_item)
46
+ @ews = user.ews
47
+ @user = user
48
+ @ews_item = ews_item
49
+ @changed = false
50
+ simplify!
51
+ end
52
+
53
+ def changed?
54
+ @changed
55
+ end
56
+
57
+ def save!
58
+ return true unless changed?
59
+ opts = { mailbox: {address: user.email_address} }.merge(@ews_item[:oof_settings])
60
+ resp = @ews.set_user_oof_settings(opts)
61
+ if resp.success?
62
+ @changed = false
63
+ true
64
+ else
65
+ raise SaveFailed, "Could not save #{self.class}. #{resp.code}: #{resp.message}"
66
+ end
67
+ end
68
+
69
+ def enable
70
+ return true if enabled?
71
+ @changed = true
72
+ @ews_item[:oof_settings][:oof_state] = :enabled
73
+ end
74
+
75
+ def disable
76
+ return true unless enabled? || scheduled?
77
+ @changed = true
78
+ @ews_item[:oof_settings][:oof_state] = :disabled
79
+ end
80
+
81
+ # Schedule an out of office.
82
+ # @param [DateTime] start_time
83
+ # @param [DateTime] end_time
84
+ def schedule(start_time, end_time)
85
+ @changed = true
86
+ @ews_item[:oof_settings][:oof_state] = :scheduled
87
+ set_duration start_time, end_time
88
+ end
89
+
90
+ # Specify a duration for this Out Of Office setting
91
+ # @param [DateTime] start_time
92
+ # @param [DateTime] end_time
93
+ def set_duration(start_time, end_time)
94
+ @changed = true
95
+ @ews_item[:oof_settings][:duration][:start_time] = start_time
96
+ @ews_item[:oof_settings][:duration][:end_time] = end_time
97
+ end
98
+
99
+ # A message to send to internal users
100
+ # @param [String] message
101
+ def internal_reply=(message)
102
+ @changed = true
103
+ @ews_item[:oof_settings][:internal_reply] = message
104
+ end
105
+
106
+ # A message to send to external users
107
+ # @param [String] message
108
+ def external_reply=(message)
109
+ @changed = true
110
+ @ews_item[:oof_settings][:external_reply] = message
111
+ end
112
+
113
+
114
+ private
115
+
116
+ def key_paths
117
+ @key_paths ||= super.merge(OOF_KEY_PATHS)
118
+ end
119
+
120
+ def key_types
121
+ @key_types ||= super.merge(OOF_KEY_TYPES)
122
+ end
123
+
124
+ def key_alias
125
+ @key_alias ||= super.merge(OOF_KEY_ALIAS)
126
+ end
127
+
128
+ def simplify!
129
+ oof_settings = @ews_item[:oof_settings][:elems].inject(:merge)
130
+ oof_settings[:oof_state] = oof_settings[:oof_state][:text].downcase.to_sym
131
+ oof_settings[:external_audience] = oof_settings[:external_audience][:text]
132
+ if oof_settings[:duration]
133
+ dur = oof_settings[:duration][:elems].inject(:merge)
134
+ oof_settings[:duration] = {
135
+ start_time: DateTime.iso8601(dur[:start_time][:text]),
136
+ end_time: DateTime.iso8601(dur[:end_time][:text])
137
+ }
138
+ end
139
+ oof_settings[:internal_reply] = oof_settings[:internal_reply][:elems][0][:message][:text] || ""
140
+ oof_settings[:external_reply] = oof_settings[:external_reply][:elems][0][:message][:text] || ""
141
+ @ews_item[:oof_settings] = oof_settings
142
+ @ews_item[:allow_external_oof] = @ews_item[:allow_external_oof][:text]
143
+ end
144
+
145
+ end #OutOfOffice
146
+
147
+ end
@@ -0,0 +1,7 @@
1
+ module Viewpoint::EWS::Types
2
+ class PostItem
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::Item
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module Viewpoint::EWS::Types
2
+ class SearchFolder
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::GenericFolder
6
+
7
+ end
8
+ end
@@ -0,0 +1,39 @@
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
+
21
+ class StatusEvent
22
+ include Viewpoint::EWS
23
+ include Viewpoint::EWS::Types
24
+ include Viewpoint::EWS::Types::Item
25
+
26
+ STATUS_EVENT_KEY_PATHS = {
27
+ :watermark => [:watermark, :text],
28
+ }
29
+
30
+
31
+ private
32
+
33
+
34
+ def key_paths
35
+ @key_paths ||= STATUS_EVENT_KEY_PATHS
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,104 @@
1
+ module Viewpoint::EWS::Types
2
+ class Task
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::Item
6
+
7
+ TASK_KEY_PATHS = {
8
+ complete?: [:is_complete, :text],
9
+ recurring?: [:is_recurring, :text],
10
+ start_date: [:start_date, :text],
11
+ due_date: [:due_date, :text],
12
+ reminder_due_by: [:reminder_due_by, :text],
13
+ reminder?: [:reminder_is_set, :text],
14
+ percent_complete: [:percent_complete, :text],
15
+ status: [:status, :text],
16
+ owner: [:owner, :text],
17
+ }
18
+
19
+ TASK_KEY_TYPES = {
20
+ recurring?: ->(str){str.downcase == 'true'},
21
+ complete?: ->(str){str.downcase == 'true'},
22
+ reminder?: ->(str){str.downcase == 'true'},
23
+ percent_complete: ->(str){str.to_i},
24
+ }
25
+ TASK_KEY_ALIAS = {}
26
+
27
+ # Updates the specified attributes
28
+ #
29
+ # @param updates [Hash] with (:attribute => value)
30
+ # @param options [Hash]
31
+ # @option options :conflict_resolution [String] one of 'NeverOverwrite', 'AutoResolve' (default) or 'AlwaysOverwrite'
32
+ # @return [Task, false]
33
+ # @example Update Subject and Body
34
+ # item = #...
35
+ # item.update_item!(subject: 'New subject', due_date: Time.parse('25.03.2013 12:00'))
36
+
37
+ def update_task!(updates, options = {})
38
+ item_updates = []
39
+ updates.each do |attribute, value|
40
+ item_field = FIELD_URIS[attribute][:text] if FIELD_URIS.include? attribute
41
+ field = {field_uRI: {field_uRI: item_field}}
42
+
43
+ if value.nil? && item_field
44
+ # Build DeleteItemField Change
45
+ item_updates << {delete_item_field: field}
46
+ elsif item_field
47
+ # Build SetItemField Change
48
+ item = Viewpoint::EWS::Template::Task.new(attribute => value)
49
+
50
+ # Remap attributes because ews_builder #dispatch_field_item! uses #build_xml!
51
+ item_attributes = item.to_ews_item.map do |name, value|
52
+ if value.is_a? String
53
+ {name => {text: value}}
54
+ elsif value.is_a? Hash
55
+ node = {name => {}}
56
+ value.each do |attrib_key, attrib_value|
57
+ attrib_key = camel_case(attrib_key) unless attrib_key == :text
58
+ node[name][attrib_key] = attrib_value
59
+ end
60
+ node
61
+ else
62
+ {name => value}
63
+ end
64
+ end
65
+
66
+ item_updates << {set_item_field: field.merge(task: {sub_elements: item_attributes})}
67
+ else
68
+ # Ignore unknown attribute
69
+ end
70
+ end
71
+
72
+ if item_updates.any?
73
+ data = {}
74
+ data[:conflict_resolution] = options[:conflict_resolution] || 'AlwaysOverwrite'
75
+ data[:item_changes] = [{item_id: self.item_id, updates: item_updates}]
76
+ response_message = ews.update_item(data).response_messages.first
77
+ if response_message && response_message.success?
78
+ self.get_all_properties!
79
+ self
80
+ elsif response_message
81
+ raise EwsCreateItemError, "Could not update task. #{response_message.code}: #{response_message.message_text}"
82
+ else
83
+ raise StandardError("No response message received.")
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ private
90
+
91
+ def key_paths
92
+ super.merge(TASK_KEY_PATHS)
93
+ end
94
+
95
+ def key_types
96
+ super.merge(TASK_KEY_TYPES)
97
+ end
98
+
99
+ def key_alias
100
+ super.merge(TASK_KEY_ALIAS)
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,27 @@
1
+ module Viewpoint::EWS::Types
2
+ class TasksFolder
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::GenericFolder
6
+
7
+ # Creates a new task
8
+ # @param attributes [Hash] Parameters of the task. Some example attributes are listed below.
9
+ # @option attributes :subject [String]
10
+ # @option attributes :start_date [Time]
11
+ # @option attributes :due_date [Time]
12
+ # @option attributes :reminder_due_by [Time]
13
+ # @option attributes :reminder_is_set [Boolean]
14
+ # @return [Task]
15
+ # @see Template::Task
16
+ def create_item(attributes)
17
+ template = Viewpoint::EWS::Template::Task.new attributes
18
+ template.saved_item_folder_id = {id: self.id, change_key: self.change_key}
19
+ rm = ews.create_item(template.to_ews_create).response_messages.first
20
+ if rm && rm.success?
21
+ Task.new ews, rm.items.first[:task][:elems].first
22
+ else
23
+ raise EwsCreateItemError, "Could not create item in folder. #{rm.code}: #{rm.message_text}" unless rm
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
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
20
+ module EWS
21
+ attr_reader :logger
22
+
23
+ def self.root_logger
24
+ Logging.logger.root
25
+ end
26
+ end # EWS
27
+ end
@@ -0,0 +1,24 @@
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
20
+ module EWS
21
+ Logging.logger.root.level = :debug
22
+ Logging.logger.root.appenders = Logging.appenders.stdout
23
+ end # EWS
24
+ end