zm-ruby-client 0.14.0 → 0.17.1

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 (129) 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 +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 +66 -123
  38. data/lib/zm/client/connector/soap_admin.rb +28 -16
  39. data/lib/zm/client/connector/soap_base.rb +11 -3
  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 +9 -5
  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 +7 -5
  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 +2 -2
  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 +1 -0
  129. metadata +59 -3
@@ -3,20 +3,25 @@
3
3
  module Zm
4
4
  module Client
5
5
  # collection of folders
6
- class FoldersCollection < Base::ObjectsCollection
7
- METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
6
+ class FoldersCollection < 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 = Folder
14
+ @builder_class = FoldersBuilder
15
+ super(parent)
13
16
  @root = nil
14
17
  reset_query_params
15
18
  end
16
19
 
17
- def new
18
- folder = Folder.new(@parent)
19
- yield(folder) if block_given?
20
+ def find(id)
21
+ folder = @child_class.new(@parent) do |f|
22
+ f.id = id
23
+ end
24
+ folder.reload!
20
25
  folder
21
26
  end
22
27
 
@@ -28,16 +33,7 @@ module Zm
28
33
  end
29
34
 
30
35
  def ids
31
- fb = FoldersBuilder.new @parent, make_query
32
- fb.ids
33
- end
34
-
35
- def all
36
- @all || all!
37
- end
38
-
39
- def all!
40
- build_response
36
+ @builder_class.new(@parent, make_query).ids
41
37
  end
42
38
 
43
39
  def clear
@@ -74,8 +70,7 @@ module Zm
74
70
  private
75
71
 
76
72
  def build_response
77
- rep = make_query
78
- fb = FoldersBuilder.new @parent, rep
73
+ fb = @builder_class.new(@parent, make_query)
79
74
  @root = fb.make
80
75
  @all = fb.flatten
81
76
  @all.select! { |folder| folder.view == @view } unless @view.nil?
@@ -83,12 +78,19 @@ module Zm
83
78
  end
84
79
 
85
80
  def make_query
86
- @parent.sacc.get_all_folders(@parent.token, @view, @tr)
81
+ @parent.sacc.get_folder(@parent.token, jsns_builder.to_jsns)
87
82
  end
88
83
 
89
84
  def reset_query_params
90
85
  @view = nil
91
86
  @tr = nil
87
+ @visible = nil
88
+ @needGranteeName = nil
89
+ @depth = nil
90
+ end
91
+
92
+ def jsns_builder
93
+ @jsns_builder ||= FoldersJsnsBuilder.new(self)
92
94
  end
93
95
  end
94
96
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account collection folders jsns builder
6
+ class FoldersJsnsBuilder
7
+ def initialize(item)
8
+ @item = item
9
+ end
10
+
11
+ def to_jsns
12
+ {
13
+ visible: @item.visible,
14
+ needGranteeName: @item.needGranteeName,
15
+ view: @item.view,
16
+ depth: @item.depth,
17
+ tr: @item.tr
18
+ }.delete_if { |_, v| v.nil? }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/folder/folder'
4
+ require 'zm/client/folder/folder_jsns_builder'
5
+ require 'zm/client/folder/folder_jsns_initializer'
6
+ require 'zm/client/folder/folders_jsns_builder'
4
7
  require 'zm/client/folder/folder_grant'
8
+ require 'zm/client/folder/folder_grants_collection'
9
+ require 'zm/client/folder/folder_grant_jsns_builder'
5
10
  require 'zm/client/folder/folder_retention_policy'
11
+ require 'zm/client/folder/folder_retention_policies_collection'
6
12
  require 'zm/client/folder/folders_builder'
7
13
  require 'zm/client/folder/folders_collection'
8
14
  require 'zm/client/folder/mod_document_folder'
@@ -2,23 +2,12 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # class factory [identitys]
5
+ # class factory [identities]
6
6
  class IdentitiesBuilder < Base::ObjectsBuilder
7
7
  def initialize(parent, json)
8
- @parent = parent
9
- @json = json
10
- end
11
-
12
- def make
13
- root = @json[:Body][:GetIdentitiesResponse][:identity]
14
- return [] if root.nil?
15
-
16
- root = [root] unless root.is_a?(Array)
17
- root.map do |s|
18
- identity = Identity.new(@parent)
19
- identity.init_from_json(s)
20
- identity
21
- end
8
+ super(parent, json)
9
+ @child_class = Identity
10
+ @json_item_key = :identity
22
11
  end
23
12
  end
24
13
  end
@@ -2,24 +2,18 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # collection account identitys
6
- class IdentitiesCollection < Base::ObjectsCollection
5
+ # collection account identities
6
+ class IdentitiesCollection < Base::AccountObjectsCollection
7
7
  def initialize(parent)
8
- @parent = parent
9
- end
10
-
11
- def new
12
- identity = Identity.new(@parent)
13
- yield(identity) if block_given?
14
- identity
8
+ @child_class = Identity
9
+ @builder_class = IdentitiesBuilder
10
+ super(parent)
15
11
  end
16
12
 
17
13
  private
18
14
 
19
- def build_response
20
- rep = @parent.sacc.get_all_identities(@parent.token)
21
- ib = IdentitiesBuilder.new @parent, rep
22
- ib.make
15
+ def make_query
16
+ @parent.sacc.get_all_identities(@parent.token)
23
17
  end
24
18
  end
25
19
  end
@@ -17,13 +17,14 @@ module Zm
17
17
 
18
18
  attr_accessor *INSTANCE_VARIABLE_KEYS
19
19
 
20
- def concat
21
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
20
+ def all_instance_variable_keys
21
+ INSTANCE_VARIABLE_KEYS
22
22
  end
23
23
 
24
24
  def init_from_json(json)
25
- super(json)
26
- INSTANCE_VARIABLE_KEYS.each do |key|
25
+ @id = json[:id]
26
+ @name = json[:name]
27
+ all_instance_variable_keys.each do |key|
27
28
  value = json[:_attrs][key]
28
29
  next if value.nil?
29
30
 
@@ -55,7 +56,8 @@ module Zm
55
56
  end
56
57
 
57
58
  def delete!
58
- @parent.sacc.delete_identity(@parent.token, id)
59
+ @parent.sacc.delete_identity(@parent.token, @id)
60
+ super
59
61
  end
60
62
 
61
63
  def rename!(new_name)
@@ -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