zm-ruby-client 0.10.4 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +39 -17
  6. data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
  7. data/lib/zm/client/account/accounts_builder.rb +6 -3
  8. data/lib/zm/client/account/accounts_collection.rb +11 -20
  9. data/lib/zm/client/account.rb +1 -0
  10. data/lib/zm/client/ace/ace.rb +22 -9
  11. data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
  12. data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
  13. data/lib/zm/client/ace/aces_builder.rb +6 -9
  14. data/lib/zm/client/ace/aces_collection.rb +23 -9
  15. data/lib/zm/client/ace.rb +2 -0
  16. data/lib/zm/client/appointment/appointment.rb +9 -6
  17. data/lib/zm/client/appointment/appointments_collection.rb +6 -90
  18. data/lib/zm/client/backup/backup.rb +8 -4
  19. data/lib/zm/client/base/account_object.rb +34 -0
  20. data/lib/zm/client/base/account_objects_collection.rb +14 -0
  21. data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
  22. data/lib/zm/client/base/admin_object.rb +6 -0
  23. data/lib/zm/client/base/admin_objects_collection.rb +65 -0
  24. data/lib/zm/client/base/base_jsns_builder.rb +19 -0
  25. data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
  26. data/lib/zm/client/base/folder_object.rb +41 -0
  27. data/lib/zm/client/base/ldap_filter.rb +33 -0
  28. data/lib/zm/client/base/object.rb +19 -0
  29. data/lib/zm/client/base/objects_builder.rb +4 -0
  30. data/lib/zm/client/base/objects_collection.rb +11 -32
  31. data/lib/zm/client/base/zimbra_attribute.rb +119 -0
  32. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
  33. data/lib/zm/client/base.rb +15 -0
  34. data/lib/zm/client/cluster/cluster.rb +47 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/common/token_metadata.rb +44 -0
  37. data/lib/zm/client/common.rb +2 -1
  38. data/lib/zm/client/connector/rest_account.rb +0 -3
  39. data/lib/zm/client/connector/soap_account.rb +66 -122
  40. data/lib/zm/client/connector/soap_admin.rb +47 -15
  41. data/lib/zm/client/connector/soap_base.rb +11 -3
  42. data/lib/zm/client/contact/contact.rb +2 -1
  43. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  44. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  45. data/lib/zm/client/cos/cos.rb +9 -5
  46. data/lib/zm/client/cos/coses_builder.rb +1 -16
  47. data/lib/zm/client/cos/coses_collection.rb +6 -9
  48. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  49. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  50. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  51. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  52. data/lib/zm/client/distributionlist.rb +1 -0
  53. data/lib/zm/client/document/document.rb +11 -9
  54. data/lib/zm/client/domain/domain.rb +23 -7
  55. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  56. data/lib/zm/client/domain/domains_builder.rb +1 -19
  57. data/lib/zm/client/domain/domains_collection.rb +7 -10
  58. data/lib/zm/client/domain.rb +1 -0
  59. data/lib/zm/client/folder/folder.rb +50 -124
  60. data/lib/zm/client/folder/folder_grant.rb +44 -22
  61. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  62. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  63. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  64. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  65. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  66. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  67. data/lib/zm/client/folder/folders_builder.rb +2 -2
  68. data/lib/zm/client/folder/folders_collection.rb +46 -19
  69. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  70. data/lib/zm/client/folder.rb +6 -0
  71. data/lib/zm/client/identity/identities_builder.rb +4 -15
  72. data/lib/zm/client/identity/identities_collection.rb +7 -13
  73. data/lib/zm/client/identity/identity.rb +9 -7
  74. data/lib/zm/client/message/message.rb +111 -21
  75. data/lib/zm/client/message/messages_builder.rb +1 -1
  76. data/lib/zm/client/message/messages_collection.rb +10 -92
  77. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  78. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  79. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  80. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  81. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  82. data/lib/zm/client/mountpoint.rb +2 -0
  83. data/lib/zm/client/resource/resource.rb +5 -5
  84. data/lib/zm/client/resource/resources_builder.rb +1 -16
  85. data/lib/zm/client/resource/resources_collection.rb +5 -13
  86. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  87. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  88. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  89. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  90. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  91. data/lib/zm/client/search_folder.rb +2 -0
  92. data/lib/zm/client/server/server.rb +7 -14
  93. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  94. data/lib/zm/client/server/servers_builder.rb +4 -16
  95. data/lib/zm/client/server/servers_collection.rb +5 -10
  96. data/lib/zm/client/server.rb +1 -0
  97. data/lib/zm/client/share/share.rb +2 -9
  98. data/lib/zm/client/share/shares_builder.rb +3 -12
  99. data/lib/zm/client/signature/signature.rb +17 -13
  100. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  101. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  102. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  103. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  104. data/lib/zm/client/signature.rb +1 -0
  105. data/lib/zm/client/tag/tag.rb +27 -20
  106. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  107. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  108. data/lib/zm/client/tag/tags_builder.rb +6 -9
  109. data/lib/zm/client/tag/tags_collection.rb +6 -12
  110. data/lib/zm/client/tag.rb +2 -0
  111. data/lib/zm/client/task/tasks_collection.rb +6 -90
  112. data/lib/zm/client/upload/upload.rb +1 -1
  113. data/lib/zm/client/version.rb +2 -2
  114. data/lib/zm/modules/common/dl_common.rb +6 -1
  115. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  116. data/lib/zm/modules/zm_logger.rb +24 -0
  117. data/lib/zm/modules/zm_model.rb +41 -0
  118. data/test/accounts.rb +15 -1
  119. data/test/ace.rb +50 -0
  120. data/test/cluster.rb +41 -0
  121. data/test/cluster_zimbra_attributes.rb +38 -0
  122. data/test/domains.rb +8 -0
  123. data/test/folder.rb +125 -0
  124. data/test/folder_grant.rb +51 -0
  125. data/test/mountpoint.rb +49 -0
  126. data/test/retention_policies.rb +40 -0
  127. data/test/search_folder.rb +67 -0
  128. data/test/signature.rb +53 -0
  129. data/test/tag.rb +65 -0
  130. data/test/zimbra_attributes.rb +35 -0
  131. data/zm-ruby-client.gemspec +1 -0
  132. metadata +60 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2179dff314053e41480d35e8dc012dc64509f4f51939682daf89fe96a3ed9bf3
4
- data.tar.gz: 9b27f7a2c40226ba8691cd19afa8647a86fb3596a5b6a724a693637ccbc760f9
3
+ metadata.gz: 4de72020fc5b06ed81e86eec0c27f10fbbd9d09de6f65d3299f8ed467cb5058f
4
+ data.tar.gz: fcc142156bdc55b58c33c66433bf7ca278ff396381514f646b74b6101b26115d
5
5
  SHA512:
6
- metadata.gz: 364b6e0e612a76caf9350129e0adf852a5ad7847c7d79d306bbaa53a289802462d3324a862ff827c5087150ade21236d0bd287d8ad92844da0c46a149ce13904
7
- data.tar.gz: c49afd819b6a5bd34fa1e9bc0f2a9fe6705c2d41389174c83a2f1e5bcdc97f0a48d2af5b02cb1e0f771ed363b8d9c2dca13475fbc45f8726f6a35fe6cad11dc6
6
+ metadata.gz: 2df2ca3bdcc7ee18ebcb865e34d5a8335e2da2eff4191c83261d20ced0510f8434081f0b33ea186af791e81c56ded88b084375eed245277810cc6157282e9ce4
7
+ data.tar.gz: dfaa387e98fc19098640927f85d4318119d9c198c8d9e95a991c3d90fe13d1fea0524e26b2fabec1c2d6ac9d25f7dc06f5a9d7fb4105fdf280206584a62e9ae4
data/.gitignore CHANGED
@@ -12,6 +12,7 @@
12
12
  /test/fixtures/
13
13
  /test/version_tmp/
14
14
  /tmp/
15
+ /demo/
15
16
  /.idea
16
17
  /zm-ruby-client.iml
17
18
 
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gem 'addressable', '~> 2.6'
6
6
  gem 'curb', '~> 0.9.8'
7
7
  gem 'nokogiri', '~>1.10.1'
8
8
  gem 'gyoku', '~>1.3.1'
9
+ gem 'version_sorter'
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Library to interface with Zimbra simply.
4
4
 
5
+ ## Installation
6
+
7
+ ```bash
8
+ sudo apt install make gcc curl libcurl4-openssl-dev
9
+ ```
10
+
5
11
  ## Examples of uses:
6
12
 
7
13
  ### Connection:
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'zm/modules/common/account_common'
4
4
  # require_relative '../../modules/common/account_galsync'
5
+ require 'zm/client/common'
5
6
  require 'zm/client/connector/rest_account'
6
7
  require 'zm/client/signature'
7
8
  require 'zm/client/folder'
@@ -24,27 +25,28 @@ module Zm
24
25
  module Client
25
26
  # objectClass: zimbraAccount
26
27
  class Account < Base::AdminObject
27
- attr_reader :name, :id, :token
28
- attr_writer :home_url
29
- attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense
28
+ # attr_reader :name, :id, :token
29
+ # attr_writer :home_url
30
+ # attr_accessor :password, :domainkey, :company, :zimbraCOSId, :zimbraMailHost, :zimbraMailTransport, :carLicense
31
+ attr_accessor :name, :id, :token, :home_url, :password, :domainkey, :carLicense
30
32
 
31
- def initialize(parent, attrs = {})
32
- extend(AccountCommon)
33
+ def initialize(parent)
34
+ # extend(AccountCommon)
33
35
  super(parent)
34
36
  @grantee_type = 'usr'.freeze
35
37
  end
36
38
 
37
- def init_by_hash(attrs)
38
- attrs.each do |k, v|
39
- self.instance_variable_set(arrow_name(k), v)
40
- end
41
- end
39
+ # def init_by_hash(attrs)
40
+ # attrs.each do |k, v|
41
+ # self.instance_variable_set(arrow_name(k), v)
42
+ # end
43
+ # end
42
44
 
43
- def to_h
44
- hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
45
- hashmap.delete_if { |_, v| v.nil? }
46
- hashmap
47
- end
45
+ # def to_h
46
+ # hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
47
+ # hashmap.delete_if { |_, v| v.nil? }
48
+ # hashmap
49
+ # end
48
50
 
49
51
  def all_instance_variable_keys
50
52
  AccountCommon::ZM_ACCOUNT_ATTRS
@@ -93,8 +95,12 @@ module Zm
93
95
  @token = sac.delegate_auth(@name)
94
96
  end
95
97
 
98
+ def token_metadata
99
+ @token_metadata ||= TokenMetaData.new(@token)
100
+ end
101
+
96
102
  def domain_name
97
- @name.split('@').last
103
+ @domain_name ||= @name.split('@').last
98
104
  end
99
105
 
100
106
  def domain_key
@@ -102,7 +108,7 @@ module Zm
102
108
  end
103
109
 
104
110
  def infos
105
- @infos ||= read_infos
111
+ @infos || read_infos
106
112
  end
107
113
 
108
114
  def read_infos
@@ -112,6 +118,7 @@ module Zm
112
118
  @public_url = @infos[:publicURL]
113
119
  @zimbraCOSId = @infos[:cos][:id]
114
120
  @home_url = @infos[:rest]
121
+ @infos
115
122
  end
116
123
 
117
124
  def cos
@@ -213,6 +220,11 @@ module Zm
213
220
  sac.delete_account(@id)
214
221
  end
215
222
 
223
+ def password!(new_password)
224
+ sac.set_password(@id, new_password)
225
+ @password = new_password
226
+ end
227
+
216
228
  def update!(hash)
217
229
  sac.modify_account(@id, hash)
218
230
 
@@ -243,6 +255,12 @@ module Zm
243
255
  @id = rep[:Body][:CreateAccountResponse][:account].first[:id]
244
256
  end
245
257
 
258
+ def set_password(new_password = nil)
259
+ new_password ||= @password
260
+ sac.set_password(@id, new_password)
261
+ @password = new_password
262
+ end
263
+
246
264
  def aliases
247
265
  @aliases ||= set_aliases
248
266
  end
@@ -325,6 +343,10 @@ module Zm
325
343
  @dls_owner ||= AccountDlsOwnerCollection.new(self)
326
344
  end
327
345
 
346
+ def ranking(op, email = nil)
347
+ sacc.ranking_action(@token, op, email)
348
+ end
349
+
328
350
  def init_from_json(json)
329
351
  @used = json[:used] if json[:used]
330
352
  @zimbraMailQuota = json[:limit] if json[:limit]
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account
6
+ class AccountJsnsInitializer
7
+ class << self
8
+ def create(parent, json)
9
+ item = Account.new(parent)
10
+
11
+ update(item, json)
12
+ end
13
+
14
+ def update(item, json)
15
+
16
+ attr_types_h = item.parent.zimbra_attributes.all_account_attr_types_h
17
+
18
+ # puts attr_types_h
19
+
20
+ item.id = json[:id]
21
+ item.name = json[:name]
22
+
23
+ json[:a].reject! { |n| n[:n].nil? }
24
+ json_map = Hash[json[:a].map { |n| [n[:n], n[:_content]] }].freeze
25
+
26
+ # puts json_map
27
+
28
+ # item.parent.zimbra_attributes.all_account_attrs.each do |attr|
29
+ # if attr.type.nil?
30
+ # # p attr
31
+ # else
32
+ # json_field = json_map[attr.name]
33
+ # puts json_field unless json_field.nil?
34
+ # end
35
+ # end
36
+
37
+ item.init_from_json(json)
38
+
39
+ item
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -7,12 +7,15 @@ module Zm
7
7
  def initialize(parent, json)
8
8
  super(parent, json)
9
9
  @child_class = Account
10
+ @json_item_key = :account
10
11
  end
11
12
 
12
- private
13
+ def make
14
+ return [] if json_items.nil?
13
15
 
14
- def json_items
15
- @json_items ||= @json[:Body][json_key][:account]
16
+ json_items.map do |entry|
17
+ AccountJsnsInitializer.create(@parent, entry)
18
+ end
16
19
  end
17
20
  end
18
21
  end
@@ -3,45 +3,36 @@
3
3
  module Zm
4
4
  module Client
5
5
  # Collection Accounts
6
- class AccountsCollection < Base::ObjectsCollection
6
+ class AccountsCollection < Base::AdminObjectsCollection
7
7
  def initialize(parent)
8
8
  @child_class = Account
9
- @parent = parent
10
- reset_query_params
11
- end
12
-
13
- def ldap
14
- @apply_cos = 0
15
- self
9
+ @builder_class = AccountsBuilder
10
+ @search_type = SearchType::ACCOUNT
11
+ super(parent)
16
12
  end
17
13
 
18
14
  def find_by(hash)
19
15
  rep = sac.get_account(hash.values.first, hash.keys.first, attrs_comma, @apply_cos)
20
- reset_query_params
21
16
  entry = rep[:Body][:GetAccountResponse][:account].first
17
+ # puts entry
22
18
 
19
+ reset_query_params
23
20
  build_from_entry(entry)
24
21
  end
25
22
 
26
- def find_all_quotas(domain_name = nil, target_server_id = nil)
27
- json = sac.get_quota_usage(domain_name, @all_servers, @limit, @offset, @sort_by, @sort_ascending, @refresh, target_server_id)
23
+ def quotas
24
+ return nil if @domain_name.nil? && @target_server_id.nil?
25
+
26
+ json = sac.get_quota_usage(@domain_name, @all_servers, @limit, @offset, @sort_by, @sort_ascending, @refresh, @target_server_id)
28
27
  reset_query_params
29
- AccountsBuilder.new(@parent, json).make
28
+ @builder_class.new(@parent, json).make
30
29
  end
31
30
 
32
31
  private
33
32
 
34
- def build_response
35
- AccountsBuilder.new(@parent, make_query).make
36
- end
37
-
38
33
  def reset_query_params
39
34
  super
40
- @search_type = SearchType::ACCOUNT
41
35
  @attrs = SearchType::Attributes::ACCOUNT.dup
42
- @all_servers = 1
43
- @refresh = 0
44
- @apply_cos = 1
45
36
  end
46
37
  end
47
38
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/account/account'
4
+ require 'zm/client/account/account_jsns_initializer'
4
5
  require 'zm/client/account/accounts_builder'
5
6
  require 'zm/client/account/accounts_collection'
6
7
  require 'zm/client/account/account_dls_membership_collection'
@@ -9,23 +9,36 @@ module Zm
9
9
 
10
10
  attr_accessor *INSTANCE_VARIABLE_KEYS
11
11
 
12
- def init_from_json(json)
13
- INSTANCE_VARIABLE_KEYS.each do |key|
14
- var_name = "@#{key}"
15
- instance_variable_set(var_name, json[key])
16
- end
12
+ def all_instance_variable_keys
13
+ INSTANCE_VARIABLE_KEYS
17
14
  end
18
15
 
19
16
  def create!
20
- # todo
17
+ rep = @parent.sacc.grant_rights(get_token, jsns_builder.to_jsns)
18
+ json = rep[:Body][:GrantRightsResponse][:ace].first if rep[:Body][:GrantRightsResponse][:ace].is_a?(Array)
19
+ AceJsnsInitializer.update(self, json) unless json.nil?
20
+ true
21
21
  end
22
22
 
23
23
  def delete!
24
- # todo
24
+ @parent.sacc.revoke_rights(get_token, jsns_builder.to_delete)
25
+ @parent.all.delete(self)
26
+ true
25
27
  end
26
28
 
27
- def rename!(new_name)
28
- # todo
29
+ private
30
+
31
+ def jsns_builder
32
+ @jsns_builder ||= AceJsnsBuilder.new(self)
33
+ end
34
+
35
+ def get_token(target = self)
36
+ token = nil
37
+ return target.token if target.respond_to?(:token) && !target.token.nil?
38
+
39
+ token = get_token(target.parent) if target.respond_to?(:parent)
40
+
41
+ token
29
42
  end
30
43
  end
31
44
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder jsns builder
6
+ class AceJsnsBuilder < Base::BaseJsnsBuilder
7
+
8
+ def to_find
9
+ return nil if @item.rights.empty?
10
+
11
+ ace = @item.rights.map { |r| { right: r } }
12
+ { ace: ace }
13
+ end
14
+
15
+ def to_jsns
16
+ ace = {
17
+ zid: @item.zid,
18
+ gt: @item.gt,
19
+ right: @item.right,
20
+ d: @item.d
21
+ }.reject { |_, v| v.nil? }
22
+
23
+ { ace: ace }
24
+ end
25
+
26
+ def to_delete
27
+ ace = {
28
+ zid: @item.zid,
29
+ gt: @item.gt,
30
+ right: @item.right,
31
+ d: @item.d
32
+ }.reject { |_, v| v.nil? }
33
+
34
+ { ace: ace }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account ace
6
+ class AceJsnsInitializer
7
+ class << self
8
+ def create(parent, json)
9
+ item = Ace.new(parent)
10
+
11
+ update(item, json)
12
+ end
13
+
14
+ def update(item, json)
15
+
16
+ item.instance_variable_set(:@zid, json[:zid])
17
+ item.instance_variable_set(:@gt, json[:gt])
18
+ item.instance_variable_set(:@right, json[:right])
19
+ item.instance_variable_set(:@d, json[:d])
20
+
21
+ item
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,19 +5,16 @@ module Zm
5
5
  # class factory [aces]
6
6
  class AcesBuilder < Base::ObjectsBuilder
7
7
  def initialize(parent, json)
8
- @parent = parent
9
- @json = json
8
+ super(parent, json)
9
+ @child_class = Ace
10
+ @json_item_key = :ace
10
11
  end
11
12
 
12
13
  def make
13
- root = @json[:Body][:GetRightsResponse][:ace]
14
- return [] if root.nil?
14
+ return [] if json_items.nil?
15
15
 
16
- root = [root] unless root.is_a?(Array)
17
- root.map do |s|
18
- ace = Ace.new(@parent)
19
- ace.init_from_json(s)
20
- ace
16
+ json_items.map do |entry|
17
+ AceJsnsInitializer.create(@parent, entry)
21
18
  end
22
19
  end
23
20
  end
@@ -3,33 +3,47 @@
3
3
  module Zm
4
4
  module Client
5
5
  # collection account aces
6
- class AcesCollection < Base::ObjectsCollection
6
+ class AcesCollection < Base::AccountObjectsCollection
7
+ attr_reader :rights
8
+
7
9
  def initialize(parent)
8
- @parent = parent
10
+ super(parent)
11
+ @builder_class = AcesBuilder
12
+ @jsns_builder = AceJsnsBuilder.new(self)
9
13
  reset_query_params
10
14
  end
11
15
 
12
16
  def new
13
- ace = Ace.new(@parent)
17
+ ace = Ace.new(self)
14
18
  yield(ace) if block_given?
15
19
  ace
16
20
  end
17
21
 
18
- def rights(*rights)
19
- @rights = rights
22
+ def where(*rights)
23
+ @rights += rights
24
+ @rights.uniq!
20
25
  self
21
26
  end
22
27
 
28
+ def soap_account_connector
29
+ @parent.soap_account_connector
30
+ end
31
+
32
+ alias sacc soap_account_connector
33
+
23
34
  private
24
35
 
36
+ def make_query
37
+ @parent.sacc.get_rights(@parent.token, @jsns_builder.to_find)
38
+ end
39
+
25
40
  def build_response
26
- rep = @parent.sacc.get_rights(@parent.token, @rights)
27
- ab = AcesBuilder.new @parent, rep
28
- ab.make
41
+ @builder_class.new(self, make_query).make
29
42
  end
30
43
 
31
44
  def reset_query_params
32
- @rights = %i[sendAs sendOnBehalfOf]
45
+ # @rights = %i[sendAs sendOnBehalfOf]
46
+ @rights = []
33
47
  end
34
48
  end
35
49
  end
data/lib/zm/client/ace.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/ace/ace'
4
+ require 'zm/client/ace/ace_jsns_builder'
5
+ require 'zm/client/ace/ace_jsns_initializer'
4
6
  require 'zm/client/ace/aces_builder'
5
7
  require 'zm/client/ace/aces_collection'
@@ -15,7 +15,6 @@ module Zm
15
15
  alias description desc
16
16
  alias parent_id l
17
17
 
18
- # def initialize(parent, json = nil)
19
18
  def initialize(parent)
20
19
  @parent = parent
21
20
  @recipients = Recipients.new
@@ -26,8 +25,8 @@ module Zm
26
25
  yield(self) if block_given?
27
26
  end
28
27
 
29
- def concat
30
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
28
+ def all_instance_variable_keys
29
+ INSTANCE_VARIABLE_KEYS
31
30
  end
32
31
 
33
32
  def folder
@@ -41,7 +40,6 @@ module Zm
41
40
  end
42
41
 
43
42
  def create!
44
- jsns_builder = AppointmentJsnsBuilder.new(self)
45
43
  rep = @parent.sacc.create_appointment(@parent.token, jsns_builder.to_jsns)
46
44
  rep_h = rep[:Body][:CreateAppointmentResponse]
47
45
 
@@ -51,7 +49,6 @@ module Zm
51
49
  end
52
50
 
53
51
  def modify!
54
- jsns_builder = AppointmentJsnsBuilder.new(self)
55
52
  @parent.sacc.modify_appointment(@parent.token, jsns_builder.to_update)
56
53
  end
57
54
 
@@ -64,8 +61,8 @@ module Zm
64
61
  end
65
62
 
66
63
  def delete!
67
- jsns_builder = AppointmentJsnsBuilder.new(self)
68
64
  @parent.sacc.cancel_appointment(@parent.token, jsns_builder.to_delete)
65
+ super
69
66
  end
70
67
 
71
68
  def free!
@@ -138,6 +135,12 @@ module Zm
138
135
  @rsvp = rsvp
139
136
  end
140
137
  end
138
+
139
+ private
140
+
141
+ def jsns_builder
142
+ @jsns_builder ||= AppointmentJsnsBuilder.new(self)
143
+ end
141
144
  end
142
145
  end
143
146
  end
@@ -3,13 +3,13 @@
3
3
  module Zm
4
4
  module Client
5
5
  # collection of appointments
6
- class AppointmentsCollection < Base::ObjectsCollection
7
- attr_accessor :more
8
-
6
+ class AppointmentsCollection < Base::AccountSearchObjectsCollection
9
7
  def initialize(parent)
10
- @parent = parent
11
- @more = true
12
- reset_query_params
8
+ super(parent)
9
+ @child_class = Appointment
10
+ @builder_class = AppointmentsBuilder
11
+ @type = 'appointment'
12
+ @sort_by = 'dateAsc'
13
13
  end
14
14
 
15
15
  def find(id)
@@ -17,90 +17,6 @@ module Zm
17
17
  entry = rep[:Body][:GetMsgResponse][:m].first
18
18
  AppointmentJsnsInitializer.new(@parent, entry).create
19
19
  end
20
-
21
- def new
22
- appointment = Appointment.new(@parent)
23
- yield(appointment) if block_given?
24
- appointment
25
- end
26
-
27
- def start_at(start_at)
28
- @start_at = start_at
29
- self
30
- end
31
-
32
- def end_at(end_at)
33
- @end_at = end_at
34
- self
35
- end
36
-
37
- def folders(folders)
38
- @folders = folders
39
- @folder_ids = @folders.map(&:id)
40
- self
41
- end
42
-
43
- def folder_ids(folder_ids)
44
- @folder_ids = folder_ids
45
- self
46
- end
47
-
48
- def where(query)
49
- @query = query
50
- self
51
- end
52
-
53
- def ids
54
- search_builder.ids
55
- end
56
-
57
- private
58
-
59
- def search_response
60
- rep = @parent.sacc.search(@parent.token, 'appointment', @offset, @limit, 'dateAsc', query, build_options)
61
- @more = rep[:Body][:SearchResponse][:more]
62
- rep
63
- end
64
-
65
- def search_builder
66
- AppointmentsBuilder.new(@parent, search_response)
67
- end
68
-
69
- def build_response
70
- appointments = search_builder.make
71
- appointments.each { |appo| appo.folder = find_folder(appo) } unless @folders.empty?
72
- appointments
73
- end
74
-
75
- def build_options
76
- return {} if !@start_at.is_a?(Time) && !@end_at.is_a?(Time)
77
-
78
- {
79
- calExpandInstStart: (@start_at.to_f * 1000).to_i,
80
- calExpandInstEnd: (@end_at.to_f * 1000).to_i,
81
- }
82
- end
83
-
84
- def query
85
- return @query unless @query.nil?
86
-
87
- return nil if @folder_ids.empty?
88
-
89
- @folder_ids.map { |id| %Q{inid:"#{id}"} }.join(' OR ')
90
- end
91
-
92
- def find_folder(appointment)
93
- @folders.find { |folder| folder.id == appointment.l }
94
- end
95
-
96
- def reset_query_params
97
- super
98
- @start_at = nil
99
- @end_at = nil
100
- @query = nil
101
- @folder_ids = []
102
- @folders = []
103
- end
104
20
  end
105
21
  end
106
22
  end
@@ -13,12 +13,16 @@ module Zm
13
13
  parent
14
14
  end
15
15
 
16
- def to_h
17
- hashmap = Hash[INSTANCE_VARIABLE_KEYS.map { |key| [key, instance_variable_get(arrow_name(key))] }]
18
- hashmap.delete_if { |_, v| v.nil? }
19
- hashmap
16
+ def all_instance_variable_keys
17
+ INSTANCE_VARIABLE_KEYS
20
18
  end
21
19
 
20
+ # def to_h
21
+ # hashmap = Hash[INSTANCE_VARIABLE_KEYS.map { |key| [key, instance_variable_get(arrow_name(key))] }]
22
+ # hashmap.delete_if { |_, v| v.nil? }
23
+ # hashmap
24
+ # end
25
+
22
26
  def to_s
23
27
  to_h.to_s
24
28
  end