zm-ruby-client 0.14.0 → 0.18.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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -5
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +29 -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 +43 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/connector/rest_account.rb +0 -3
  37. data/lib/zm/client/connector/soap_account.rb +76 -177
  38. data/lib/zm/client/connector/soap_admin.rb +82 -51
  39. data/lib/zm/client/connector/soap_base.rb +12 -12
  40. data/lib/zm/client/contact/contact.rb +2 -1
  41. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  42. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  43. data/lib/zm/client/cos/cos.rb +11 -6
  44. data/lib/zm/client/cos/coses_builder.rb +1 -16
  45. data/lib/zm/client/cos/coses_collection.rb +6 -9
  46. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  47. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  48. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  49. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  50. data/lib/zm/client/distributionlist.rb +1 -0
  51. data/lib/zm/client/document/document.rb +7 -9
  52. data/lib/zm/client/domain/domain.rb +11 -6
  53. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  54. data/lib/zm/client/domain/domains_builder.rb +1 -19
  55. data/lib/zm/client/domain/domains_collection.rb +7 -10
  56. data/lib/zm/client/domain.rb +1 -0
  57. data/lib/zm/client/folder/folder.rb +50 -124
  58. data/lib/zm/client/folder/folder_grant.rb +44 -22
  59. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  60. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  61. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  62. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  63. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  64. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  65. data/lib/zm/client/folder/folders_builder.rb +2 -2
  66. data/lib/zm/client/folder/folders_collection.rb +21 -19
  67. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  68. data/lib/zm/client/folder.rb +6 -0
  69. data/lib/zm/client/identity/identities_builder.rb +4 -15
  70. data/lib/zm/client/identity/identities_collection.rb +7 -13
  71. data/lib/zm/client/identity/identity.rb +19 -19
  72. data/lib/zm/client/message/message.rb +111 -21
  73. data/lib/zm/client/message/messages_builder.rb +1 -1
  74. data/lib/zm/client/message/messages_collection.rb +10 -92
  75. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  76. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  77. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  78. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  79. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  80. data/lib/zm/client/mountpoint.rb +2 -0
  81. data/lib/zm/client/resource/resource.rb +5 -5
  82. data/lib/zm/client/resource/resources_builder.rb +1 -16
  83. data/lib/zm/client/resource/resources_collection.rb +5 -13
  84. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  85. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  86. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  87. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  88. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  89. data/lib/zm/client/search_folder.rb +2 -0
  90. data/lib/zm/client/server/server.rb +7 -14
  91. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  92. data/lib/zm/client/server/servers_builder.rb +4 -16
  93. data/lib/zm/client/server/servers_collection.rb +5 -10
  94. data/lib/zm/client/server.rb +1 -0
  95. data/lib/zm/client/share/share.rb +2 -9
  96. data/lib/zm/client/share/shares_builder.rb +3 -12
  97. data/lib/zm/client/signature/signature.rb +17 -13
  98. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  99. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  100. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  101. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  102. data/lib/zm/client/signature.rb +1 -0
  103. data/lib/zm/client/tag/tag.rb +27 -20
  104. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  105. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  106. data/lib/zm/client/tag/tags_builder.rb +6 -9
  107. data/lib/zm/client/tag/tags_collection.rb +6 -12
  108. data/lib/zm/client/tag.rb +2 -0
  109. data/lib/zm/client/task/tasks_collection.rb +6 -90
  110. data/lib/zm/client/upload/upload.rb +1 -1
  111. data/lib/zm/client/version.rb +1 -1
  112. data/lib/zm/modules/common/dl_common.rb +3 -1
  113. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  114. data/lib/zm/modules/zm_logger.rb +24 -0
  115. data/lib/zm/modules/zm_model.rb +41 -0
  116. data/test/accounts.rb +15 -1
  117. data/test/ace.rb +50 -0
  118. data/test/cluster.rb +41 -0
  119. data/test/cluster_zimbra_attributes.rb +38 -0
  120. data/test/folder.rb +125 -0
  121. data/test/folder_grant.rb +51 -0
  122. data/test/mountpoint.rb +49 -0
  123. data/test/retention_policies.rb +40 -0
  124. data/test/search_folder.rb +67 -0
  125. data/test/signature.rb +53 -0
  126. data/test/tag.rb +65 -0
  127. data/test/zimbra_attributes.rb +35 -0
  128. data/zm-ruby-client.gemspec +15 -10
  129. metadata +53 -26
  130. data/lib/zm/client/connector/soap_xml_builder.rb +0 -68
@@ -4,7 +4,7 @@ module Zm
4
4
  module Client
5
5
  # class message for account
6
6
  class Message < Base::AccountObject
7
- INSTANCE_VARIABLE_KEYS = %i[id date l su fr]
7
+ INSTANCE_VARIABLE_KEYS = %i[id date l su fr autoSendTime mid idnt]
8
8
  attr_accessor *INSTANCE_VARIABLE_KEYS
9
9
 
10
10
  attr_accessor :subject
@@ -22,6 +22,14 @@ module Zm
22
22
  yield(self) if block_given?
23
23
  end
24
24
 
25
+ def has_attachment?
26
+ @has_attachment ||= @attachments.all.any?
27
+ end
28
+
29
+ def all_instance_variable_keys
30
+ INSTANCE_VARIABLE_KEYS
31
+ end
32
+
25
33
  def from
26
34
  @from ||= @recipients.find { |r| r.field == Recipient::FROM }
27
35
  end
@@ -31,15 +39,6 @@ module Zm
31
39
  @l = folder.id
32
40
  end
33
41
 
34
- def to_jsns
35
- {
36
- attach: @attachments.to_jsns,
37
- e: @recipients.to_jsns,
38
- su: { _content: @subject },
39
- mp: @body.to_jsns
40
- }
41
- end
42
-
43
42
  def delete!
44
43
  msg_action('delete')
45
44
  end
@@ -89,6 +88,20 @@ module Zm
89
88
  @parent.sacc.send_msg(@parent.token, to_jsns)
90
89
  end
91
90
 
91
+ def to_jsns
92
+ h = {
93
+ id: @id,
94
+ attach: @attachments.to_jsns,
95
+ e: @recipients.to_jsns,
96
+ su: { _content: @su },
97
+ mp: @body.to_jsns
98
+ }.delete_if { |_, v| v.nil? }
99
+
100
+ h[:did] = @id if l.to_i == FolderDefault::DRAFTS[:id]
101
+
102
+ h
103
+ end
104
+
92
105
  def init_from_json(json)
93
106
  # puts json
94
107
  @id = json[:id]
@@ -96,11 +109,54 @@ module Zm
96
109
  @l = json[:l]
97
110
  @su = json[:su]
98
111
  @fr = json[:fr]
112
+ @autoSendTime = json[:autoSendTime]
113
+ @mid = json[:mid]
114
+ @idnt = json[:idnt]
115
+ @has_attachment = json[:f].to_s.include?('a')
99
116
 
100
117
  json[:e].each do |e|
101
118
  recipient = Recipient.new(e[:t], e[:a], e[:p])
102
119
  @recipients.add(recipient)
103
120
  end
121
+
122
+ init_part_from_json(json[:mp])
123
+ end
124
+
125
+ def init_part_from_json(json)
126
+ return if json.nil?
127
+ # puts json
128
+ json = [json] unless json.is_a?(Array)
129
+
130
+ json.each do |json_part|
131
+ if ['text/plain', 'text/html'].include?(json_part[:ct])
132
+ init_body_from_json(json_part)
133
+ elsif json_part[:cd] == 'attachment'
134
+ init_attachment_from_json(json_part)
135
+ else
136
+ init_part_from_json(json_part[:mp])
137
+ end
138
+ end
139
+ end
140
+
141
+ def init_body_from_json(json)
142
+ # puts "\ninit_body_from_json #{json}\n"
143
+ body.text = json[:content] if json[:ct] == 'text/plain'
144
+ body.html = json[:content] if json[:ct] == 'text/html'
145
+ end
146
+
147
+ def init_attachment_from_json(json)
148
+ # puts "\ninit_attachment_from_json #{json}\n"
149
+ pj = Zm::Client::Message::Attachment.new(self)
150
+ # pj.part = json[:part],
151
+ pj.mid = json[:mid]
152
+ pj.aid = json[:aid]
153
+ pj.ct = json[:ct]
154
+ pj.s = json[:s]
155
+ pj.filename = json[:filename]
156
+ pj.ci = json[:ci]
157
+ pj.cd = json[:cd]
158
+ pj.part = json[:part]
159
+ attachments.add(pj)
104
160
  end
105
161
 
106
162
  def msg_action(action_name, options = {})
@@ -113,18 +169,18 @@ module Zm
113
169
  attr_accessor :text, :html
114
170
 
115
171
  def text_jsns
116
- { ct: 'text/plain', content: { _content: @text } }
172
+ @text.nil? ? nil : { ct: 'text/plain', content: { _content: @text } }
117
173
  end
118
174
 
119
175
  def html_jsns
120
- { ct: 'text/html', content: { _content: @html } }
176
+ @html.nil? ? nil : { ct: 'text/html', content: { _content: @html } }
121
177
  end
122
178
 
123
179
  def to_jsns
124
180
  [
125
181
  {
126
182
  ct: 'multipart/alternative',
127
- mp: [text_jsns, html_jsns]
183
+ mp: [text_jsns, html_jsns].compact
128
184
  }
129
185
  ]
130
186
  end
@@ -132,36 +188,66 @@ module Zm
132
188
 
133
189
  # collection attachments
134
190
  class Attachments
191
+ attr_reader :all
135
192
  def initialize
136
- @attachments = []
193
+ @all = []
137
194
  end
138
195
 
139
196
  def add(attachment)
140
197
  return unless attachment.is_a?(Attachment)
141
198
 
142
- @attachments.push(attachment)
199
+ @all.push(attachment)
143
200
  end
144
201
 
145
202
  def to_jsns
146
- @attachments.map(&:to_jsns)
203
+ @all.map(&:to_jsns)
147
204
  end
148
205
  end
149
206
 
150
207
  # class attachment for email
151
208
  class Attachment
152
- attr_accessor :aid, :part, :mid
209
+ attr_accessor :aid, :part, :mid, :ct, :s, :filename, :ci, :cd
153
210
 
154
- def initialize
211
+ def initialize(parent)
212
+ @parent = parent
155
213
  yield(self) if block_given?
156
214
  end
157
215
 
216
+ def download(dest_file_path)
217
+ h = {
218
+ id: @parent.id,
219
+ part: part,
220
+ auth: 'qp',
221
+ zauthtoken: account.token,
222
+ disp: 'a'
223
+ }
224
+
225
+ url = account.home_url
226
+
227
+ uri = Addressable::URI.new
228
+ uri.query_values = h
229
+ url << '?' << uri.query
230
+
231
+ uploader = Upload.new(@parent, RestAccountConnector.new)
232
+ uploader.download_file_with_url(url, dest_file_path)
233
+ end
234
+
158
235
  def to_jsns
159
236
  {
160
- part: @part,
161
- mid: @mid,
162
- aid: @aid
237
+ part: part,
238
+ mid: mid,
239
+ aid: aid,
240
+ ct: ct,
241
+ s: s,
242
+ filename: filename,
243
+ ci: ci,
244
+ cd: cd
163
245
  }.reject { |_, v| v.nil? }
164
246
  end
247
+
248
+ def account
249
+ @parent.parent
250
+ end
165
251
  end
166
252
 
167
253
  # Collection recipients
@@ -212,6 +298,10 @@ module Zm
212
298
  @display_name = display_name
213
299
  end
214
300
 
301
+ def to_s
302
+ "#{@email} (#{@display_name})"
303
+ end
304
+
215
305
  def to_jsns
216
306
  {
217
307
  t: @field,
@@ -16,7 +16,7 @@ module Zm
16
16
  end
17
17
 
18
18
  def ids
19
- root.map { |s| s[:id] }
19
+ @json[:Body][:SearchResponse][:hit].map { |s| s[:id] }
20
20
  end
21
21
 
22
22
  def root
@@ -3,108 +3,26 @@
3
3
  module Zm
4
4
  module Client
5
5
  # Collection Messages
6
- class MessagesCollection < Base::ObjectsCollection
7
- attr_accessor :more
8
-
6
+ class MessagesCollection < Base::AccountSearchObjectsCollection
9
7
  def initialize(parent)
10
- @parent = parent
11
- @more = true
12
- reset_query_params
13
- end
14
-
15
-
16
- def find(id)
17
- rep = @parent.sacc.get_msg(@parent.token, id, { part: 0 })
18
- entry = rep[:Body][:GetMsgResponse][:m].first
19
- # puts entry
20
- msg = Message.new(@parent)
21
- msg.init_from_json(entry)
22
- msg
23
- end
24
-
25
- def new
26
- message = Message.new(@parent)
27
- yield(message) if block_given?
28
- message
29
- end
30
-
31
- def start_at(start_at)
32
- @start_at = start_at
33
- self
34
- end
35
-
36
- def end_at(end_at)
37
- @end_at = end_at
38
- self
39
- end
40
-
41
- def folders(folders)
42
- @folders = folders
43
- @folder_ids = @folders.map(&:id)
44
- self
45
- end
46
-
47
- def folder_ids(folder_ids)
48
- @folder_ids = folder_ids
49
- self
50
- end
51
-
52
- def where(query)
53
- @query = query
54
- self
55
- end
56
-
57
- def ids
58
- search_builder.ids
59
- end
60
-
61
- def all
62
- build_response
8
+ super(parent)
9
+ @child_class = Message
10
+ @builder_class = MessagesBuilder
11
+ @type = 'message'
12
+ @sort_by = 'dateDesc'
63
13
  end
64
14
 
65
15
  private
66
16
 
67
- def search_response
68
- rep = @parent.sacc.search(@parent.token, 'message', @offset, @limit, 'dateDesc', query, build_options)
69
- @more = rep[:Body][:SearchResponse][:more]
70
- rep
71
- end
72
-
73
- def search_builder
74
- MessagesBuilder.new(@parent, search_response)
75
- end
76
-
77
- def build_response
78
- messages = search_builder.make
79
- messages.each { |msg| msg.folder = find_folder(msg) } unless @folders.empty?
80
- messages
81
- end
82
-
83
17
  def build_options
84
- {
85
- recip: 2
86
- }
87
- end
88
-
89
- def query
90
- return @query unless @query.nil?
91
-
92
- return nil if @folder_ids.empty?
93
-
94
- @folder_ids.map { |id| %Q{inid:"#{id}"} }.join(' OR ')
95
- end
96
-
97
- def find_folder(message)
98
- @folders.find { |folder| folder.id == message.l }
18
+ options = super
19
+ options[:recip] = @recip
20
+ options
99
21
  end
100
22
 
101
23
  def reset_query_params
102
24
  super
103
- @start_at = nil
104
- @end_at = nil
105
- @query = nil
106
- @folder_ids = []
107
- @folders = []
25
+ @recip = 2
108
26
  end
109
27
  end
110
28
  end
@@ -3,92 +3,39 @@
3
3
  module Zm
4
4
  module Client
5
5
  # class for account mountpoint
6
- class MountPoint < Base::AccountObject
6
+ class MountPoint < Base::FolderObject
7
+ include Zm::Model::AttributeChangeObserver
8
+
7
9
  INSTANCE_VARIABLE_KEYS = %i[
8
10
  owner rev reminder ms deletable l rid uuid url f broken
9
11
  luuid ruuid activesyncdisabled absFolderPath view zid name id
10
12
  webOfflineSyncDays color rgb
11
13
  ].freeze
12
14
 
13
- attr_accessor(*INSTANCE_VARIABLE_KEYS)
15
+ attr_reader :owner, :rev, :reminder, :ms, :deletable, :rid, :uuid, :url, :f, :broken, :luuid, :ruuid, :activesyncdisabled, :absFolderPath, :view, :zid, :id, :webOfflineSyncDays
16
+
17
+ define_changed_attributes :name, :color, :rgb, :l
14
18
 
15
- def concat
16
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
19
+ def all_instance_variable_keys
20
+ INSTANCE_VARIABLE_KEYS
17
21
  end
18
22
 
19
23
  alias parent_id l
20
24
 
21
- def initialize(parent, json = nil)
22
- @parent = parent
23
- @l = 1
24
- init_from_json(json) if json.is_a?(Hash)
25
- yield(self) if block_given?
26
- end
27
-
28
25
  def create!
29
- rep = @parent.sacc.create_mountpoint(@parent.token, build_create_options)
30
- init_from_json(rep[:Body][:CreateMountpointResponse][:link].first)
31
- end
32
-
33
- def build_create_options
34
- {
35
- l: @l,
36
- name: @name,
37
- view: @view,
38
- zid: @zid,
39
- rid: @rid,
40
- url: @url,
41
- color: @color,
42
- rgb: @rgb,
43
- f: @f
44
- }.delete_if { |_, v| v.nil? }
45
- end
46
-
47
- def modify!
48
- update!(build_update_options)
26
+ rep = @parent.sacc.create_mountpoint(@parent.token, jsns_builder.to_jsns)
27
+ json = rep[:Body][:CreateMountpointResponse][:link].first
28
+ MountpointJsnsInitializer.update(self, json)
49
29
  end
50
30
 
51
31
  def update!(options)
52
- @parent.sacc.folder_action(@parent.token, 'update', @id, options)
32
+ # todo
53
33
  end
54
34
 
55
- def build_update_options
56
- {
57
- f: @f,
58
- name: @name,
59
- l: @l,
60
- color: @color,
61
- rgb: @rgb
62
- }.delete_if { |_, v| v.nil? }
63
- end
64
-
65
- def rename!(new_name)
66
- @parent.sacc.folder_action(@parent.token, 'rename', @id, name: new_name)
67
- @name = new_name
68
- end
69
-
70
- def move!(folder_id)
71
- @parent.sacc.folder_action(@parent.token, 'move', @id, l: folder_id)
72
- @l = folder_id
73
- end
74
-
75
- def color!(new_color)
76
- key = new_color.to_i.zero? ? :rgb : :color
77
- options = {}
78
- options[key] = new_color
79
- @parent.sacc.folder_action(@parent.token, 'color', @id, options)
80
- instance_variable_set("@#{key}", new_color)
81
- end
82
-
83
- def delete!
84
- @parent.sacc.folder_action(@parent.token, :delete, @id)
85
- end
35
+ private
86
36
 
87
- def init_from_json(json)
88
- INSTANCE_VARIABLE_KEYS.each do |key|
89
- var_name = "@#{key}"
90
- instance_variable_set(var_name, json[key])
91
- end
37
+ def jsns_builder
38
+ @jsns_builder ||= MountpointJsnsBuilder.new(self)
92
39
  end
93
40
  end
94
41
  end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account folder
6
+ class MountpointJsnsBuilder < Base::BaseJsnsBuilder
7
+
8
+ def to_find
9
+ { link: { l: @item.id } }
10
+ end
11
+
12
+ def to_jsns
13
+ link = {
14
+ f: @item.f,
15
+ name: @item.name,
16
+ l: @item.l,
17
+ color: @item.color,
18
+ rgb: @item.rgb,
19
+ url: @item.url,
20
+ fb: @item.fb,
21
+ view: @item.view,
22
+ zid: @item.zid,
23
+ rid: @item.rid
24
+ }.delete_if { |_, v| v.nil? }
25
+
26
+ { link: link }
27
+ end
28
+
29
+ alias to_create to_jsns
30
+
31
+ def to_update
32
+ action = {
33
+ op: :update,
34
+ id: @item.id,
35
+ f: @item.f,
36
+ name: @item.name,
37
+ l: @item.l,
38
+ color: @item.color,
39
+ rgb: @item.rgb,
40
+ url: @item.url,
41
+ fb: @item.fb,
42
+ view: @item.view
43
+ }.delete_if { |_, v| v.nil? }
44
+
45
+ if @item.is_immutable?
46
+ action.delete(:name)
47
+ action.delete(:l)
48
+ end
49
+
50
+ { action: action }
51
+ end
52
+
53
+ def to_rename
54
+ action = {
55
+ op: :rename,
56
+ id: @item.id,
57
+ name: @item.name
58
+ }
59
+
60
+ { action: action }
61
+ end
62
+
63
+ def to_move
64
+ action = {
65
+ op: :move,
66
+ id: @item.id,
67
+ l: @item.l
68
+ }
69
+
70
+ { action: action }
71
+ end
72
+
73
+ def to_color
74
+ action = {
75
+ op: :color,
76
+ id: @item.id
77
+ }
78
+
79
+ action[:rgb] = @item.rgb if @item.rgb_changed?
80
+ action[:color] = @item.color if @item.color_changed?
81
+
82
+ { action: action }
83
+ end
84
+
85
+ def to_empty
86
+ action = {
87
+ op: :empty,
88
+ id: @item.id,
89
+ recursive: false
90
+ }
91
+
92
+ { action: action }
93
+ end
94
+
95
+ def to_delete
96
+ { action: { op: :delete, id: @item.id } }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account mountpoint
6
+ class MountpointJsnsInitializer
7
+ class << self
8
+ def create(parent, json)
9
+ item = MountPoint.new(parent)
10
+
11
+ item.instance_variable_set(:@id, json[:id])
12
+ item.instance_variable_set(:@name, json[:name])
13
+
14
+ update(item, json)
15
+ end
16
+
17
+ def update(item, json)
18
+ item.all_instance_variable_keys.reject { |key| json[key].nil? }.each do |key|
19
+ item.instance_variable_set(arrow_name(key), json[key])
20
+ end
21
+
22
+ item
23
+ end
24
+
25
+ def arrow_name(name)
26
+ return name if name.to_s.start_with?('@')
27
+
28
+ "@#{name}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -24,7 +24,7 @@ module Zm
24
24
  json_folders.each do |json_folder|
25
25
  if json_folder[@key_link].is_a?(Array)
26
26
  @list += json_folder[@key_link].map do |json_link|
27
- MountPoint.new(@account, json_link)
27
+ MountpointJsnsInitializer.create(@account, json_link)
28
28
  end
29
29
  end
30
30
 
@@ -3,23 +3,20 @@
3
3
  module Zm
4
4
  module Client
5
5
  # collection of mountpoints
6
- class MountPointsCollection < Base::ObjectsCollection
7
- METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
6
+ class MountPointsCollection < Base::AccountObjectsCollection
8
7
 
9
8
  attr_reader :root
10
9
 
10
+ attr_accessor :view, :tr, :visible, :needGranteeName, :depth
11
+
11
12
  def initialize(parent)
12
- @parent = parent
13
+ @child_class = MountPoint
14
+ @builder_class = MountPointsBuilder
15
+ super(parent)
13
16
  @root = nil
14
17
  reset_query_params
15
18
  end
16
19
 
17
- def new
18
- mountpoint = MountPoint.new(@parent)
19
- yield(mountpoint) if block_given?
20
- mountpoint
21
- end
22
-
23
20
  def where(view: nil, tr: nil)
24
21
  @view = view
25
22
  @tr = tr
@@ -27,14 +24,6 @@ module Zm
27
24
  self
28
25
  end
29
26
 
30
- def all
31
- @all || all!
32
- end
33
-
34
- def all!
35
- build_response
36
- end
37
-
38
27
  def clear
39
28
  @all = nil
40
29
  @root = nil
@@ -43,18 +32,20 @@ module Zm
43
32
 
44
33
  private
45
34
 
46
- def build_response
47
- @all = MountPointsBuilder.new(@parent, make_query).make
48
- @all
49
- end
50
-
51
35
  def make_query
52
- @parent.sacc.get_all_folders(@parent.token, @view, @tr)
36
+ @parent.sacc.get_folder(@parent.token, jsns_builder.to_jsns)
53
37
  end
54
38
 
55
39
  def reset_query_params
56
40
  @view = nil
57
41
  @tr = nil
42
+ @visible = nil
43
+ @needGranteeName = nil
44
+ @depth = nil
45
+ end
46
+
47
+ def jsns_builder
48
+ @jsns_builder ||= FoldersJsnsBuilder.new(self)
58
49
  end
59
50
  end
60
51
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/mountpoint/mountpoint'
4
+ require 'zm/client/mountpoint/mountpoint_jsns_builder'
5
+ require 'zm/client/mountpoint/mountpoint_jsns_initializer'
4
6
  require 'zm/client/mountpoint/mountpoints_builder'
5
7
  require 'zm/client/mountpoint/mountpoints_collection'
@@ -15,11 +15,11 @@ module Zm
15
15
  @grantee_type = 'usr'.freeze
16
16
  end
17
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
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
23
 
24
24
  def all_instance_variable_keys
25
25
  ResourceCommon::ALL_ATTRS