viewpoint 0.1.27 → 1.0.0.beta.1

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 (93) hide show
  1. data/README.md +196 -0
  2. data/lib/ews/calendar_accessors.rb +34 -0
  3. data/lib/ews/connection.rb +117 -0
  4. data/lib/ews/connection_helper.rb +35 -0
  5. data/lib/ews/ews_client.rb +71 -0
  6. data/lib/ews/exceptions/exceptions.rb +59 -0
  7. data/lib/ews/folder_accessors.rb +199 -0
  8. data/lib/ews/item_accessors.rb +157 -0
  9. data/lib/ews/mailbox_accessors.rb +87 -0
  10. data/lib/ews/message_accessors.rb +86 -0
  11. data/lib/ews/push_subscription_accessors.rb +33 -0
  12. data/lib/ews/soap.rb +63 -0
  13. data/lib/ews/soap/builders/ews_builder.rb +1011 -0
  14. data/lib/ews/soap/ews_response.rb +83 -0
  15. data/lib/ews/soap/ews_soap_availability_response.rb +58 -0
  16. data/lib/ews/soap/ews_soap_free_busy_response.rb +109 -0
  17. data/lib/ews/soap/ews_soap_response.rb +103 -0
  18. data/lib/ews/soap/exchange_availability.rb +61 -0
  19. data/lib/ews/soap/exchange_data_services.rb +742 -0
  20. data/lib/ews/soap/exchange_notification.rb +146 -0
  21. data/lib/ews/soap/exchange_user_configuration.rb +33 -0
  22. data/lib/ews/soap/exchange_web_service.rb +294 -0
  23. data/lib/{model/attendee.rb → ews/soap/parsers/ews_parser.rb} +20 -14
  24. data/lib/ews/soap/parsers/ews_sax_document.rb +66 -0
  25. data/lib/ews/soap/response_message.rb +78 -0
  26. data/lib/ews/soap/responses/create_attachment_response_message.rb +46 -0
  27. data/lib/{model/meeting_message.rb → ews/soap/responses/create_item_response_message.rb} +7 -10
  28. data/lib/ews/soap/responses/find_item_response_message.rb +80 -0
  29. data/lib/ews/soap/responses/get_events_response_message.rb +53 -0
  30. data/lib/ews/soap/responses/send_notification_response_message.rb +58 -0
  31. data/lib/{model/attachment.rb → ews/soap/responses/subscribe_response_message.rb} +17 -13
  32. data/lib/ews/templates/forward_item.rb +24 -0
  33. data/lib/ews/templates/message.rb +66 -0
  34. data/lib/ews/templates/reply_to_item.rb +25 -0
  35. data/lib/ews/types.rb +146 -0
  36. data/lib/ews/types/attachment.rb +77 -0
  37. data/lib/{model/meeting_cancellation.rb → ews/types/attendee.rb} +9 -8
  38. data/lib/ews/types/calendar_folder.rb +8 -0
  39. data/lib/ews/types/calendar_item.rb +37 -0
  40. data/lib/ews/types/contact.rb +7 -0
  41. data/lib/ews/types/contacts_folder.rb +8 -0
  42. data/lib/ews/types/copied_event.rb +51 -0
  43. data/lib/{soap/handsoap/builder.rb → ews/types/created_event.rb} +5 -2
  44. data/lib/{model/meeting_response.rb → ews/types/deleted_event.rb} +6 -6
  45. data/lib/ews/types/distribution_list.rb +7 -0
  46. data/lib/ews/types/event.rb +62 -0
  47. data/lib/ews/types/file_attachment.rb +65 -0
  48. data/lib/ews/types/folder.rb +60 -0
  49. data/lib/{model/distribution_list.rb → ews/types/free_busy_changed_event.rb} +6 -6
  50. data/lib/ews/types/generic_folder.rb +352 -0
  51. data/lib/ews/types/item.rb +381 -0
  52. data/lib/ews/types/item_attachment.rb +46 -0
  53. data/lib/{model → ews/types}/item_field_uri_map.rb +2 -2
  54. data/lib/ews/types/mailbox_user.rb +156 -0
  55. data/lib/ews/types/meeting_cancellation.rb +7 -0
  56. data/lib/ews/types/meeting_message.rb +7 -0
  57. data/lib/ews/types/meeting_request.rb +7 -0
  58. data/lib/ews/types/meeting_response.rb +7 -0
  59. data/lib/ews/types/message.rb +7 -0
  60. data/lib/ews/types/modified_event.rb +48 -0
  61. data/lib/{model/item_attachment.rb → ews/types/moved_event.rb} +33 -15
  62. data/lib/ews/types/new_mail_event.rb +24 -0
  63. data/lib/ews/types/out_of_office.rb +147 -0
  64. data/lib/ews/types/search_folder.rb +8 -0
  65. data/lib/ews/types/status_event.rb +39 -0
  66. data/lib/ews/types/task.rb +7 -0
  67. data/lib/ews/types/tasks_folder.rb +8 -0
  68. data/lib/viewpoint.rb +82 -106
  69. metadata +99 -67
  70. data/README +0 -114
  71. data/lib/exceptions/exceptions.rb +0 -46
  72. data/lib/model/calendar_folder.rb +0 -67
  73. data/lib/model/calendar_item.rb +0 -267
  74. data/lib/model/contact.rb +0 -238
  75. data/lib/model/contacts_folder.rb +0 -46
  76. data/lib/model/event.rb +0 -116
  77. data/lib/model/file_attachment.rb +0 -53
  78. data/lib/model/folder.rb +0 -47
  79. data/lib/model/generic_folder.rb +0 -471
  80. data/lib/model/item.rb +0 -313
  81. data/lib/model/mailbox_user.rb +0 -146
  82. data/lib/model/meeting_request.rb +0 -39
  83. data/lib/model/message.rb +0 -142
  84. data/lib/model/model.rb +0 -269
  85. data/lib/model/search_folder.rb +0 -48
  86. data/lib/model/task.rb +0 -121
  87. data/lib/model/tasks_folder.rb +0 -44
  88. data/lib/soap/handsoap/builders/ews_build_helpers.rb +0 -383
  89. data/lib/soap/handsoap/builders/ews_builder.rb +0 -146
  90. data/lib/soap/handsoap/ews_service.rb +0 -813
  91. data/lib/soap/handsoap/parser.rb +0 -104
  92. data/lib/soap/handsoap/parsers/ews_parser.rb +0 -246
  93. data/lib/soap/soap_provider.rb +0 -64
@@ -16,16 +16,20 @@
16
16
  limitations under the License.
17
17
  =end
18
18
 
19
- module Viewpoint
20
- module EWS
21
- # A generic Attachment. This class should not be instantiated directly. You
22
- # should use one of the subclasses like FileAttachment or ItemAttachment.
23
- class Attachment
24
- include Model
25
-
26
- # All Attachment types will have an id.
27
- attr_reader :id
28
-
29
- end # Attachment
30
- end # EWS
31
- end # Viewpoint
19
+ module Viewpoint::EWS::SOAP
20
+ class SubscribeResponseMessage < ResponseMessage
21
+
22
+ def subscription
23
+ safe_hash_access message, [:elems]
24
+ end
25
+
26
+ def subscription_id
27
+ safe_hash_access subscription, [:subscription_id, :text]
28
+ end
29
+
30
+ def watermark
31
+ safe_hash_access subscription, [:watermark, :text]
32
+ end
33
+
34
+ end # SubscribeResponseMessage
35
+ end # Viewpoint::EWS::SOAP
@@ -0,0 +1,24 @@
1
+ module Viewpoint::EWS
2
+ module Template
3
+ class ForwardItem < Message
4
+
5
+ # Format this object for EWS backend consumption.
6
+ def to_ews
7
+ ews_opts, msg = to_ews_basic
8
+ msg[:reference_item_id] = reference_item_id
9
+ msg[:new_body_content] = {text: new_body_content, body_type: new_body_type}
10
+ ews_opts.merge({items: [{forward_item: msg}]})
11
+ end
12
+
13
+ private
14
+
15
+
16
+ def init_defaults!
17
+ super
18
+ self.new_body_content ||= ''
19
+ self.new_body_type ||= 'Text'
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,66 @@
1
+ module Viewpoint::EWS
2
+ module Template
3
+ class Message < OpenStruct
4
+
5
+ def initialize(opts = {})
6
+ super opts.clone
7
+ init_defaults!
8
+ end
9
+
10
+ # Format this object for EWS backend consumption.
11
+ def to_ews
12
+ ews_opts, msg = to_ews_basic
13
+ ews_opts.merge({items: [{message: msg}]})
14
+ end
15
+
16
+ def has_attachments?
17
+ !(file_attachments.empty? && item_attachments.empty?)
18
+ end
19
+
20
+
21
+ private
22
+
23
+
24
+ def init_defaults!
25
+ self.subject ||= nil
26
+ self.body ||= nil
27
+ self.body_type ||= 'Text'
28
+ self.draft ||= false
29
+ self.to_recipients ||= []
30
+ self.cc_recipients ||= []
31
+ self.bcc_recipients ||= []
32
+ self.file_attachments ||= []
33
+ self.item_attachments ||= []
34
+ end
35
+
36
+ def to_ews_basic
37
+ ews_opts = {}
38
+ ews_opts[:message_disposition] = (draft ? 'SaveOnly' : 'SendAndSaveCopy')
39
+
40
+ if saved_item_folder_id
41
+ if saved_item_folder_id.kind_of?(Hash)
42
+ ews_opts[:saved_item_folder_id] = saved_item_folder_id
43
+ else
44
+ ews_opts[:saved_item_folder_id] = {id: saved_item_folder_id}
45
+ end
46
+ end
47
+
48
+ msg = {}
49
+ msg[:subject] = subject if subject
50
+ msg[:body] = {text: body, body_type: body_type} if body
51
+
52
+ to_r = to_recipients.collect{|r| {mailbox: {email_address: r}}}
53
+ msg[:to_recipients] = to_r unless to_r.empty?
54
+
55
+ cc_r = cc_recipients.collect{|r| {mailbox: {email_address: r}}}
56
+ msg[:cc_recipients] = cc_r unless cc_r.empty?
57
+
58
+ bcc_r = bcc_recipients.collect{|r| {mailbox: {email_address: r}}}
59
+ msg[:bcc_recipients] = bcc_r unless bcc_r.empty?
60
+
61
+ [ews_opts, msg]
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,25 @@
1
+ module Viewpoint::EWS
2
+ module Template
3
+ class ReplyToItem < Message
4
+
5
+ # Format this object for EWS backend consumption.
6
+ def to_ews
7
+ ews_opts, msg = to_ews_basic
8
+ msg[:reference_item_id] = reference_item_id
9
+ msg[:new_body_content] = {text: new_body_content, body_type: new_body_type}
10
+ ews_opts.merge({items: [{ews_type => msg}]})
11
+ end
12
+
13
+ private
14
+
15
+
16
+ def init_defaults!
17
+ super
18
+ self.new_body_content ||= ''
19
+ self.new_body_type ||= 'Text'
20
+ self.ews_type = :reply_to_item
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,146 @@
1
+ module Viewpoint::EWS
2
+ module Types
3
+
4
+ KEY_PATHS = {
5
+ extended_properties: [:extended_property],
6
+ }
7
+ KEY_TYPES = {
8
+ extended_properties: :build_extended_properties,
9
+ }
10
+ KEY_ALIAS = {}
11
+
12
+ attr_reader :ews_item
13
+
14
+ # @param [SOAP::ExchangeWebService] ews the EWS reference
15
+ # @param [Hash] ews_item the EWS parsed response document
16
+ def initialize(ews, ews_item)
17
+ @ews = ews
18
+ @ews_item = ews_item
19
+ @shallow = true
20
+ end
21
+
22
+ def method_missing(method_sym, *arguments, &block)
23
+ if method_keys.include?(method_sym)
24
+ type_convert( method_sym, resolve_method(method_sym) )
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ def to_s
31
+ "#{self.class.name}: EWS METHODS: #{self.ews_methods.sort.join(', ')}"
32
+ end
33
+
34
+ def shallow?
35
+ @shallow
36
+ end
37
+
38
+ def mark_deep!
39
+ @shallow = false
40
+ end
41
+
42
+ def auto_deepen?
43
+ ews.auto_deepen
44
+ end
45
+
46
+ def deepen!
47
+ if shallow?
48
+ self.get_all_properties!
49
+ @shallow = false
50
+ true
51
+ end
52
+ end
53
+ alias_method :enlighten!, :deepen!
54
+
55
+ # @see http://www.ruby-doc.org/core/classes/Object.html#M000333
56
+ def respond_to?(method_sym, include_private = false)
57
+ if method_keys.include?(method_sym)
58
+ true
59
+ else
60
+ super
61
+ end
62
+ end
63
+
64
+ def methods(include_super = true)
65
+ super + ews_methods
66
+ end
67
+
68
+ def ews_methods
69
+ key_paths.keys + key_alias.keys
70
+ end
71
+
72
+ protected # things like OutOfOffice need protected level access
73
+
74
+ def ews
75
+ @ews
76
+ end
77
+
78
+ private
79
+
80
+ def key_paths
81
+ KEY_PATHS
82
+ end
83
+
84
+ def key_types
85
+ KEY_TYPES
86
+ end
87
+
88
+ def key_alias
89
+ KEY_ALIAS
90
+ end
91
+
92
+ def class_by_name(cname)
93
+ if(cname.instance_of? Symbol)
94
+ cname = cname.to_s.camel_case
95
+ end
96
+ Viewpoint::EWS::Types.const_get(cname)
97
+ end
98
+
99
+ def type_convert(key,str)
100
+ return nil if str.nil?
101
+ key = key_alias[key] || key
102
+ if key_types[key]
103
+ key_types[key].is_a?(Symbol) ? method(key_types[key]).call(str) : key_types[key].call(str)
104
+ else
105
+ str
106
+ end
107
+ end
108
+
109
+ def resolve_method(method_sym)
110
+ begin
111
+ resolve_key_path(@ews_item, method_path(method_sym))
112
+ rescue
113
+ if shallow?
114
+ if auto_deepen?
115
+ enlighten!
116
+ retry
117
+ else
118
+ raise EwsMinimalObjectError, "Could not resolve :#{method_sym}. #auto_deepen set to false"
119
+ end
120
+ else
121
+ nil
122
+ end
123
+ end
124
+ end
125
+
126
+ def resolve_key_path(hsh, path)
127
+ k = path.first
128
+ return hsh[k] if path.length == 1
129
+ resolve_key_path(hsh[k],path[1..-1])
130
+ end
131
+
132
+ def method_keys
133
+ key_paths.keys + key_alias.keys
134
+ end
135
+
136
+ # Resolve the method path with or without an alias
137
+ def method_path(sym)
138
+ key_paths[key_alias[sym] || sym]
139
+ end
140
+
141
+ def build_extended_properties(eprops)
142
+ eprops.collect.collect {|e| e[:elems]}
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,77 @@
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)
52
+ 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
+ end
77
+ end
@@ -16,11 +16,12 @@
16
16
  limitations under the License.
17
17
  =end
18
18
 
19
- module Viewpoint
20
- module EWS
21
- # Meeting cancellations have the exact same elements as a Meeting Message
22
- # so MeetingCancellation is just a subclass of that.
23
- class MeetingCancellation < MeetingMessage
24
- end # MeetingCancellation
25
- end # EWS
26
- end # Viewpoint
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
@@ -0,0 +1,8 @@
1
+ module Viewpoint::EWS::Types
2
+ class CalendarFolder
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::GenericFolder
6
+
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module Viewpoint::EWS::Types
2
+ class CalendarItem
3
+ include Viewpoint::EWS
4
+ include Viewpoint::EWS::Types
5
+ include Viewpoint::EWS::Types::Item
6
+
7
+ CALENDAR_ITEM_KEY_PATHS = {
8
+ recurring?: [:is_recurring, :text],
9
+ meeting?: [:is_meeting, :text],
10
+ cancelled?: [:is_cancelled, :text],
11
+ }
12
+
13
+ CALENDAR_ITEM_KEY_TYPES = {
14
+ recurring?: ->(str){str.downcase == 'true'},
15
+ meeting?: ->(str){str.downcase == 'true'},
16
+ cancelled?: ->(str){str.downcase == 'true'},
17
+ }
18
+ CALENDAR_ITEM_KEY_ALIAS = {}
19
+
20
+
21
+ private
22
+
23
+ def key_paths
24
+ super.merge(CALENDAR_ITEM_KEY_PATHS)
25
+ end
26
+
27
+ def key_types
28
+ super.merge(CALENDAR_ITEM_KEY_TYPES)
29
+ end
30
+
31
+ def key_alias
32
+ super.merge(CALENDAR_ITEM_KEY_ALIAS)
33
+ end
34
+
35
+
36
+ end
37
+ end