zm-ruby-client 0.14.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +4 -5
- data/README.md +6 -0
- data/lib/zm/client/account/account.rb +29 -17
- data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
- data/lib/zm/client/account/accounts_builder.rb +6 -3
- data/lib/zm/client/account/accounts_collection.rb +11 -20
- data/lib/zm/client/account.rb +1 -0
- data/lib/zm/client/ace/ace.rb +22 -9
- data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
- data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
- data/lib/zm/client/ace/aces_builder.rb +6 -9
- data/lib/zm/client/ace/aces_collection.rb +23 -9
- data/lib/zm/client/ace.rb +2 -0
- data/lib/zm/client/appointment/appointment.rb +9 -6
- data/lib/zm/client/appointment/appointments_collection.rb +6 -90
- data/lib/zm/client/backup/backup.rb +8 -4
- data/lib/zm/client/base/account_object.rb +34 -0
- data/lib/zm/client/base/account_objects_collection.rb +14 -0
- data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
- data/lib/zm/client/base/admin_object.rb +6 -0
- data/lib/zm/client/base/admin_objects_collection.rb +65 -0
- data/lib/zm/client/base/base_jsns_builder.rb +19 -0
- data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
- data/lib/zm/client/base/folder_object.rb +41 -0
- data/lib/zm/client/base/ldap_filter.rb +33 -0
- data/lib/zm/client/base/object.rb +19 -0
- data/lib/zm/client/base/objects_builder.rb +4 -0
- data/lib/zm/client/base/objects_collection.rb +11 -32
- data/lib/zm/client/base/zimbra_attribute.rb +119 -0
- data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
- data/lib/zm/client/base.rb +15 -0
- data/lib/zm/client/cluster/cluster.rb +43 -7
- data/lib/zm/client/cluster/cluster_config.rb +19 -17
- data/lib/zm/client/connector/rest_account.rb +0 -3
- data/lib/zm/client/connector/soap_account.rb +76 -177
- data/lib/zm/client/connector/soap_admin.rb +82 -51
- data/lib/zm/client/connector/soap_base.rb +12 -12
- data/lib/zm/client/contact/contact.rb +2 -1
- data/lib/zm/client/contact/contacts_builder.rb +3 -13
- data/lib/zm/client/contact/contacts_collection.rb +6 -12
- data/lib/zm/client/cos/cos.rb +11 -6
- data/lib/zm/client/cos/coses_builder.rb +1 -16
- data/lib/zm/client/cos/coses_collection.rb +6 -9
- data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
- data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
- data/lib/zm/client/distributionlist.rb +1 -0
- data/lib/zm/client/document/document.rb +7 -9
- data/lib/zm/client/domain/domain.rb +11 -6
- data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
- data/lib/zm/client/domain/domains_builder.rb +1 -19
- data/lib/zm/client/domain/domains_collection.rb +7 -10
- data/lib/zm/client/domain.rb +1 -0
- data/lib/zm/client/folder/folder.rb +50 -124
- data/lib/zm/client/folder/folder_grant.rb +44 -22
- data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
- data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
- data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
- data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
- data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
- data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
- data/lib/zm/client/folder/folders_builder.rb +2 -2
- data/lib/zm/client/folder/folders_collection.rb +21 -19
- data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
- data/lib/zm/client/folder.rb +6 -0
- data/lib/zm/client/identity/identities_builder.rb +4 -15
- data/lib/zm/client/identity/identities_collection.rb +7 -13
- data/lib/zm/client/identity/identity.rb +19 -19
- data/lib/zm/client/message/message.rb +111 -21
- data/lib/zm/client/message/messages_builder.rb +1 -1
- data/lib/zm/client/message/messages_collection.rb +10 -92
- data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
- data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
- data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
- data/lib/zm/client/mountpoint.rb +2 -0
- data/lib/zm/client/resource/resource.rb +5 -5
- data/lib/zm/client/resource/resources_builder.rb +1 -16
- data/lib/zm/client/resource/resources_collection.rb +5 -13
- data/lib/zm/client/search_folder/search_folder.rb +19 -39
- data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
- data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
- data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
- data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
- data/lib/zm/client/search_folder.rb +2 -0
- data/lib/zm/client/server/server.rb +7 -14
- data/lib/zm/client/server/server_accounts_collection.rb +19 -0
- data/lib/zm/client/server/servers_builder.rb +4 -16
- data/lib/zm/client/server/servers_collection.rb +5 -10
- data/lib/zm/client/server.rb +1 -0
- data/lib/zm/client/share/share.rb +2 -9
- data/lib/zm/client/share/shares_builder.rb +3 -12
- data/lib/zm/client/signature/signature.rb +17 -13
- data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
- data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
- data/lib/zm/client/signature/signatures_builder.rb +7 -11
- data/lib/zm/client/signature/signatures_collection.rb +6 -14
- data/lib/zm/client/signature.rb +1 -0
- data/lib/zm/client/tag/tag.rb +27 -20
- data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
- data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
- data/lib/zm/client/tag/tags_builder.rb +6 -9
- data/lib/zm/client/tag/tags_collection.rb +6 -12
- data/lib/zm/client/tag.rb +2 -0
- data/lib/zm/client/task/tasks_collection.rb +6 -90
- data/lib/zm/client/upload/upload.rb +1 -1
- data/lib/zm/client/version.rb +1 -1
- data/lib/zm/modules/common/dl_common.rb +3 -1
- data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
- data/lib/zm/modules/zm_logger.rb +24 -0
- data/lib/zm/modules/zm_model.rb +41 -0
- data/test/accounts.rb +15 -1
- data/test/ace.rb +50 -0
- data/test/cluster.rb +41 -0
- data/test/cluster_zimbra_attributes.rb +38 -0
- data/test/folder.rb +125 -0
- data/test/folder_grant.rb +51 -0
- data/test/mountpoint.rb +49 -0
- data/test/retention_policies.rb +40 -0
- data/test/search_folder.rb +67 -0
- data/test/signature.rb +53 -0
- data/test/tag.rb +65 -0
- data/test/zimbra_attributes.rb +35 -0
- data/zm-ruby-client.gemspec +15 -10
- metadata +53 -26
- 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
|
-
@
|
193
|
+
@all = []
|
137
194
|
end
|
138
195
|
|
139
196
|
def add(attachment)
|
140
197
|
return unless attachment.is_a?(Attachment)
|
141
198
|
|
142
|
-
@
|
199
|
+
@all.push(attachment)
|
143
200
|
end
|
144
201
|
|
145
202
|
def to_jsns
|
146
|
-
@
|
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:
|
161
|
-
mid:
|
162
|
-
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,
|
@@ -3,108 +3,26 @@
|
|
3
3
|
module Zm
|
4
4
|
module Client
|
5
5
|
# Collection Messages
|
6
|
-
class MessagesCollection < Base::
|
7
|
-
attr_accessor :more
|
8
|
-
|
6
|
+
class MessagesCollection < Base::AccountSearchObjectsCollection
|
9
7
|
def initialize(parent)
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
-
@
|
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::
|
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
|
-
|
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
|
16
|
-
INSTANCE_VARIABLE_KEYS
|
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,
|
30
|
-
|
31
|
-
|
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
|
-
|
32
|
+
# todo
|
53
33
|
end
|
54
34
|
|
55
|
-
|
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
|
88
|
-
|
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
|
@@ -3,23 +3,20 @@
|
|
3
3
|
module Zm
|
4
4
|
module Client
|
5
5
|
# collection of mountpoints
|
6
|
-
class MountPointsCollection < Base::
|
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
|
-
@
|
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.
|
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
|
data/lib/zm/client/mountpoint.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
21
|
-
|
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
|