zm-ruby-client 0.10.4

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 (147) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +674 -0
  5. data/README.md +47 -0
  6. data/SECURITY.md +21 -0
  7. data/lib/zm/client/account/account.rb +335 -0
  8. data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
  9. data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
  10. data/lib/zm/client/account/accounts_builder.rb +19 -0
  11. data/lib/zm/client/account/accounts_collection.rb +48 -0
  12. data/lib/zm/client/account.rb +7 -0
  13. data/lib/zm/client/ace/ace.rb +32 -0
  14. data/lib/zm/client/ace/aces_builder.rb +25 -0
  15. data/lib/zm/client/ace/aces_collection.rb +36 -0
  16. data/lib/zm/client/ace.rb +5 -0
  17. data/lib/zm/client/appointment/appointment.rb +143 -0
  18. data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
  19. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
  20. data/lib/zm/client/appointment/appointments_builder.rb +33 -0
  21. data/lib/zm/client/appointment/appointments_collection.rb +106 -0
  22. data/lib/zm/client/appointment.rb +7 -0
  23. data/lib/zm/client/backup/backup.rb +59 -0
  24. data/lib/zm/client/backup/backups_builder.rb +26 -0
  25. data/lib/zm/client/backup/backups_collection.rb +22 -0
  26. data/lib/zm/client/backup.rb +5 -0
  27. data/lib/zm/client/base/account_object.rb +17 -0
  28. data/lib/zm/client/base/admin_object.rb +45 -0
  29. data/lib/zm/client/base/object.rb +80 -0
  30. data/lib/zm/client/base/objects_builder.rb +31 -0
  31. data/lib/zm/client/base/objects_collection.rb +135 -0
  32. data/lib/zm/client/base.rb +7 -0
  33. data/lib/zm/client/cluster/cluster.rb +117 -0
  34. data/lib/zm/client/cluster/cluster_config.rb +100 -0
  35. data/lib/zm/client/cluster.rb +4 -0
  36. data/lib/zm/client/common/message.rb +10 -0
  37. data/lib/zm/client/common/recipients.rb +67 -0
  38. data/lib/zm/client/common.rb +4 -0
  39. data/lib/zm/client/config.rb +12 -0
  40. data/lib/zm/client/connector/rest_account.rb +74 -0
  41. data/lib/zm/client/connector/soap_account.rb +562 -0
  42. data/lib/zm/client/connector/soap_admin.rb +512 -0
  43. data/lib/zm/client/connector/soap_base.rb +65 -0
  44. data/lib/zm/client/connector/soap_error.rb +26 -0
  45. data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
  46. data/lib/zm/client/constant.rb +217 -0
  47. data/lib/zm/client/contact/contact.rb +124 -0
  48. data/lib/zm/client/contact/contact_member.rb +73 -0
  49. data/lib/zm/client/contact/contacts_builder.rb +24 -0
  50. data/lib/zm/client/contact/contacts_collection.rb +26 -0
  51. data/lib/zm/client/contact/mod_group_contact.rb +74 -0
  52. data/lib/zm/client/contact.rb +7 -0
  53. data/lib/zm/client/cos/cos.rb +59 -0
  54. data/lib/zm/client/cos/coses_builder.rb +29 -0
  55. data/lib/zm/client/cos/coses_collection.rb +33 -0
  56. data/lib/zm/client/cos.rb +5 -0
  57. data/lib/zm/client/data_source.rb +5 -0
  58. data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
  59. data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
  60. data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
  61. data/lib/zm/client/distributionlist.rb +5 -0
  62. data/lib/zm/client/document/document.rb +47 -0
  63. data/lib/zm/client/document/documents_builder.rb +31 -0
  64. data/lib/zm/client/document/documents_collection.rb +93 -0
  65. data/lib/zm/client/document.rb +5 -0
  66. data/lib/zm/client/domain/domain.rb +74 -0
  67. data/lib/zm/client/domain/domains_builder.rb +32 -0
  68. data/lib/zm/client/domain/domains_collection.rb +36 -0
  69. data/lib/zm/client/domain.rb +5 -0
  70. data/lib/zm/client/folder/folder.rb +215 -0
  71. data/lib/zm/client/folder/folder_grant.rb +58 -0
  72. data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
  73. data/lib/zm/client/folder/folders_builder.rb +58 -0
  74. data/lib/zm/client/folder/folders_collection.rb +70 -0
  75. data/lib/zm/client/folder/mod_document_folder.rb +17 -0
  76. data/lib/zm/client/folder.rb +8 -0
  77. data/lib/zm/client/identity/identities_builder.rb +25 -0
  78. data/lib/zm/client/identity/identities_collection.rb +26 -0
  79. data/lib/zm/client/identity/identity.rb +75 -0
  80. data/lib/zm/client/identity.rb +5 -0
  81. data/lib/zm/client/license/license.rb +29 -0
  82. data/lib/zm/client/license/licenses_collection.rb +28 -0
  83. data/lib/zm/client/license.rb +4 -0
  84. data/lib/zm/client/message/message.rb +225 -0
  85. data/lib/zm/client/message/messages_builder.rb +31 -0
  86. data/lib/zm/client/message/messages_collection.rb +111 -0
  87. data/lib/zm/client/message.rb +5 -0
  88. data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
  89. data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
  90. data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
  91. data/lib/zm/client/mountpoint.rb +5 -0
  92. data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
  93. data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
  94. data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
  95. data/lib/zm/client/mta_queue.rb +5 -0
  96. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
  97. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
  98. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
  99. data/lib/zm/client/mta_queue_item.rb +5 -0
  100. data/lib/zm/client/resource/resource.rb +149 -0
  101. data/lib/zm/client/resource/resources_builder.rb +29 -0
  102. data/lib/zm/client/resource/resources_collection.rb +41 -0
  103. data/lib/zm/client/resource.rb +5 -0
  104. data/lib/zm/client/search_folder/search_folder.rb +63 -0
  105. data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
  106. data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
  107. data/lib/zm/client/search_folder.rb +5 -0
  108. data/lib/zm/client/server/server.rb +516 -0
  109. data/lib/zm/client/server/servers_builder.rb +26 -0
  110. data/lib/zm/client/server/servers_collection.rb +37 -0
  111. data/lib/zm/client/server.rb +5 -0
  112. data/lib/zm/client/share/share.rb +60 -0
  113. data/lib/zm/client/share/shares_builder.rb +23 -0
  114. data/lib/zm/client/share/shares_collection.rb +48 -0
  115. data/lib/zm/client/share.rb +5 -0
  116. data/lib/zm/client/signature/signature.rb +62 -0
  117. data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
  118. data/lib/zm/client/signature/signatures_builder.rb +26 -0
  119. data/lib/zm/client/signature/signatures_collection.rb +28 -0
  120. data/lib/zm/client/signature.rb +6 -0
  121. data/lib/zm/client/tag/tag.rb +45 -0
  122. data/lib/zm/client/tag/tags_builder.rb +25 -0
  123. data/lib/zm/client/tag/tags_collection.rb +26 -0
  124. data/lib/zm/client/tag.rb +5 -0
  125. data/lib/zm/client/task/task.rb +74 -0
  126. data/lib/zm/client/task/tasks_builder.rb +31 -0
  127. data/lib/zm/client/task/tasks_collection.rb +100 -0
  128. data/lib/zm/client/task.rb +5 -0
  129. data/lib/zm/client/upload/upload.rb +154 -0
  130. data/lib/zm/client/upload.rb +3 -0
  131. data/lib/zm/client/version.rb +18 -0
  132. data/lib/zm/client.rb +5 -0
  133. data/lib/zm/modules/common/account_common.rb +71 -0
  134. data/lib/zm/modules/common/cos_common.rb +463 -0
  135. data/lib/zm/modules/common/dl_common.rb +33 -0
  136. data/lib/zm/modules/common/identity_common.rb +19 -0
  137. data/lib/zm/modules/common/resource_common.rb +59 -0
  138. data/lib/zm/modules/common/signature_common.rb +16 -0
  139. data/lib/zm/modules/common/zimbra-attrs.json +1 -0
  140. data/lib/zm/utils/thread_pool.rb +72 -0
  141. data/lib/zm-ruby-client.rb +1 -0
  142. data/test/accounts.rb +62 -0
  143. data/test/cluster_config.rb +30 -0
  144. data/test/coses.rb +26 -0
  145. data/test/domains.rb +62 -0
  146. data/zm-ruby-client.gemspec +24 -0
  147. metadata +243 -0
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection MtaQueues
6
+ class MtaQueuesCollection < Base::ObjectsCollection
7
+ METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ reset_query_params
12
+ end
13
+
14
+ def all
15
+ @all ||= all!
16
+ end
17
+
18
+ def all!
19
+ build_response
20
+ end
21
+
22
+ def defaults
23
+ @all || defaults!
24
+ end
25
+
26
+ def defaults!
27
+ # queues = []
28
+ Zm::Client::MtaQueueName::ALL.each do |queue_name|
29
+ queue = MtaQueue.new(@parent)
30
+ queue.name = queue_name
31
+ set_dynamic_queue_method(queue)
32
+ @queues_h[queue_name] = queue
33
+ # queues << queue
34
+ end
35
+ # @all = queues
36
+ @all = @queues_h.values
37
+ end
38
+
39
+ def find(queue_name)
40
+ raise ZmError, 'Unknown queue name' unless Zm::Client::MtaQueueName::ALL.include?(queue_name)
41
+ all! if @queues_h.empty?
42
+ @queues_h[queue_name]
43
+ end
44
+
45
+ def method_missing(method, *args, &block)
46
+ if METHODS_MISSING_LIST.include?(method)
47
+ build_response.send(method, *args, &block)
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ def respond_to_missing?(method, *)
54
+ METHODS_MISSING_LIST.include?(method) || super
55
+ end
56
+
57
+ private
58
+
59
+ def make_query
60
+ sac.get_mail_queue_info(@parent.name)
61
+ end
62
+
63
+ def build_response
64
+ queues = MtaQueuesBuilder.new(@parent, make_query).make
65
+ clear_dynamic_methods
66
+
67
+ queues.each do |queue|
68
+ set_dynamic_queue_method(queue)
69
+ @queues_h[queue.name] = queue
70
+ end
71
+ queues
72
+ end
73
+
74
+ def set_dynamic_queue_method(queue)
75
+ s_name = "@#{queue.name}"
76
+ instance_variable_set(s_name, queue)
77
+ self.class.attr_reader queue.name
78
+ @dynamic_methods << s_name
79
+ end
80
+
81
+ def clear_dynamic_methods
82
+ return if @dynamic_methods.empty?
83
+
84
+ @dynamic_methods.each do |name|
85
+ remove_instance_variable(name) if instance_variable_get(name)
86
+ end
87
+ end
88
+
89
+ def reset_query_params
90
+ @dynamic_methods = []
91
+ @queues_h = {}
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/mta_queue/mta_queue'
4
+ require 'zm/client/mta_queue/mta_queues_builder'
5
+ require 'zm/client/mta_queue/mta_queues_collection'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ class MtaQueueItem < Base::AdminObject
6
+ attr_reader :name, :n
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[size fromdomain id reason time to addr filter host from todomain received]
9
+ attr_reader *INSTANCE_VARIABLE_KEYS
10
+
11
+ def mta_queue
12
+ parent
13
+ end
14
+
15
+ def server
16
+ mta_queue.parent
17
+ end
18
+
19
+ def to_h
20
+ hashmap = Hash[INSTANCE_VARIABLE_KEYS.map { |key| [key, instance_variable_get(arrow_name(key))] }]
21
+ hashmap.delete_if { |_, v| v.nil? }
22
+ hashmap
23
+ end
24
+
25
+ def sent_at
26
+ @sent_at ||= Time.at(@time / 1000)
27
+ rescue StandardError => e
28
+ nil
29
+ end
30
+
31
+ def hold!
32
+ sac.mail_queue_action(server.name, mta_queue.name, Zm::Client::MtaQueueAction::HOLD, @id)
33
+ end
34
+
35
+ def init_from_json(json)
36
+ @size = json[:size]
37
+ @fromdomain = json[:fromdomain]
38
+ @id = json[:id]
39
+ @reason = json[:reason]
40
+ @time = json[:time].to_i
41
+ @to = json[:to] ? json[:to].split(',') : []
42
+ @addr = json[:addr]
43
+ @filter = json[:filter]
44
+ @host = json[:host]
45
+ @from = json[:from]
46
+ @todomain = json[:todomain] ? json[:todomain].split(',') : []
47
+ @received = json[:received]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [MtaQueueItem]
6
+ class MtaQueueItemsBuilder < Base::ObjectsBuilder
7
+ def make
8
+ records = []
9
+ return records if json_items.nil?
10
+
11
+ json_items.each do |entry|
12
+ mta_queue = MtaQueueItem.new(@parent)
13
+ mta_queue.init_from_json(entry)
14
+ records << mta_queue
15
+ end
16
+ records
17
+ end
18
+
19
+ private
20
+
21
+ def json_items
22
+ # puts @json
23
+ @json_items ||= @json[:Body][json_key][:server].first[:queue].first[:qi]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection MtaQueues
6
+ class MtaQueueItemsCollection < Base::ObjectsCollection
7
+ METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ reset_query_params
12
+ end
13
+
14
+ def mta_queue
15
+ parent
16
+ end
17
+
18
+ def server
19
+ mta_queue.parent
20
+ end
21
+
22
+ def all
23
+ @all ||= all!
24
+ end
25
+
26
+ def all!
27
+ build_response
28
+ end
29
+
30
+ def where(fields)
31
+ @fields = fields
32
+ self
33
+ end
34
+
35
+ def fromdomain(value)
36
+ @fields[:fromdomain] = value
37
+ self
38
+ end
39
+
40
+ def todomain(value)
41
+ @fields[:todomain] = value
42
+ self
43
+ end
44
+
45
+ def ids
46
+ all.map(&:id)
47
+ end
48
+
49
+ def do_action(action_name)
50
+ sac.mail_queue_action(server.name, mta_queue.name, action_name, ids)
51
+ end
52
+
53
+ def hold!
54
+ do_action(Zm::Client::MtaQueueAction::HOLD)
55
+ end
56
+
57
+ def release!
58
+ do_action(Zm::Client::MtaQueueAction::RELEASE)
59
+ end
60
+
61
+ def delete!
62
+ do_action(Zm::Client::MtaQueueAction::DELETE)
63
+ end
64
+
65
+ def requeue!
66
+ do_action(Zm::Client::MtaQueueAction::REQUEUE)
67
+ end
68
+
69
+ def method_missing(method, *args, &block)
70
+ if METHODS_MISSING_LIST.include?(method)
71
+ build_response.send(method, *args, &block)
72
+ else
73
+ super
74
+ end
75
+ end
76
+
77
+ def respond_to_missing?(method, *)
78
+ METHODS_MISSING_LIST.include?(method) || super
79
+ end
80
+
81
+ private
82
+
83
+ def make_query
84
+ json = sac.get_mail_queue(@parent.parent.name, @parent.name, @offset, @limit, @fields)
85
+ reset_query_params
86
+ json
87
+ end
88
+
89
+ def build_response
90
+ MtaQueueItemsBuilder.new(@parent, make_query).make
91
+ end
92
+
93
+ def reset_query_params
94
+ super
95
+ @fields = {}
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/mta_queue_item/mta_queue_item'
4
+ require 'zm/client/mta_queue_item/mta_queue_items_builder'
5
+ require 'zm/client/mta_queue_item/mta_queue_items_collection'
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/modules/common/resource_common'
4
+
5
+ module Zm
6
+ module Client
7
+ # objectClass: zimbraCalendarResource
8
+ class Resource < Base::AdminObject
9
+ # attr_reader :name, :id, :domainkey, :used, :token
10
+ attr_accessor :home_url
11
+
12
+ def initialize(parent)
13
+ extend(ResourceCommon)
14
+ super(parent)
15
+ @grantee_type = 'usr'.freeze
16
+ end
17
+
18
+ def to_h
19
+ hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
20
+ hashmap.delete_if { |_, v| v.nil? }
21
+ hashmap
22
+ end
23
+
24
+ def all_instance_variable_keys
25
+ ResourceCommon::ALL_ATTRS
26
+ end
27
+
28
+ def rest_account_connector
29
+ @rest_account_connector ||= RestAccountConnector.new
30
+ end
31
+
32
+ alias rac rest_account_connector
33
+
34
+ def logged?
35
+ !@token.nil?
36
+ end
37
+
38
+ def login
39
+ if @parent.logged?
40
+ admin_login
41
+ else
42
+ account_login
43
+ end
44
+ end
45
+
46
+ def account_login_preauth
47
+ domain_key
48
+ raise ZmError, 'domain key is required to login !' if @domainkey.nil?
49
+
50
+ @token = sacc.auth_preauth(@name, @domainkey)
51
+ end
52
+
53
+ def account_login_password
54
+ raise ZmError, 'password is required to login !' if password.nil?
55
+
56
+ @token = sacc.auth_password(@name, @password)
57
+ end
58
+
59
+ def admin_login
60
+ @token = sac.delegate_auth(@name)
61
+ end
62
+
63
+ def domain_name
64
+ @name.split('@').last
65
+ end
66
+
67
+ def domain_key
68
+ @domainkey ||= @parent.domain_key(domain_name)
69
+ end
70
+
71
+ def infos
72
+ @infos ||= read_infos
73
+ end
74
+
75
+ def read_infos
76
+ @infos = sacc.get_info(@token)[:Body][:GetInfoResponse]
77
+ @id = @infos[:id]
78
+ @used = @infos[:used]
79
+ @public_url = @infos[:publicURL]
80
+ @zimbraCOSId = @infos[:cos][:id]
81
+ @home_url = @infos[:rest]
82
+ end
83
+
84
+ def folders
85
+ @folders ||= FoldersCollection.new(self)
86
+ end
87
+
88
+ def delete!
89
+ sac.delete_resource(@id)
90
+ end
91
+
92
+ def update!(hash)
93
+ sac.modify_resource(@id, hash)
94
+ hash.each { |k, v| send "#{k}=", v }
95
+ end
96
+
97
+ def modify!
98
+ attrs_to_modify = instance_variables_array(attrs_write)
99
+ return if attrs_to_modify.empty?
100
+
101
+ sac.modify_resource(@id, attrs_to_modify)
102
+ end
103
+
104
+ def create!
105
+ rep = sac.create_resource(
106
+ @name,
107
+ @password,
108
+ instance_variables_array(attrs_write)
109
+ )
110
+ @id = rep[:Body][:CreateCalendarResourceResponse][:calresource].first[:id]
111
+ end
112
+
113
+ def uploader
114
+ @uploader ||= Upload.new(self)
115
+ end
116
+
117
+ # def download(folder_path, fmt, types, dest_file_path)
118
+ # url_folder_path = File.join(@home_url, folder_path.to_s)
119
+ # uri = Addressable::URI.new
120
+ # uri.query_values = {
121
+ # fmt: fmt,
122
+ # types: types.join(','),
123
+ # emptyname: 'Vide',
124
+ # charset: 'UTF-8',
125
+ # auth: 'qp',
126
+ # zauthtoken: @token
127
+ # }
128
+ # url_folder_path << '?' << uri.query
129
+ #
130
+ # rac.download(url_folder_path, dest_file_path)
131
+ # end
132
+ #
133
+ # def upload(folder_path, fmt, types, resolve, src_file_path)
134
+ # url_folder_path = File.join(@home_url, folder_path.to_s)
135
+ # uri = Addressable::URI.new
136
+ # uri.query_values = {
137
+ # fmt: fmt,
138
+ # types: types.join(','),
139
+ # resolve: resolve,
140
+ # auth: 'qp',
141
+ # zauthtoken: @token
142
+ # }
143
+ # url_folder_path << '?' << uri.query
144
+ #
145
+ # rac.upload(url_folder_path, src_file_path)
146
+ # end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [resources]
6
+ class ResourcesBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ super(parent, json)
9
+ @child_class = Resource
10
+ end
11
+
12
+ # def make
13
+ # return [] if json_items.nil?
14
+ #
15
+ # json_items.map do |entry|
16
+ # resource = Resource.new(@parent)
17
+ # resource.init_from_json(entry)
18
+ # resource
19
+ # end
20
+ # end
21
+
22
+ private
23
+
24
+ def json_items
25
+ @json_items ||= @json[:Body][json_key][:calresource]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Resources
6
+ class ResourcesCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @child_class = Resource
9
+ @parent = parent
10
+ reset_query_params
11
+ end
12
+
13
+ def ldap
14
+ @apply_cos = 0
15
+ self
16
+ end
17
+
18
+ def find_by(hash)
19
+ rep = sac.get_resource(hash.values.first, hash.keys.first, attrs_comma)
20
+ entry = rep[:Body][:GetCalendarResourceResponse][:calresource].first
21
+
22
+ build_from_entry(entry)
23
+ end
24
+
25
+ private
26
+
27
+ def build_response
28
+ ResourcesBuilder.new(@parent, make_query).make
29
+ end
30
+
31
+ def reset_query_params
32
+ super
33
+ @search_type = SearchType::RESOURCE
34
+ @attrs = SearchType::Attributes::RESOURCE.dup
35
+ @all_servers = 1
36
+ @refresh = 0
37
+ @apply_cos = 1
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/resource/resource'
4
+ require 'zm/client/resource/resources_builder'
5
+ require 'zm/client/resource/resources_collection'
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account SearchFolder
6
+ class SearchFolder < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[id uuid deletable name absFolderPath l luuid color rgb rev ms webOfflineSyncDays activesyncdisabled query sortBy types]
9
+
10
+ attr_accessor *INSTANCE_VARIABLE_KEYS
11
+
12
+ def concat
13
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
14
+ end
15
+
16
+ def init_from_json(json)
17
+ INSTANCE_VARIABLE_KEYS.each do |key|
18
+ var_name = "@#{key}"
19
+ instance_variable_set(var_name, json[key])
20
+ end
21
+ end
22
+
23
+ def create!
24
+ rep = @parent.sacc.create_search_folder(@parent.token, name, query, types, l, color, sortBy)
25
+ init_from_json(rep[:Body][:CreateSearchFolderResponse][:search].first)
26
+ end
27
+
28
+ def modify!
29
+ @parent.sacc.modify_search_folder(@parent.token, id, query, types)
30
+ @parent.sacc.folder_action(@parent.token, :update, id, build_update_options)
31
+ end
32
+
33
+ def query!(new_query)
34
+ @parent.sacc.modify_search_folder(@parent.token, id, new_query, types)
35
+ instance_variable_set("@query", new_query)
36
+ end
37
+
38
+ def color!(new_color)
39
+ key = new_color.to_i.zero? ? :rgb : :color
40
+ options = {}
41
+ options[key] = new_color
42
+ @parent.sacc.folder_action(@parent.token, :color, @id, options)
43
+ instance_variable_set("@#{key}", new_color)
44
+ end
45
+
46
+ def build_update_options
47
+ {
48
+ name: @name,
49
+ color: @color,
50
+ rgb: @rgb
51
+ }.delete_if { |_, v| v.nil? }
52
+ end
53
+
54
+ def delete!
55
+ @parent.sacc.folder_action(@parent.token, :delete, id)
56
+ end
57
+
58
+ def rename!(new_name)
59
+ # todo
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [folders]
6
+ class SearchFoldersBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root = @json[:Body][:GetSearchFolderResponse][:search]
14
+ return [] if root.nil?
15
+
16
+ root = [root] unless root.is_a?(Array)
17
+
18
+ root.map do |s|
19
+ f = SearchFolder.new(@parent)
20
+ f.init_from_json(s)
21
+ f
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection of folders
6
+ class SearchFoldersCollection < Base::ObjectsCollection
7
+ METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ end
12
+
13
+ def new
14
+ folder = SearchFolder.new(@parent)
15
+ yield(folder) if block_given?
16
+ folder
17
+ end
18
+
19
+ private
20
+
21
+ def build_response
22
+ rep = @parent.sacc.get_all_search_folders(@parent.token)
23
+ fb = SearchFoldersBuilder.new @parent, rep
24
+ fb.make
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/search_folder/search_folder'
4
+ require 'zm/client/search_folder/search_folders_builder'
5
+ require 'zm/client/search_folder/search_folders_collection'