zm-ruby-client 3.0.1 → 3.1.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 (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +96 -0
  3. data/README.md +128 -27
  4. data/VERSION +1 -1
  5. data/lib/zm/client/account/account.rb +12 -19
  6. data/lib/zm/client/account/account_aliases_collection.rb +6 -4
  7. data/lib/zm/client/account/account_dls_membership_collection.rb +4 -3
  8. data/lib/zm/client/account/account_dls_owner_collection.rb +3 -2
  9. data/lib/zm/client/account/account_jsns_builder.rb +10 -10
  10. data/lib/zm/client/account/accounts_collection.rb +27 -16
  11. data/lib/zm/client/ace/ace.rb +3 -6
  12. data/lib/zm/client/ace/ace_jsns_builder.rb +6 -6
  13. data/lib/zm/client/appointment/appointment.rb +32 -14
  14. data/lib/zm/client/appointment/appointment_jsns_builder.rb +5 -5
  15. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +6 -1
  16. data/lib/zm/client/appointment/appointments_collection.rb +12 -9
  17. data/lib/zm/client/backup/backup.rb +5 -2
  18. data/lib/zm/client/backup/backups_collection.rb +3 -2
  19. data/lib/zm/client/base/account_objects_collection.rb +1 -0
  20. data/lib/zm/client/base/account_search_objects_collection.rb +6 -6
  21. data/lib/zm/client/base/admin_objects_collection.rb +60 -7
  22. data/lib/zm/client/base/base_account_jsns_builder.rb +89 -87
  23. data/lib/zm/client/base/base_jsns_builder.rb +3 -3
  24. data/lib/zm/client/base/base_jsns_initializer.rb +20 -15
  25. data/lib/zm/client/base/mailbox_infos_collection.rb +92 -90
  26. data/lib/zm/client/base/mailbox_object.rb +49 -160
  27. data/lib/zm/client/base/mailbox_prefs_collection.rb +54 -52
  28. data/lib/zm/client/base/object.rb +19 -2
  29. data/lib/zm/client/base/objects_collection.rb +10 -10
  30. data/lib/zm/client/base/zimbra_attribute.rb +28 -42
  31. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -24
  32. data/lib/zm/client/{cluster/batch_request.rb → batch_request.rb} +1 -1
  33. data/lib/zm/client/cluster/cluster.rb +24 -61
  34. data/lib/zm/client/cluster/cluster_config.rb +35 -15
  35. data/lib/zm/client/contact/contact.rb +15 -13
  36. data/lib/zm/client/contact/contact_jsns_builder.rb +9 -6
  37. data/lib/zm/client/contact/contact_jsns_initializer.rb +2 -2
  38. data/lib/zm/client/contact/contact_member.rb +3 -3
  39. data/lib/zm/client/contact/contact_members_collection.rb +3 -3
  40. data/lib/zm/client/contact/contacts_builder.rb +1 -1
  41. data/lib/zm/client/contact/contacts_collection.rb +2 -2
  42. data/lib/zm/client/contact/group_contact_jsns_builder.rb +18 -14
  43. data/lib/zm/client/contact/mod_group_contact.rb +12 -8
  44. data/lib/zm/client/cos/cos.rb +15 -31
  45. data/lib/zm/client/cos/cos_jsns_builder.rb +21 -21
  46. data/lib/zm/client/cos/coses_collection.rb +11 -6
  47. data/lib/zm/client/datasource/datasource.rb +3 -9
  48. data/lib/zm/client/datasource/datasource_jsns_builder.rb +4 -4
  49. data/lib/zm/client/datasource/datasources_builder.rb +1 -1
  50. data/lib/zm/client/datasource/datasources_collection.rb +2 -2
  51. data/lib/zm/client/deprecated_constants.rb +36 -0
  52. data/lib/zm/client/distributionlist/distributionlist.rb +15 -47
  53. data/lib/zm/client/distributionlist/distributionlist_aces_collection.rb +4 -4
  54. data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +7 -5
  55. data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +29 -41
  56. data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +14 -3
  57. data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +14 -10
  58. data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +13 -13
  59. data/lib/zm/client/distributionlist/distributionlists_collection.rb +15 -7
  60. data/lib/zm/client/distributionlist/dls_membership_collection.rb +8 -6
  61. data/lib/zm/client/document/document.rb +5 -11
  62. data/lib/zm/client/document/document_jsns_builder.rb +2 -2
  63. data/lib/zm/client/document/documents_collection.rb +4 -4
  64. data/lib/zm/client/domain/domain.rb +8 -25
  65. data/lib/zm/client/domain/domain_jsns_builder.rb +13 -13
  66. data/lib/zm/client/domain/domains_collection.rb +13 -6
  67. data/lib/zm/client/filter_rules/filter_rules_collection.rb +1 -1
  68. data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +1 -1
  69. data/lib/zm/client/folder/folder.rb +34 -21
  70. data/lib/zm/client/folder/folder_default.rb +39 -0
  71. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +3 -3
  72. data/lib/zm/client/folder/folder_grants_collection.rb +1 -1
  73. data/lib/zm/client/folder/folder_jsns_builder.rb +12 -12
  74. data/lib/zm/client/folder/folder_jsns_initializer.rb +1 -1
  75. data/lib/zm/client/folder/folder_retention_policies_collection.rb +6 -2
  76. data/lib/zm/client/folder/folder_view.rb +15 -0
  77. data/lib/zm/client/folder/folders_jsns_builder.rb +1 -1
  78. data/lib/zm/client/folder/mod_document_folder.rb +16 -12
  79. data/lib/zm/client/identity/identities_collection.rb +1 -1
  80. data/lib/zm/client/identity/identity.rb +3 -9
  81. data/lib/zm/client/identity/identity_jsns_builder.rb +8 -8
  82. data/lib/zm/client/{base/ldap_filter.rb → ldap_filter.rb} +1 -1
  83. data/lib/zm/client/license/licenses_collection.rb +1 -1
  84. data/lib/zm/client/mailbox/mailbox_item_concern.rb +0 -2
  85. data/lib/zm/client/message/message.rb +14 -19
  86. data/lib/zm/client/message/message_attachments_collection.rb +39 -0
  87. data/lib/zm/client/message/message_flags_collection.rb +130 -0
  88. data/lib/zm/client/message/message_jsns_builder.rb +4 -8
  89. data/lib/zm/client/message/message_jsns_initializer.rb +4 -4
  90. data/lib/zm/client/message/message_recipients.rb +19 -43
  91. data/lib/zm/client/message/messages_collection.rb +20 -4
  92. data/lib/zm/client/mountpoint/{mountpoint.rb → mount_point.rb} +4 -10
  93. data/lib/zm/client/mountpoint/{mountpoint_jsns_builder.rb → mount_point_jsns_builder.rb} +3 -3
  94. data/lib/zm/client/mountpoint/{mountpoint_jsns_initializer.rb → mount_point_jsns_initializer.rb} +1 -1
  95. data/lib/zm/client/mountpoint/{mountpoints_builder.rb → mount_points_builder.rb} +1 -1
  96. data/lib/zm/client/mta_queue/mta_queue.rb +4 -16
  97. data/lib/zm/client/mta_queue/mta_queue_action.rb +12 -0
  98. data/lib/zm/client/mta_queue/mta_queue_jsns_builder.rb +7 -7
  99. data/lib/zm/client/mta_queue/mta_queue_name.rb +14 -0
  100. data/lib/zm/client/mta_queue/mta_queues_collection.rb +4 -3
  101. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +1 -0
  102. data/lib/zm/client/recipient.rb +21 -0
  103. data/lib/zm/client/{common/recipients.rb → recipients.rb} +0 -16
  104. data/lib/zm/client/resource/resource.rb +3 -7
  105. data/lib/zm/client/resource/resource_jsns_builder.rb +13 -13
  106. data/lib/zm/client/resource/resources_collection.rb +20 -7
  107. data/lib/zm/client/search_folder/search_folder.rb +4 -11
  108. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +6 -6
  109. data/lib/zm/client/search_folder/search_folders_collection.rb +1 -1
  110. data/lib/zm/client/server/server.rb +16 -22
  111. data/lib/zm/client/server/server_services.rb +26 -0
  112. data/lib/zm/client/server/servers_collection.rb +6 -6
  113. data/lib/zm/client/share/share.rb +2 -5
  114. data/lib/zm/client/share/shares_builder.rb +1 -1
  115. data/lib/zm/client/share/shares_collection.rb +5 -4
  116. data/lib/zm/client/signature/signature.rb +7 -13
  117. data/lib/zm/client/signature/signature_jsns_builder.rb +13 -13
  118. data/lib/zm/client/signature/signature_jsns_initializer.rb +2 -2
  119. data/lib/zm/client/signature/signatures_collection.rb +1 -1
  120. data/lib/zm/client/tag/account_object_tags_collection.rb +45 -47
  121. data/lib/zm/client/tag/tag.rb +3 -9
  122. data/lib/zm/client/tag/tag_jsns_builder.rb +3 -3
  123. data/lib/zm/client/tag/tags_builder.rb +1 -1
  124. data/lib/zm/client/tag/tags_collection.rb +2 -2
  125. data/lib/zm/client/task/task.rb +2 -2
  126. data/lib/zm/client/task/tasks_collection.rb +2 -2
  127. data/lib/zm/client/token.rb +4 -1
  128. data/lib/zm/client/upload.rb +179 -1
  129. data/lib/zm/client/{common/utils.rb → utils.rb} +6 -3
  130. data/lib/zm/client/zm_logger.rb +1 -1
  131. data/lib/zm/client.rb +227 -10
  132. data/lib/zm/connector/network_error_handler.rb +18 -0
  133. data/lib/zm/{client/connector → connector}/rest_connector.rb +46 -40
  134. data/lib/zm/{client/connector/soap_account.rb → connector/soap_account_connector.rb} +15 -17
  135. data/lib/zm/{client/connector/soap_admin.rb → connector/soap_admin_connector.rb} +3 -5
  136. data/lib/zm/connector/soap_base_connector.rb +115 -0
  137. data/lib/zm/connector.rb +13 -0
  138. data/lib/zm/error/auth_error.rb +8 -0
  139. data/lib/zm/error/connection_error.rb +8 -0
  140. data/lib/zm/error/rest_error.rb +8 -0
  141. data/lib/zm/{client/connector → error}/soap_error.rb +1 -10
  142. data/lib/zm/error/zm_error.rb +8 -0
  143. data/lib/zm/error.rb +11 -0
  144. data/lib/zm/relationship/has_many.rb +22 -0
  145. data/lib/zm/relationship/jsns_builder.rb +21 -0
  146. data/lib/zm/relationship/relationship.rb +113 -0
  147. data/lib/zm/relationship/schema.rb +32 -0
  148. data/lib/zm/relationship.rb +5 -0
  149. data/lib/zm/{client/soap_request → soap_request}/request_methods_admin.rb +11 -5
  150. data/lib/zm/{client/soap_request → soap_request}/request_methods_mailbox.rb +1 -1
  151. data/lib/zm/{client/soap_request/account_soap_constants.rb → soap_request/soap_account_constants.rb} +1 -1
  152. data/lib/zm/{client/soap_request/admin_soap_constants.rb → soap_request/soap_admin_constants.rb} +1 -1
  153. data/lib/zm/{client/soap_request → soap_request}/soap_constants.rb +1 -1
  154. data/lib/zm/{client/soap_request → soap_request}/soap_context.rb +13 -5
  155. data/lib/zm/{client/soap_request → soap_request}/soap_element.rb +1 -1
  156. data/lib/zm/{client/soap_request/mail_soap_constants.rb → soap_request/soap_mail_constants.rb} +1 -1
  157. data/lib/zm/soap_request.rb +14 -0
  158. data/lib/zm/support/cache/entry.rb +3 -3
  159. data/lib/zm/support/cache/file_store.rb +4 -6
  160. data/lib/zm/support/cache/null_store.rb +2 -4
  161. data/lib/zm/support/cache/store.rb +17 -9
  162. data/lib/zm/support/cache.rb +13 -8
  163. data/lib/zm/support.rb +7 -0
  164. data/lib/zm/{modules → utils}/belongs_to_folder.rb +1 -1
  165. data/lib/zm/{modules → utils}/belongs_to_tag.rb +2 -2
  166. data/lib/zm/utils/content_part.rb +9 -0
  167. data/lib/zm/utils/content_type.rb +11 -0
  168. data/lib/zm/{modules → utils}/has_soap_admin_connector.rb +1 -1
  169. data/lib/zm/utils/inspector.rb +26 -0
  170. data/lib/zm/utils/log_filter.rb +30 -0
  171. data/lib/zm/utils/missing_method_static_collection.rb +17 -0
  172. data/lib/zm/utils/regex.rb +11 -0
  173. data/lib/zm/utils/search_utils.rb +13 -0
  174. data/lib/zm/utils.rb +16 -0
  175. data/lib/zm-ruby-client.rb +12 -0
  176. data/sig/zm/client/admin_objects.rbs +261 -0
  177. data/sig/zm/client/base.rbs +191 -0
  178. data/sig/zm/client/cluster.rbs +152 -0
  179. data/sig/zm/client/mailbox.rbs +766 -0
  180. data/sig/zm/error.rbs +23 -0
  181. metadata +99 -91
  182. data/.gitignore +0 -59
  183. data/.rubocop.yml +0 -6
  184. data/.ruby-version +0 -1
  185. data/Gemfile +0 -11
  186. data/SECURITY.md +0 -21
  187. data/bin/console +0 -11
  188. data/lib/zm/client/account.rb +0 -9
  189. data/lib/zm/client/ace.rb +0 -7
  190. data/lib/zm/client/appointment.rb +0 -7
  191. data/lib/zm/client/backup.rb +0 -6
  192. data/lib/zm/client/base.rb +0 -21
  193. data/lib/zm/client/cluster.rb +0 -4
  194. data/lib/zm/client/common/message.rb +0 -10
  195. data/lib/zm/client/common.rb +0 -5
  196. data/lib/zm/client/connector/soap_base.rb +0 -104
  197. data/lib/zm/client/constant.rb +0 -229
  198. data/lib/zm/client/contact.rb +0 -11
  199. data/lib/zm/client/cos.rb +0 -10
  200. data/lib/zm/client/datasource.rb +0 -7
  201. data/lib/zm/client/distributionlist.rb +0 -8
  202. data/lib/zm/client/document.rb +0 -7
  203. data/lib/zm/client/domain.rb +0 -10
  204. data/lib/zm/client/filter_rule.rb +0 -7
  205. data/lib/zm/client/folder.rb +0 -14
  206. data/lib/zm/client/identity.rb +0 -7
  207. data/lib/zm/client/license.rb +0 -5
  208. data/lib/zm/client/message/attachments_collection.rb +0 -55
  209. data/lib/zm/client/message/message_flags.rb +0 -115
  210. data/lib/zm/client/message.rb +0 -10
  211. data/lib/zm/client/mountpoint.rb +0 -7
  212. data/lib/zm/client/mta_queue.rb +0 -7
  213. data/lib/zm/client/mta_queue_item.rb +0 -6
  214. data/lib/zm/client/resource.rb +0 -7
  215. data/lib/zm/client/search_folder.rb +0 -7
  216. data/lib/zm/client/server.rb +0 -7
  217. data/lib/zm/client/share.rb +0 -7
  218. data/lib/zm/client/signature.rb +0 -7
  219. data/lib/zm/client/soap_request.rb +0 -11
  220. data/lib/zm/client/tag.rb +0 -8
  221. data/lib/zm/client/task.rb +0 -6
  222. data/lib/zm/client/upload/upload.rb +0 -160
  223. data/lib/zm/modules/base.rb +0 -9
  224. data/lib/zm/modules/common/zimbra-attrs.json +0 -58
  225. data/lib/zm/modules/inspector.rb +0 -24
  226. data/lib/zm/modules/missing_method_static_collection.rb +0 -13
  227. data/lib/zm/modules/zm_model.rb +0 -43
  228. data/zm-ruby-client.gemspec +0 -27
  229. /data/lib/zm/client/mountpoint/{mountpoints_collection.rb → mount_points_collection.rb} +0 -0
@@ -4,26 +4,35 @@ module Zm
4
4
  module Client
5
5
  # class for account appointment
6
6
  class Appointment < Base::Object
7
- include BelongsToFolder
8
- include BelongsToTag
9
- include RequestMethodsMailbox
7
+ include Zm::Utils::BelongsToFolder
8
+ include Zm::Utils::BelongsToTag
9
+ include SoapRequest::RequestMethodsMailbox
10
10
  include MailboxItemConcern
11
+ extend Zm::Relationship
12
+ has_jsns_builder
11
13
 
12
14
  attr_accessor :uid, :name, :desc, :start_at, :dur, :end_at, :tn, :allDay, :organizer, :timezone,
13
- :calItemId, :apptId, :invId, :rev, :fb, :transp
15
+ :calItemId, :apptId, :invId, :rev, :fb, :transp, :recur, :s, :ms, :f
14
16
  attr_reader :recipients, :attendees, :body
15
17
 
16
18
  alias description desc
19
+ alias recurrent recur
20
+ alias size s
17
21
 
18
22
  def initialize(parent)
19
- @parent = parent
20
23
  @recipients = Recipients.new
21
24
  @body = BodyMail.new
22
25
  @attendees = Attendees.new
23
26
  @allDay = false
24
27
  @timezone = 'Europe/Berlin'
25
28
 
26
- yield(self) if block_given?
29
+ super
30
+ end
31
+
32
+ def flags
33
+ return @flags if defined? @flags
34
+
35
+ @flags = f.chars
27
36
  end
28
37
 
29
38
  def download(dest_file_path, fmt: 'ics')
@@ -31,6 +40,11 @@ module Zm
31
40
  uploader.download_file(dest_file_path, id, FolderView::APPOINTMENT, fmt:)
32
41
  end
33
42
 
43
+ def read
44
+ uploader = @parent.build_uploader
45
+ uploader.read_file(id, FolderView::APPOINTMENT, fmt: 'ics')
46
+ end
47
+
34
48
  def create!
35
49
  rep = @parent.soap_connector.invoke(build_create)
36
50
 
@@ -41,12 +55,12 @@ module Zm
41
55
  end
42
56
 
43
57
  def build_create
44
- SoapElement.mail(SoapMailConstants::CREATE_APPOINTMENT_REQUEST)
58
+ SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::CREATE_APPOINTMENT_REQUEST)
45
59
  .add_attributes(jsns_builder.to_jsns)
46
60
  end
47
61
 
48
62
  def build_modify
49
- SoapElement.mail(SoapMailConstants::MODIFY_APPOINTMENT_REQUEST)
63
+ SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::MODIFY_APPOINTMENT_REQUEST)
50
64
  .add_attributes(jsns_builder.to_update)
51
65
  end
52
66
 
@@ -63,9 +77,9 @@ module Zm
63
77
  end
64
78
 
65
79
  def reload!
66
- jsns = { m: { id: id, html: SoapUtils::ON } }
80
+ jsns = { m: { id:, html: Zm::Utils::SearchUtils::ON } }
67
81
 
68
- soap_request = SoapElement.mail(SoapMailConstants::GET_MSG_REQUEST)
82
+ soap_request = SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::GET_MSG_REQUEST)
69
83
  .add_attributes(jsns)
70
84
  rep = @parent.soap_connector.invoke(soap_request)
71
85
  entry = rep[:GetMsgResponse][:m].first
@@ -147,11 +161,15 @@ module Zm
147
161
  end
148
162
  end
149
163
 
150
- def jsns_builder
151
- return @jsns_builder if defined? @jsns_builder
152
-
153
- @jsns_builder = AppointmentJsnsBuilder.new(self)
164
+ class BodyMail
165
+ attr_accessor :text, :html
154
166
  end
167
+
168
+ # def jsns_builder
169
+ # return @jsns_builder if defined? @jsns_builder
170
+ #
171
+ # @jsns_builder = AppointmentJsnsBuilder.new(self)
172
+ # end
155
173
  end
156
174
  end
157
175
  end
@@ -3,7 +3,7 @@
3
3
  module Zm
4
4
  module Client
5
5
  # class for account appointment
6
- class AppointmentJsnsBuilder < BaseAccountJsnsBuilder
6
+ class AppointmentJsnsBuilder < Base::BaseAccountJsnsBuilder
7
7
  def to_jsns
8
8
  {
9
9
  m: {
@@ -22,7 +22,7 @@ module Zm
22
22
 
23
23
  def to_update
24
24
  jsns = to_jsns
25
- jsns[:comp] = SoapUtils::OFF
25
+ jsns[:comp] = Zm::Utils::SearchUtils::OFF
26
26
  jsns[:id] = @item.id
27
27
  jsns[:m][:inv][:uid] = @item.uid
28
28
  jsns
@@ -43,18 +43,18 @@ module Zm
43
43
  def body_to_jsns
44
44
  [
45
45
  {
46
- ct: ContentPart::ALTERNATIVE,
46
+ ct: Zm::Utils::ContentPart::ALTERNATIVE,
47
47
  mp: [body_text_jsns, body_html_jsns]
48
48
  }
49
49
  ]
50
50
  end
51
51
 
52
52
  def body_text_jsns
53
- { ct: ContentType::TEXT, content: { _content: @item.body.text } }
53
+ { ct: Zm::Utils::ContentType::TEXT, content: { _content: @item.body.text } }
54
54
  end
55
55
 
56
56
  def body_html_jsns
57
- { ct: ContentType::HTML, content: { _content: @item.body.html } }
57
+ { ct: Zm::Utils::ContentType::HTML, content: { _content: @item.body.html } }
58
58
  end
59
59
 
60
60
  def comp_to_jsns
@@ -31,6 +31,11 @@ module Zm
31
31
  @appointment.tn = @json.delete(:tn)
32
32
  @appointment.l = @json.delete(:l)
33
33
  @appointment.uid = @json.delete(:uid)
34
+ @appointment.recur = @json.delete(:recur) || false
35
+ @appointment.s = @json.delete(:s).to_i
36
+ @appointment.ms = @json.delete(:ms).to_i
37
+ @appointment.rev = @json.delete(:rev).to_i
38
+ @appointment.f = @json.delete(:f) || ''
34
39
 
35
40
  if inv.nil?
36
41
  init_from_search
@@ -108,7 +113,7 @@ module Zm
108
113
  end
109
114
 
110
115
  def comp
111
- raise Zm::Client::ZmError, 'invalid appointment received' if inv[:comp].nil?
116
+ raise Zm::Error::ZmError, 'invalid appointment received' if inv[:comp].nil?
112
117
 
113
118
  @comp ||= inv[:comp].first
114
119
  end
@@ -8,14 +8,14 @@ module Zm
8
8
  super
9
9
  @child_class = Appointment
10
10
  @builder_class = AppointmentsBuilder
11
- @type = SoapConstants::APPOINTMENT
12
- @sort_by = SoapConstants::DATE_ASC
11
+ @type = SoapRequest::SoapConstants::APPOINTMENT
12
+ @sort_by = SoapRequest::SoapConstants::DATE_ASC
13
13
  end
14
14
 
15
15
  def find(id)
16
- jsns = { m: { id: id, html: SoapUtils::ON } }
16
+ jsns = { m: { id:, html: Zm::Utils::SearchUtils::ON } }
17
17
 
18
- soap_request = SoapElement.mail(SoapMailConstants::GET_MSG_REQUEST)
18
+ soap_request = SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::GET_MSG_REQUEST)
19
19
  .add_attributes(jsns)
20
20
  rep = @parent.soap_connector.invoke(soap_request)
21
21
  entry = rep[:GetMsgResponse][:m].first
@@ -23,16 +23,19 @@ module Zm
23
23
  AppointmentJsnsInitializer.new(@parent, entry).create
24
24
  end
25
25
 
26
- def find_each(offset: 0, limit: 500, &block)
27
- (Time.at(0).year..(Time.now.year + 10)).each do |year|
28
- @start_at ||= Time.new(year, 1, 1).to_i * 1000
29
- @end_at ||= Time.new(year, 12, 31).to_i * 1000
26
+ def find_each(offset: 0, limit: 500, start_year: nil, end_year: nil, &)
27
+ start_year ||= Time.now.year - 10
28
+ end_year ||= Time.now.year + 10
29
+
30
+ (start_year..end_year).each do |year|
31
+ @start_at = Time.new(year, 1, 1).to_i * 1000
32
+ @end_at = Time.new(year, 12, 31).to_i * 1000
30
33
  @more = true
31
34
  @offset = offset
32
35
  @limit = limit
33
36
 
34
37
  while @more
35
- build_response.each { |item| block.call(item) }
38
+ build_response.each(&)
36
39
  @offset += @limit
37
40
  end
38
41
  end
@@ -3,6 +3,9 @@
3
3
  module Zm
4
4
  module Client
5
5
  class Backup < Base::Object
6
+ FULL = 'full'
7
+ INCREMENTAL = 'incremental'
8
+
6
9
  attr_accessor :label, :type, :aborted, :start, :end, :minRedoSeq, :maxRedoSeq, :live, :accounts
7
10
 
8
11
  alias name label
@@ -28,11 +31,11 @@ module Zm
28
31
  end
29
32
 
30
33
  def full?
31
- @type == Zm::Client::BackupTypes::FULL
34
+ @type == FULL
32
35
  end
33
36
 
34
37
  def incremental?
35
- @type == Zm::Client::BackupTypes::INCREMENTAL
38
+ @type == INCREMENTAL
36
39
  end
37
40
  end
38
41
  end
@@ -5,14 +5,15 @@ module Zm
5
5
  # Collection Backups
6
6
  class BackupsCollection < Base::ObjectsCollection
7
7
  def initialize(parent)
8
+ super()
8
9
  @parent = parent
9
10
  end
10
11
 
11
12
  private
12
13
 
13
14
  def make_query
14
- soap_request = SoapElement.admin(SoapAdminConstants::BACKUP_QUERY_REQUEST)
15
- .add_attribute(SoapConstants::QUERY, {})
15
+ soap_request = Zm::SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::BACKUP_QUERY_REQUEST)
16
+ .add_attribute(Zm::SoapRequest::SoapConstants::QUERY, {})
16
17
  sac.target_invoke(soap_request, @parent.id)
17
18
  end
18
19
 
@@ -6,6 +6,7 @@ module Zm
6
6
  # Collection AccountObjectsCollection
7
7
  class AccountObjectsCollection < ObjectsCollection
8
8
  def initialize(parent)
9
+ super()
9
10
  @parent = parent
10
11
  end
11
12
  end
@@ -21,8 +21,8 @@ module Zm
21
21
  end
22
22
 
23
23
  def build_find(id)
24
- SoapElement.mail(SoapMailConstants::GET_MSG_REQUEST)
25
- .add_attributes({ m: { id: id, html: SoapUtils::ON } })
24
+ SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::GET_MSG_REQUEST)
25
+ .add_attributes({ m: { id:, html: Zm::Utils::SearchUtils::ON } })
26
26
  end
27
27
 
28
28
  def start_at(start_at)
@@ -92,7 +92,7 @@ module Zm
92
92
  offset: @offset,
93
93
  limit: @limit,
94
94
  sortBy: @sort_by,
95
- query: query,
95
+ query:,
96
96
  header: @headers
97
97
  }
98
98
 
@@ -100,7 +100,7 @@ module Zm
100
100
 
101
101
  jsns.compact!
102
102
 
103
- SoapElement.mail(SoapMailConstants::SEARCH_REQUEST)
103
+ SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::SEARCH_REQUEST)
104
104
  .add_attributes(jsns)
105
105
  end
106
106
 
@@ -112,8 +112,8 @@ module Zm
112
112
 
113
113
  attrs.compact!
114
114
 
115
- soap_request = SoapElement.mail(SoapMailConstants::ITEM_ACTION_REQUEST)
116
- node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
115
+ soap_request = SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::ITEM_ACTION_REQUEST)
116
+ node_action = SoapRequest::SoapElement.create(SoapRequest::SoapConstants::ACTION).add_attributes(attrs)
117
117
  soap_request.add_node(node_action)
118
118
  @parent.soap_connector.invoke(soap_request)
119
119
  end
@@ -5,7 +5,10 @@ module Zm
5
5
  module Base
6
6
  # Collection AdminObjectsCollection
7
7
  class AdminObjectsCollection < ObjectsCollection
8
+ ONERRORS = %w[continue stop].freeze
9
+
8
10
  def initialize(parent)
11
+ super()
9
12
  @parent = parent
10
13
  @persistent = false
11
14
  reset_query_params
@@ -15,14 +18,14 @@ module Zm
15
18
  find_by!(hash)
16
19
  end
17
20
 
18
- def find_by_or_nil(hash, error_handler = SoapError)
21
+ def find_by_or_nil(hash, error_handler = Zm::Error::SoapError)
19
22
  find_by(hash)
20
23
  rescue error_handler => _e
21
24
  nil
22
25
  end
23
26
 
24
27
  def ldap
25
- @apply_cos = SoapUtils::OFF
28
+ @apply_cos = Zm::Utils::SearchUtils::OFF
26
29
  self
27
30
  end
28
31
 
@@ -47,9 +50,9 @@ module Zm
47
50
 
48
51
  def count
49
52
  reset_query_params
50
- @count_only = SoapUtils::ON
53
+ @count_only = Zm::Utils::SearchUtils::ON
51
54
  json = make_query
52
- @count_only = SoapUtils::OFF
55
+ @count_only = Zm::Utils::SearchUtils::OFF
53
56
  json[:SearchDirectoryResponse][:num]
54
57
  end
55
58
 
@@ -59,7 +62,7 @@ module Zm
59
62
  self
60
63
  end
61
64
 
62
- def find_each(offset: 0, limit: 1_000, &block)
65
+ def find_each(offset: 0, limit: 1_000, &)
63
66
  previous_persistent = @persistent.dup
64
67
  @persistent = true
65
68
 
@@ -71,7 +74,7 @@ module Zm
71
74
  @limit = limit
72
75
 
73
76
  while @offset < total
74
- build_response.each { |item| block.call(item) }
77
+ build_response.each(&)
75
78
  @offset += @limit
76
79
  end
77
80
 
@@ -88,12 +91,62 @@ module Zm
88
91
  end
89
92
 
90
93
  def build_query
91
- SoapElement.admin(SoapAdminConstants::SEARCH_DIRECTORY_REQUEST)
94
+ SoapRequest::SoapElement.admin(Zm::SoapRequest::SoapAdminConstants::SEARCH_DIRECTORY_REQUEST)
92
95
  .add_attributes(jsns)
93
96
  end
94
97
 
98
+ def update_all!(hash = nil, onerror: ONERRORS.first, update_attributes: true, **attrs)
99
+ mass_update!(build_response, hash, onerror:, update_attributes:, **attrs)
100
+ end
101
+
102
+ def mass_update!(items, hash = nil, onerror: ONERRORS.first, update_attributes: true, **attrs)
103
+ hash = hash.nil? ? attrs : hash.merge(attrs)
104
+ format_mass_items_parameter(items)
105
+
106
+ items.each do |item|
107
+ item.update!(hash, update_attributes:)
108
+ rescue Zm::Error::SoapError => e
109
+ @parent.logger.error e.message
110
+ @parent.logger.debug e.backtrace.join("\n")
111
+
112
+ return items if onerror == ONERRORS.last
113
+ end
114
+
115
+ items
116
+ end
117
+
118
+ def delete_all!(onerror: ONERRORS.first)
119
+ mass_delete!(build_response, onerror:)
120
+ end
121
+
122
+ def mass_delete!(items, onerror: ONERRORS.first)
123
+ format_mass_items_parameter(items)
124
+
125
+ items.each do |item|
126
+ item.delete!
127
+ rescue Zm::Error::SoapError => e
128
+ @parent.logger.error e.message
129
+ @parent.logger.debug e.backtrace.join("\n")
130
+
131
+ return items if onerror == ONERRORS.last
132
+ end
133
+
134
+ items
135
+ end
136
+
95
137
  private
96
138
 
139
+ def format_mass_items_parameter(items)
140
+ items.map! do |item|
141
+ if item.is_a?(@child_class)
142
+ item.updated = false
143
+ item
144
+ else
145
+ new { |acc| acc.id = item }
146
+ end
147
+ end
148
+ end
149
+
97
150
  def ldap_filter
98
151
  return @ldap_filter if defined? @ldap_filter
99
152
 
@@ -2,93 +2,95 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # class for account tag jsns builder
6
- class BaseAccountJsnsBuilder
7
- def initialize(item)
8
- @item = item
9
- end
10
-
11
- def to_tag(tag_name = nil)
12
- tag_name ||= @item.tn
13
-
14
- attrs = {
15
- op: :tag,
16
- id: @item.id,
17
- tn: tag_name
18
- }
19
-
20
- build(attrs)
21
- end
22
-
23
- def to_move(new_folder_id = nil)
24
- new_folder_id ||= @item.l
25
-
26
- attrs = {
27
- op: :move,
28
- id: @item.id,
29
- l: new_folder_id
30
- }
31
-
32
- build(attrs)
33
- end
34
-
35
- def to_patch(hash)
36
- attrs = {
37
- op: :update,
38
- id: @item.id
39
- }.merge(hash)
40
-
41
- attrs.compact!
42
-
43
- build(attrs)
44
- end
45
-
46
- def to_delete
47
- attrs = {
48
- op: :delete,
49
- id: @item.id
50
- }
51
-
52
- build(attrs)
53
- end
54
-
55
- def to_rename(new_name = nil)
56
- new_name ||= @item.name
57
-
58
- attrs = {
59
- op: :rename,
60
- id: @item.id,
61
- name: new_name
62
- }
63
-
64
- build(attrs)
65
- end
66
-
67
- def to_color
68
- attrs = {
69
- op: :color,
70
- id: @item.id,
71
- rgb: @item.rgb,
72
- color: @item.color
73
- }
74
-
75
- build(attrs)
76
- end
77
-
78
- def to_trash
79
- attrs = {
80
- op: :trash,
81
- id: @item.id
82
- }
83
-
84
- build(attrs)
85
- end
86
-
87
- def build(attrs)
88
- soap_request = SoapElement.mail(SoapMailConstants::ITEM_ACTION_REQUEST)
89
- node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
90
- soap_request.add_node(node_action)
91
- soap_request
5
+ module Base
6
+ # class for account tag jsns builder
7
+ class BaseAccountJsnsBuilder
8
+ def initialize(item)
9
+ @item = item
10
+ end
11
+
12
+ def to_tag(tag_name = nil)
13
+ tag_name ||= @item.tn
14
+
15
+ attrs = {
16
+ op: :tag,
17
+ id: @item.id,
18
+ tn: tag_name
19
+ }
20
+
21
+ build(attrs)
22
+ end
23
+
24
+ def to_move(new_folder_id = nil)
25
+ new_folder_id ||= @item.l
26
+
27
+ attrs = {
28
+ op: :move,
29
+ id: @item.id,
30
+ l: new_folder_id
31
+ }
32
+
33
+ build(attrs)
34
+ end
35
+
36
+ def to_patch(hash)
37
+ attrs = {
38
+ op: :update,
39
+ id: @item.id
40
+ }.merge(hash)
41
+
42
+ attrs.compact!
43
+
44
+ build(attrs)
45
+ end
46
+
47
+ def to_delete
48
+ attrs = {
49
+ op: :delete,
50
+ id: @item.id
51
+ }
52
+
53
+ build(attrs)
54
+ end
55
+
56
+ def to_rename(new_name = nil)
57
+ new_name ||= @item.name
58
+
59
+ attrs = {
60
+ op: :rename,
61
+ id: @item.id,
62
+ name: new_name
63
+ }
64
+
65
+ build(attrs)
66
+ end
67
+
68
+ def to_color
69
+ attrs = {
70
+ op: :color,
71
+ id: @item.id,
72
+ rgb: @item.rgb,
73
+ color: @item.color
74
+ }
75
+
76
+ build(attrs)
77
+ end
78
+
79
+ def to_trash
80
+ attrs = {
81
+ op: :trash,
82
+ id: @item.id
83
+ }
84
+
85
+ build(attrs)
86
+ end
87
+
88
+ def build(attrs)
89
+ soap_request = SoapRequest::SoapElement.mail(SoapRequest::SoapMailConstants::ITEM_ACTION_REQUEST)
90
+ node_action = SoapRequest::SoapElement.create(SoapRequest::SoapConstants::ACTION).add_attributes(attrs)
91
+ soap_request.add_node(node_action)
92
+ soap_request
93
+ end
92
94
  end
93
95
  end
94
96
  end
@@ -15,7 +15,7 @@ module Zm
15
15
  def to_jsns
16
16
  {
17
17
  name: @item.name,
18
- a: instance_variables_array.map(&A_ARRAY_PROC).flatten(1).map(&A_NODE_PROC)
18
+ a: instance_variables_array.flat_map(&A_ARRAY_PROC).map(&A_NODE_PROC)
19
19
  }
20
20
  end
21
21
 
@@ -24,14 +24,14 @@ module Zm
24
24
  def to_update
25
25
  {
26
26
  id: @item.id,
27
- a: instance_variables_array.map(&A_ARRAY_PROC).flatten(1).map(&A_NODE_PROC)
27
+ a: instance_variables_array.flat_map(&A_ARRAY_PROC).map(&A_NODE_PROC)
28
28
  }
29
29
  end
30
30
 
31
31
  def to_patch(hash)
32
32
  {
33
33
  id: @item.id,
34
- a: hash.map(&A_ARRAY_PROC).flatten(1).map(&A_NODE_PROC)
34
+ a: hash.flat_map(&A_ARRAY_PROC).map(&A_NODE_PROC)
35
35
  }
36
36
  end
37
37