zm-ruby-client 2.2.7 → 3.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +10 -6
  5. data/Gemfile +1 -6
  6. data/README.md +10 -15
  7. data/VERSION +1 -1
  8. data/lib/zm/client/account/account.rb +35 -22
  9. data/lib/zm/client/account/account_aliases_collection.rb +14 -6
  10. data/lib/zm/client/account/account_dls_membership_collection.rb +10 -4
  11. data/lib/zm/client/account/account_dls_owner_collection.rb +8 -5
  12. data/lib/zm/client/account/account_jsns_builder.rb +31 -19
  13. data/lib/zm/client/account/account_jsns_initializer.rb +4 -14
  14. data/lib/zm/client/account/accounts_builder.rb +1 -1
  15. data/lib/zm/client/account/accounts_collection.rb +15 -8
  16. data/lib/zm/client/ace/ace.rb +5 -5
  17. data/lib/zm/client/ace/ace_jsns_builder.rb +8 -8
  18. data/lib/zm/client/ace/ace_jsns_initializer.rb +7 -7
  19. data/lib/zm/client/ace/aces_builder.rb +1 -1
  20. data/lib/zm/client/ace/aces_collection.rb +2 -2
  21. data/lib/zm/client/appointment/appointment.rb +27 -24
  22. data/lib/zm/client/appointment/appointment_jsns_builder.rb +29 -20
  23. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +14 -13
  24. data/lib/zm/client/appointment/appointments_builder.rb +1 -1
  25. data/lib/zm/client/appointment/appointments_collection.rb +8 -7
  26. data/lib/zm/client/backup/backup.rb +6 -2
  27. data/lib/zm/client/backup/backup_jsns_initializer.rb +14 -12
  28. data/lib/zm/client/backup/backups_builder.rb +1 -1
  29. data/lib/zm/client/backup/backups_collection.rb +2 -1
  30. data/lib/zm/client/base/account_search_objects_collection.rb +46 -20
  31. data/lib/zm/client/base/admin_objects_collection.rb +22 -27
  32. data/lib/zm/client/base/base_account_jsns_builder.rb +1 -4
  33. data/lib/zm/client/base/base_jsns_initializer.rb +8 -8
  34. data/lib/zm/client/base/mailbox_infos_collection.rb +23 -15
  35. data/lib/zm/client/base/mailbox_object.rb +174 -69
  36. data/lib/zm/client/base/mailbox_prefs_collection.rb +4 -8
  37. data/lib/zm/client/base/object.rb +2 -2
  38. data/lib/zm/client/base/objects_builder.rb +7 -3
  39. data/lib/zm/client/base/objects_collection.rb +4 -13
  40. data/lib/zm/client/base/zimbra_attribute.rb +4 -17
  41. data/lib/zm/client/base/zimbra_attributes_collection.rb +16 -9
  42. data/lib/zm/client/base.rb +0 -1
  43. data/lib/zm/client/cluster/batch_request.rb +50 -0
  44. data/lib/zm/client/cluster/cluster.rb +49 -27
  45. data/lib/zm/client/cluster/cluster_config.rb +129 -40
  46. data/lib/zm/client/common/recipients.rb +2 -2
  47. data/lib/zm/client/common/utils.rb +1 -13
  48. data/lib/zm/client/common.rb +0 -1
  49. data/lib/zm/client/connector/{rest_account.rb → rest_connector.rb} +40 -50
  50. data/lib/zm/client/connector/soap_account.rb +19 -15
  51. data/lib/zm/client/connector/soap_admin.rb +9 -9
  52. data/lib/zm/client/connector/soap_base.rb +24 -17
  53. data/lib/zm/client/connector/soap_error.rb +3 -23
  54. data/lib/zm/client/constant.rb +18 -16
  55. data/lib/zm/client/contact/contact.rb +21 -40
  56. data/lib/zm/client/contact/contact_jsns_builder.rb +1 -1
  57. data/lib/zm/client/contact/contact_jsns_initializer.rb +4 -26
  58. data/lib/zm/client/contact/contacts_builder.rb +1 -1
  59. data/lib/zm/client/contact/contacts_collection.rb +4 -24
  60. data/lib/zm/client/contact/group_contact_jsns_builder.rb +18 -13
  61. data/lib/zm/client/contact/mod_group_contact.rb +6 -2
  62. data/lib/zm/client/cos/cos.rb +35 -11
  63. data/lib/zm/client/cos/cos_domains_collection.rb +1 -1
  64. data/lib/zm/client/cos/cos_jsns_builder.rb +22 -9
  65. data/lib/zm/client/cos/cos_jsns_initializer.rb +2 -6
  66. data/lib/zm/client/cos/cos_servers_collection.rb +5 -6
  67. data/lib/zm/client/cos/coses_builder.rb +1 -1
  68. data/lib/zm/client/cos/coses_collection.rb +6 -4
  69. data/lib/zm/client/datasource/datasource.rb +27 -34
  70. data/lib/zm/client/datasource/datasource_jsns_builder.rb +1 -1
  71. data/lib/zm/client/datasource/datasource_jsns_initializer.rb +5 -6
  72. data/lib/zm/client/datasource/datasources_builder.rb +6 -9
  73. data/lib/zm/client/datasource/datasources_collection.rb +6 -5
  74. data/lib/zm/client/distributionlist/distributionlist.rb +22 -42
  75. data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +14 -6
  76. data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +20 -16
  77. data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +2 -11
  78. data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +20 -12
  79. data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +16 -5
  80. data/lib/zm/client/distributionlist/distributionlists_builder.rb +1 -1
  81. data/lib/zm/client/distributionlist/distributionlists_collection.rb +12 -6
  82. data/lib/zm/client/distributionlist/dls_membership_collection.rb +12 -6
  83. data/lib/zm/client/document/document.rb +16 -8
  84. data/lib/zm/client/document/document_jsns_builder.rb +1 -1
  85. data/lib/zm/client/document/document_jsns_initializer.rb +27 -26
  86. data/lib/zm/client/document/documents_builder.rb +1 -1
  87. data/lib/zm/client/document/documents_collection.rb +1 -1
  88. data/lib/zm/client/domain/domain.rb +18 -37
  89. data/lib/zm/client/domain/domain_accounts_collection.rb +1 -1
  90. data/lib/zm/client/domain/domain_distributionlists_collection.rb +1 -1
  91. data/lib/zm/client/domain/domain_jsns_builder.rb +18 -9
  92. data/lib/zm/client/domain/domain_jsns_initializer.rb +2 -6
  93. data/lib/zm/client/domain/domain_resources_collection.rb +1 -1
  94. data/lib/zm/client/domain/domains_builder.rb +1 -1
  95. data/lib/zm/client/domain/domains_collection.rb +12 -6
  96. data/lib/zm/client/filter_rules/filter_rule.rb +0 -9
  97. data/lib/zm/client/filter_rules/filter_rule_jsns_initializer.rb +7 -6
  98. data/lib/zm/client/filter_rules/filter_rules_builder.rb +1 -1
  99. data/lib/zm/client/filter_rules/filter_rules_collection.rb +5 -15
  100. data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +5 -2
  101. data/lib/zm/client/folder/folder.rb +73 -56
  102. data/lib/zm/client/folder/folder_grant.rb +7 -5
  103. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +6 -3
  104. data/lib/zm/client/folder/folder_grants_collection.rb +2 -4
  105. data/lib/zm/client/folder/folder_jsns_builder.rb +14 -7
  106. data/lib/zm/client/folder/folder_jsns_initializer.rb +58 -40
  107. data/lib/zm/client/folder/folder_retention_policies_collection.rb +4 -2
  108. data/lib/zm/client/folder/folders_builder.rb +1 -1
  109. data/lib/zm/client/folder/folders_collection.rb +21 -18
  110. data/lib/zm/client/folder/folders_jsns_builder.rb +4 -2
  111. data/lib/zm/client/folder/mod_document_folder.rb +5 -4
  112. data/lib/zm/client/identity/identities_builder.rb +1 -1
  113. data/lib/zm/client/identity/identities_collection.rb +6 -5
  114. data/lib/zm/client/identity/identity.rb +9 -29
  115. data/lib/zm/client/identity/identity_jsns_builder.rb +8 -4
  116. data/lib/zm/client/identity/identity_jsns_initializer.rb +5 -4
  117. data/lib/zm/client/license/license.rb +7 -1
  118. data/lib/zm/client/license/license_jsns_initializer.rb +8 -5
  119. data/lib/zm/client/license/licenses_collection.rb +1 -1
  120. data/lib/zm/client/mailbox/mailbox_item_concern.rb +33 -0
  121. data/lib/zm/client/mailbox/mailbox_item_id.rb +7 -0
  122. data/lib/zm/client/message/attachments_collection.rb +2 -2
  123. data/lib/zm/client/message/message.rb +56 -52
  124. data/lib/zm/client/message/message_flags.rb +21 -13
  125. data/lib/zm/client/message/message_jsns_builder.rb +11 -6
  126. data/lib/zm/client/message/message_jsns_initializer.rb +24 -23
  127. data/lib/zm/client/message/messages_builder.rb +1 -1
  128. data/lib/zm/client/message/messages_collection.rb +1 -15
  129. data/lib/zm/client/mountpoint/mountpoint.rb +17 -25
  130. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +6 -3
  131. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +25 -24
  132. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  133. data/lib/zm/client/mountpoint/mountpoints_collection.rb +13 -9
  134. data/lib/zm/client/mta_queue/mta_queue.rb +6 -2
  135. data/lib/zm/client/mta_queue/mta_queue_jsns_initializer.rb +3 -7
  136. data/lib/zm/client/mta_queue/mta_queues_builder.rb +3 -1
  137. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +5 -3
  138. data/lib/zm/client/mta_queue_item/mta_queue_item_jsns_initializer.rb +1 -5
  139. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +3 -1
  140. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +3 -1
  141. data/lib/zm/client/resource/resource.rb +6 -18
  142. data/lib/zm/client/resource/resource_jsns_builder.rb +20 -13
  143. data/lib/zm/client/resource/resource_jsns_initializer.rb +4 -14
  144. data/lib/zm/client/resource/resources_builder.rb +1 -1
  145. data/lib/zm/client/resource/resources_collection.rb +12 -7
  146. data/lib/zm/client/search_folder/search_folder.rb +13 -29
  147. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +6 -6
  148. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +19 -18
  149. data/lib/zm/client/search_folder/search_folders_builder.rb +1 -1
  150. data/lib/zm/client/search_folder/search_folders_collection.rb +6 -5
  151. data/lib/zm/client/server/server.rb +9 -3
  152. data/lib/zm/client/server/server_accounts_collection.rb +4 -2
  153. data/lib/zm/client/server/server_jsns_initializer.rb +1 -5
  154. data/lib/zm/client/server/servers_builder.rb +1 -1
  155. data/lib/zm/client/server/servers_collection.rb +17 -9
  156. data/lib/zm/client/share/share.rb +5 -3
  157. data/lib/zm/client/share/share_jsns_initializer.rb +15 -14
  158. data/lib/zm/client/share/share_mountpoints_collection.rb +3 -6
  159. data/lib/zm/client/share/shares_builder.rb +1 -1
  160. data/lib/zm/client/share/shares_collection.rb +6 -3
  161. data/lib/zm/client/signature/signature.rb +6 -21
  162. data/lib/zm/client/signature/signature_jsns_builder.rb +12 -7
  163. data/lib/zm/client/signature/signature_jsns_initializer.rb +5 -4
  164. data/lib/zm/client/signature/signatures_builder.rb +1 -1
  165. data/lib/zm/client/signature/signatures_collection.rb +6 -5
  166. data/lib/zm/client/soap_request/request_methods_admin.rb +56 -0
  167. data/lib/zm/client/soap_request/request_methods_mailbox.rb +60 -0
  168. data/lib/zm/client/soap_request/soap_constants.rb +7 -0
  169. data/lib/zm/client/soap_request/soap_context.rb +11 -2
  170. data/lib/zm/client/soap_request.rb +3 -0
  171. data/lib/zm/client/tag/account_object_tags_collection.rb +11 -9
  172. data/lib/zm/client/tag/tag.rb +8 -44
  173. data/lib/zm/client/tag/tag_jsns_builder.rb +4 -2
  174. data/lib/zm/client/tag/tag_jsns_initializer.rb +7 -6
  175. data/lib/zm/client/tag/tags_builder.rb +1 -1
  176. data/lib/zm/client/tag/tags_collection.rb +6 -5
  177. data/lib/zm/client/task/task.rb +6 -5
  178. data/lib/zm/client/task/task_jsns_initializer.rb +28 -27
  179. data/lib/zm/client/task/tasks_builder.rb +1 -1
  180. data/lib/zm/client/task/tasks_collection.rb +2 -2
  181. data/lib/zm/client/token.rb +52 -0
  182. data/lib/zm/client/upload/upload.rb +101 -95
  183. data/lib/zm/client/zm_logger.rb +83 -0
  184. data/lib/zm/client.rb +6 -1
  185. data/lib/zm/modules/base.rb +0 -1
  186. data/lib/zm/modules/belongs_to_folder.rb +6 -7
  187. data/lib/zm/modules/belongs_to_tag.rb +3 -1
  188. data/lib/zm/modules/common/zimbra-attrs.csv +3 -4
  189. data/lib/zm/modules/inspector.rb +2 -2
  190. data/lib/zm/modules/missing_method_static_collection.rb +2 -2
  191. data/lib/zm/support/cache/entry.rb +63 -0
  192. data/lib/zm/support/cache/file_store.rb +141 -0
  193. data/lib/zm/support/cache/null_store.rb +43 -0
  194. data/lib/zm/support/cache/request_strategy.rb +10 -0
  195. data/lib/zm/support/cache/store.rb +197 -0
  196. data/lib/zm/support/cache/strategy.rb +13 -0
  197. data/lib/zm/support/cache.rb +26 -0
  198. data/lib/zm-ruby-client.rb +2 -2
  199. data/zm-ruby-client.gemspec +10 -15
  200. metadata +37 -36
  201. data/lib/zm/client/common/token_metadata.rb +0 -44
  202. data/lib/zm/modules/zm_logger.rb +0 -26
@@ -10,16 +10,12 @@ module Zm
10
10
  end
11
11
 
12
12
  def all
13
- @all || all!
14
- end
15
-
16
- def all!
17
13
  build_response
18
14
  end
15
+ alias all! all
19
16
 
20
17
  def clear
21
18
  reset_query_params
22
- @all.clear
23
19
  end
24
20
 
25
21
  def sections(*entries)
@@ -55,30 +51,42 @@ module Zm
55
51
 
56
52
  soap_request = SoapElement.account(SoapAccountConstants::GET_ACCOUNT_INFO_REQUEST)
57
53
 
58
- if @parent.id
59
- node_entry = SoapElement.create(SoapConstants::ACCOUNT).add_attribute(SoapConstants::BY, SoapConstants::ID).add_content(@parent.id)
60
- else
61
- node_entry = SoapElement.create(SoapConstants::ACCOUNT).add_attribute(SoapConstants::BY, SoapConstants::NAME).add_content(@parent.name)
62
- end
54
+ node_entry = if @parent.id
55
+ SoapElement.create(SoapConstants::ACCOUNT)
56
+ .add_attribute(SoapConstants::BY, SoapConstants::ID)
57
+ .add_content(@parent.id)
58
+ else
59
+ SoapElement.create(SoapConstants::ACCOUNT)
60
+ .add_attribute(SoapConstants::BY, SoapConstants::NAME)
61
+ .add_content(@parent.name)
62
+ end
63
63
 
64
64
  soap_request.add_node(node_entry)
65
65
 
66
- @zimbraMailHost = @parent.sacc.invoke(soap_request).dig(:GetAccountInfoResponse, :_attrs, :zimbraMailHost)
66
+ @zimbraMailHost = @parent.soap_connector
67
+ .invoke(soap_request)
68
+ .dig(:GetAccountInfoResponse, :_attrs, :zimbraMailHost)
67
69
  end
68
70
 
69
71
  private
70
72
 
71
73
  def build_response
72
- @all = make_query[:GetInfoResponse]
74
+ make_query[:GetInfoResponse]
73
75
  end
74
76
 
75
77
  def make_query
76
- soap_request = SoapElement.account(SoapAccountConstants::GET_INFO_REQUEST).add_attributes(jsns)
77
- @parent.sacc.invoke(soap_request)
78
+ soap_request = SoapElement.account(SoapAccountConstants::GET_INFO_REQUEST)
79
+ .add_attributes(jsns)
80
+ @parent.soap_connector.invoke(soap_request)
78
81
  end
79
82
 
80
83
  def jsns
81
- { rights: @rights.join(','), sections: @sections.join(',') }.reject { |_, v| v.empty? }
84
+ h = {
85
+ rights: @rights.join(','),
86
+ sections: @sections.join(',')
87
+ }
88
+ h.compact!
89
+ h
82
90
  end
83
91
 
84
92
  def reset_query_params
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'zm/client/connector/rest_account'
3
+ require 'zm/client/mailbox/mailbox_item_concern'
4
+ require 'zm/client/connector/rest_connector'
4
5
  require 'zm/client/signature'
5
6
  require 'zm/client/folder'
6
7
  require 'zm/client/mountpoint'
@@ -29,26 +30,47 @@ module Zm
29
30
  attr_writer :used, :domain_key
30
31
 
31
32
  def soap_account_connector
32
- @soap_account_connector ||= SoapAccountConnector.create(soap_config)
33
- end
34
- alias sacc soap_account_connector
33
+ return @soap_account_connector if defined? @soap_account_connector
35
34
 
36
- def rest_account_connector
37
- @rest_account_connector ||= RestAccountConnector.new
35
+ @soap_account_connector = SoapAccountConnector.create(soap_config)
38
36
  end
39
37
 
40
- alias rac rest_account_connector
38
+ def soap_connector
39
+ return @soap_connector if defined? @soap_connector
40
+
41
+ if logged?
42
+ @soap_connector = soap_account_connector
43
+ elsif (@id || @name) && @parent&.logged?
44
+ @soap_connector = @parent.soap_admin_connector.clone
45
+
46
+ if @id
47
+ @soap_connector.context.account(:id, @id)
48
+ else
49
+ @soap_connector.context.account(:name, @name)
50
+ end
51
+ else
52
+ raise ZmError, 'SoapConnector not defined'
53
+ end
54
+
55
+ @soap_connector
56
+ end
41
57
 
42
58
  def domain_name
43
- @domain_name ||= @name.split('@').last
59
+ return @domain_name if defined? @domain_name
60
+
61
+ @domain_name = @name.split('@').last
44
62
  end
45
63
 
46
64
  def infos
47
- @infos ||= MailboxInfosCollection.new(self)
65
+ return @infos if defined? @infos
66
+
67
+ @infos = MailboxInfosCollection.new(self)
48
68
  end
49
69
 
50
70
  def prefs
51
- @prefs ||= MailboxPrefsCollection.new(self)
71
+ return @prefs if defined? @prefs
72
+
73
+ @prefs = MailboxPrefsCollection.new(self)
52
74
  end
53
75
 
54
76
  def used
@@ -78,8 +100,32 @@ module Zm
78
100
  # Authentication
79
101
  # #################################################################
80
102
 
103
+ def token
104
+ return @token if defined? @token
105
+
106
+ @token = (Token.new(soap_account_connector.token) if soap_account_connector.token)
107
+ end
108
+
109
+ def token=(value)
110
+ @token = Token.new(soap_account_connector.token = value)
111
+ @soap_connector = soap_account_connector
112
+ end
113
+
81
114
  def logged?
82
- !@token.nil?
115
+ !token.nil? && !token.expired?
116
+ end
117
+
118
+ def alive?
119
+ soap_request = SoapElement.mail(SoapMailConstants::NO_OP_REQUEST)
120
+ soap_connector.invoke(soap_request)
121
+ true
122
+ rescue Zm::Client::SoapError => e
123
+ logger.warn "Mailbox session token alive ? #{e.message}"
124
+ false
125
+ end
126
+
127
+ def logged_and_alive?
128
+ logged? && alive?
83
129
  end
84
130
 
85
131
  def domain_key
@@ -97,7 +143,7 @@ module Zm
97
143
  end
98
144
 
99
145
  def account_login
100
- sacc.token = nil
146
+ soap_account_connector.token = nil
101
147
 
102
148
  if password
103
149
  account_login_password
@@ -107,21 +153,21 @@ module Zm
107
153
  end
108
154
 
109
155
  def account_login_preauth(expires = 0)
156
+ logger.info 'Get Account session token by preauth access'
110
157
  raise ZmError, 'domain key is required to login !' if domain_key.nil?
111
158
 
112
159
  content, by = account_content_by
113
160
 
114
- @token = sacc.auth_preauth(content, by, expires, domain_key)
115
- sacc.context.token(@token)
161
+ self.token = soap_account_connector.auth_preauth(content, by, expires, domain_key)
116
162
  end
117
163
 
118
164
  def account_login_password
165
+ logger.info 'Get Account session token by password access'
119
166
  raise ZmError, 'password is required to login !' if password.nil?
120
167
 
121
168
  content, by = account_content_by
122
169
 
123
- @token = sacc.auth_password(content, by, @password)
124
- sacc.context.token(@token)
170
+ self.token = soap_account_connector.auth_password(content, by, @password)
125
171
  end
126
172
 
127
173
  def account_content_by
@@ -129,7 +175,7 @@ module Zm
129
175
  end
130
176
 
131
177
  def admin_login
132
- # @token = sac.delegate_auth(@name)
178
+ logger.info 'Get Account session token by Delegate access'
133
179
 
134
180
  soap_request = SoapElement.admin(SoapAdminConstants::DELEGATE_AUTH_REQUEST)
135
181
  node_account = SoapElement.create(SoapConstants::ACCOUNT)
@@ -141,89 +187,120 @@ module Zm
141
187
  end
142
188
 
143
189
  soap_request.add_node(node_account)
144
- @token = sac.invoke(soap_request)[:DelegateAuthResponse][:authToken].first[:_content]
145
- sacc.context.token(@token)
190
+ self.token = sac.invoke(soap_request)[:DelegateAuthResponse][:authToken].first[:_content]
146
191
  end
147
192
 
148
193
  # #################################################################
149
194
  # Associations
150
195
  # #################################################################
151
196
 
152
- def token_metadata
153
- @token_metadata ||= TokenMetaData.new(@token)
154
- end
155
-
156
197
  def messages
157
- @messages ||= MessagesCollection.new(self)
198
+ return @messages if defined? @messages
199
+
200
+ @messages = MessagesCollection.new(self)
158
201
  end
159
202
 
160
203
  def folders
161
- @folders ||= FoldersCollection.new(self)
204
+ return @folders if defined? @folders
205
+
206
+ @folders = FoldersCollection.new(self)
162
207
  end
163
208
 
164
209
  def mountpoints
165
- @mountpoints ||= MountPointsCollection.new(self)
210
+ return @mountpoints if defined? @mountpoints
211
+
212
+ @mountpoints = MountPointsCollection.new(self)
166
213
  end
167
214
 
168
215
  def search_folders
169
- @search_folders ||= SearchFoldersCollection.new(self)
216
+ return @search_folders if defined? @search_folders
217
+
218
+ @search_folders = SearchFoldersCollection.new(self)
170
219
  end
171
220
 
172
221
  def identities
173
- @identities ||= IdentitiesCollection.new(self)
222
+ return @identities if defined? @identities
223
+
224
+ @identities = IdentitiesCollection.new(self)
174
225
  end
175
226
 
176
227
  def shares
177
- @shares ||= SharesCollection.new(self)
228
+ return @shares if defined? @shares
229
+
230
+ @shares = SharesCollection.new(self)
178
231
  end
179
232
 
180
233
  def contacts
181
- @contacts ||= ContactsCollection.new(self)
234
+ return @contacts if defined? @contacts
235
+
236
+ @contacts = ContactsCollection.new(self)
182
237
  end
183
238
 
184
239
  def appointments
185
- @appointments ||= AppointmentsCollection.new(self)
240
+ return @appointments if defined? @appointments
241
+
242
+ @appointments = AppointmentsCollection.new(self)
186
243
  end
187
244
 
188
245
  def tags
189
- @tags ||= TagsCollection.new(self)
246
+ return @tags if defined? @tags
247
+
248
+ @tags = TagsCollection.new(self)
190
249
  end
191
250
 
192
251
  def tasks
193
- @tasks ||= TasksCollection.new(self)
252
+ return @tasks if defined? @tasks
253
+
254
+ @tasks = TasksCollection.new(self)
194
255
  end
195
256
 
196
257
  def aces
197
- @aces ||= AcesCollection.new(self)
258
+ return @aces if defined? @aces
259
+
260
+ @aces = AcesCollection.new(self)
198
261
  end
199
262
  alias rights aces
200
263
 
201
264
  def signatures
202
- @signatures ||= SignaturesCollection.new(self)
265
+ return @signatures if defined? @signatures
266
+
267
+ @signatures = SignaturesCollection.new(self)
203
268
  end
204
269
 
205
270
  def documents
206
- @documents ||= DocumentsCollection.new(self)
271
+ return @documents if defined? @documents
272
+
273
+ @documents = DocumentsCollection.new(self)
207
274
  end
208
275
 
209
276
  def memberships
210
- @memberships ||= AccountDlsMembershipCollection.new(self)
277
+ return @memberships if defined? @memberships
278
+
279
+ @memberships = AccountDlsMembershipCollection.new(self)
211
280
  end
212
281
 
213
282
  def dls_owner
214
- @dls_owner ||= AccountDlsOwnerCollection.new(self)
283
+ return @dls_owner if defined? @dls_owner
284
+
285
+ @dls_owner = AccountDlsOwnerCollection.new(self)
215
286
  end
216
287
 
217
288
  def filter_rules
218
- @filter_rules ||= FilterRulesCollection.new(self)
289
+ return @filter_rules if defined? @filter_rules
290
+
291
+ @filter_rules = FilterRulesCollection.new(self)
219
292
  end
220
293
 
221
294
  def outgoing_filter_rules
222
- @outgoing_filter_rules ||= OutgoingFilterRulesCollection.new(self)
295
+ return @outgoing_filter_rules if defined? @outgoing_filter_rules
296
+
297
+ @outgoing_filter_rules = OutgoingFilterRulesCollection.new(self)
223
298
  end
224
299
 
225
300
  def data_sources
226
- @data_sources ||= DataSourcesCollection.new(self)
301
+ return @data_sources if defined? @data_sources
302
+
303
+ @data_sources = DataSourcesCollection.new(self)
227
304
  end
228
305
 
229
306
  # #################################################################
@@ -241,26 +318,6 @@ module Zm
241
318
  @password = new_password
242
319
  end
243
320
 
244
- def rename!(email)
245
- soap_request = SoapElement.admin(SoapAdminConstants::RENAME_ACCOUNT_REQUEST)
246
- soap_request.add_attributes({ id: @id, newName: email })
247
- sac.invoke(soap_request)
248
-
249
- @name = email
250
- end
251
-
252
- def update!(hash)
253
- return false if hash.delete_if { |k, v| v.nil? || !respond_to?(k) }.empty?
254
-
255
- do_update!(hash)
256
-
257
- hash.each do |key, value|
258
- update_attribute(key, value)
259
- end
260
-
261
- true
262
- end
263
-
264
321
  def local_transport
265
322
  raise Zm::Client::ZmError, 'zimbraMailHost is null' if zimbraMailHost.nil?
266
323
 
@@ -272,34 +329,82 @@ module Zm
272
329
  end
273
330
 
274
331
  def is_local_transport?
275
- return nil unless zimbraMailTransport
332
+ return false unless zimbraMailTransport
276
333
 
277
334
  zimbraMailTransport.start_with?(SoapConstants::LMTP)
278
335
  end
279
336
 
280
337
  def is_external_transport?
281
- return nil unless zimbraMailTransport
338
+ return false unless zimbraMailTransport
282
339
 
283
340
  zimbraMailTransport.start_with?(SoapConstants::SMTP)
284
341
  end
285
342
 
286
343
  def last_logon
287
- @last_logon ||= Time.parse(zimbraLastLogonTimestamp) unless zimbraLastLogonTimestamp.nil?
344
+ return @last_logon if defined? @last_logon
345
+
346
+ @last_logon = Time.parse(zimbraLastLogonTimestamp) unless zimbraLastLogonTimestamp.nil?
288
347
  end
289
348
 
290
349
  # #################################################################
291
350
 
292
- def uploader
293
- @uploader ||= Upload.new(self)
351
+ def build_uploader
352
+ tmp_token = soap_connector&.token
353
+ raise ZmError, 'token have to be set to instance Upload class' unless tmp_token
354
+
355
+ Upload.new(rest_url, tmp_token, is_token_admin: soap_connector.is_a?(SoapAdminConnector), **rest_options)
356
+ end
357
+
358
+ def rest_options
359
+ if soap_config
360
+ {
361
+ timeout: soap_config.timeout,
362
+ verbose: soap_config.logger.debug?
363
+ }
364
+ else
365
+ {}
366
+ end
367
+ end
368
+
369
+ def rest_url
370
+ raise ZmError, 'name attribute is requuired for REST Url' unless @name
371
+
372
+ if logged?
373
+ rest_account_url
374
+ elsif parent_logged?
375
+ rest_admin_url
376
+ else
377
+ raise ZmError, 'impossible to set rest_url'
378
+ end
379
+ end
380
+
381
+ def rest_admin_url
382
+ raise ZmError, 'impossible to set rest_admin_url' unless soap_config.zimbra_admin_url
383
+
384
+ File.join(soap_config.zimbra_admin_url, 'home', @name)
385
+ end
386
+
387
+ def rest_account_url
388
+ if soap_config.zimbra_public_url
389
+ File.join(soap_config.zimbra_public_url, 'home', @name)
390
+ elsif home_url
391
+ home_url
392
+ else
393
+ raise ZmError, 'impossible to set rest_account_url'
394
+ end
294
395
  end
295
396
 
296
397
  private
297
398
 
298
399
  def soap_config
299
- return @parent.config if @parent.respond_to?(:config)
300
- return @parent.parent.config if @parent.respond_to?(:parent) && @parent.parent.respond_to?(:config)
400
+ return @soap_config if defined? @soap_config
401
+ return unless @parent
301
402
 
302
- nil
403
+ if @parent.respond_to?(:config)
404
+ @soap_config = @parent.config
405
+ elsif @parent.respond_to?(:parent) && @parent.parent.respond_to?(:config)
406
+ @soap_config = @parent.parent.config
407
+ end
303
408
  end
304
409
 
305
410
  def parent_logged?
@@ -9,16 +9,12 @@ module Zm
9
9
  end
10
10
 
11
11
  def all
12
- @all || all!
13
- end
14
-
15
- def all!
16
12
  build_response
17
13
  end
14
+ alias all! all
18
15
 
19
16
  def clear
20
17
  reset_query_params
21
- @all.clear
22
18
  end
23
19
 
24
20
  def preferences(*entries)
@@ -48,18 +44,18 @@ module Zm
48
44
  }
49
45
 
50
46
  soap_request = SoapElement.account(SoapAccountConstants::MODIFY_PREFS_REQUEST).add_attributes(req)
51
- @parent.sacc.invoke(soap_request)
47
+ @parent.soap_connector.invoke(soap_request)
52
48
  end
53
49
 
54
50
  private
55
51
 
56
52
  def build_response
57
- @all = make_query.dig(:GetPrefsResponse, :_attrs)
53
+ make_query.dig(:GetPrefsResponse, :_attrs)
58
54
  end
59
55
 
60
56
  def make_query
61
57
  soap_request = SoapElement.account(SoapAccountConstants::GET_PREFS_REQUEST).add_attributes(jsns)
62
- @parent.sacc.invoke(soap_request)
58
+ @parent.soap_connector.invoke(soap_request)
63
59
  end
64
60
 
65
61
  def jsns
@@ -46,12 +46,12 @@ module Zm
46
46
  end
47
47
 
48
48
  def to_h
49
- Hash[instance_variables_map]
49
+ instance_variables_map.to_h
50
50
  end
51
51
 
52
52
  def inspect
53
53
  keys_str = to_h.map { |k, v| "#{k}: #{v}" }.join(', ')
54
- "#{self.class}:#{format('0x00%x', (object_id << 1))} #{keys_str}"
54
+ "#{self.class}:#{format('0x00%x', object_id << 1)} #{keys_str}"
55
55
  end
56
56
 
57
57
  def instance_variables_map
@@ -11,17 +11,21 @@ module Zm
11
11
  end
12
12
 
13
13
  def ids
14
- @json[:Body][json_key][:hit]&.map { |s| s[:id] } || []
14
+ @json.dig(:Body, json_key, :hit)&.map { |s| s[:id] } || []
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def json_items
20
- @json_items ||= @json[json_key][@json_item_key]
20
+ return @json_items if defined? @json_items
21
+
22
+ @json_items = @json[json_key][@json_item_key]
21
23
  end
22
24
 
23
25
  def json_key
24
- @json_key ||= @json.keys.first
26
+ return @json_key if defined? @json_key
27
+
28
+ @json_key = @json.keys.first
25
29
  end
26
30
  end
27
31
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  module Zm
5
4
  module Client
6
5
  module Base
@@ -27,45 +26,37 @@ module Zm
27
26
  end
28
27
 
29
28
  def all
30
- @all || all!
31
- end
32
-
33
- def all!
34
- @all = build_response
29
+ build_response
35
30
  end
31
+ alias all! all
36
32
 
37
33
  def per_page(limit)
38
34
  return self if @limit == limit
39
35
 
40
- @all = nil
41
36
  @limit = limit
42
37
  self
43
38
  end
44
-
45
39
  alias limit per_page
46
40
 
47
41
  def page(offset)
48
42
  return self if @offset == offset
49
43
 
50
- @all = nil
51
44
  @offset = offset
52
45
  self
53
46
  end
54
-
55
47
  alias offset page
56
48
 
57
49
  def order(sort_by, sort_ascending = SoapUtils::ON)
58
50
  return self if @sort_by == sort_by && @sort_ascending == sort_ascending
59
51
 
60
- @all = nil
61
52
  @sort_by = sort_by
62
53
  @sort_ascending = sort_ascending
63
54
  self
64
55
  end
65
56
 
66
- def method_missing(method, *args, &block)
57
+ def method_missing(method, *, &)
67
58
  if METHODS_MISSING_LIST.include?(method)
68
- build_response.send(method, *args, &block)
59
+ build_response.send(method, *, &)
69
60
  else
70
61
  super
71
62
  end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
- require 'version_sorter'
5
-
6
3
  module Zm
7
4
  module Client
8
5
  module Base
9
6
  class ZimbraAttribute
10
- attr_reader :name, :optionalIn, :flags, :requiredIn, :cardinality, :callback, :immutable, :type, :value, :max, :min, :since
7
+ attr_reader :name, :optionalIn, :flags, :requiredIn, :cardinality, :callback, :immutable, :type, :value, :max,
8
+ :min, :since
11
9
 
12
- def initialize(name: nil, optionalIn: nil, flags: nil, requiredIn: nil, cardinality: nil, callback: nil, immutable: nil, type: nil, value: nil, max: nil, min: nil, since: nil)
10
+ def initialize(name: nil, optionalIn: nil, flags: nil, requiredIn: nil, cardinality: nil, callback: nil,
11
+ immutable: nil, type: nil, value: nil, max: nil, min: nil, since: nil)
13
12
  @name = name
14
13
  @optionalIn = optionalIn.to_s.split(',')
15
14
  @flags = flags
@@ -24,18 +23,6 @@ module Zm
24
23
  @since = since
25
24
  end
26
25
 
27
- def version_start
28
- return @version_start unless @version_start.nil?
29
-
30
- @version_start = if since.nil?
31
- '0.0.0'
32
- else
33
- VersionSorter.sort(since.split(',')).first
34
- end
35
-
36
- @version_start
37
- end
38
-
39
26
  def immutable?
40
27
  immutable == '1'
41
28
  end