zm-ruby-client 0.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/Gemfile +8 -0
- data/LICENSE +674 -0
- data/README.md +47 -0
- data/SECURITY.md +21 -0
- data/lib/zm/client/account/account.rb +335 -0
- data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
- data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
- data/lib/zm/client/account/accounts_builder.rb +19 -0
- data/lib/zm/client/account/accounts_collection.rb +48 -0
- data/lib/zm/client/account.rb +7 -0
- data/lib/zm/client/ace/ace.rb +32 -0
- data/lib/zm/client/ace/aces_builder.rb +25 -0
- data/lib/zm/client/ace/aces_collection.rb +36 -0
- data/lib/zm/client/ace.rb +5 -0
- data/lib/zm/client/appointment/appointment.rb +143 -0
- data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
- data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
- data/lib/zm/client/appointment/appointments_builder.rb +33 -0
- data/lib/zm/client/appointment/appointments_collection.rb +106 -0
- data/lib/zm/client/appointment.rb +7 -0
- data/lib/zm/client/backup/backup.rb +59 -0
- data/lib/zm/client/backup/backups_builder.rb +26 -0
- data/lib/zm/client/backup/backups_collection.rb +22 -0
- data/lib/zm/client/backup.rb +5 -0
- data/lib/zm/client/base/account_object.rb +17 -0
- data/lib/zm/client/base/admin_object.rb +45 -0
- data/lib/zm/client/base/object.rb +80 -0
- data/lib/zm/client/base/objects_builder.rb +31 -0
- data/lib/zm/client/base/objects_collection.rb +135 -0
- data/lib/zm/client/base.rb +7 -0
- data/lib/zm/client/cluster/cluster.rb +117 -0
- data/lib/zm/client/cluster/cluster_config.rb +100 -0
- data/lib/zm/client/cluster.rb +4 -0
- data/lib/zm/client/common/message.rb +10 -0
- data/lib/zm/client/common/recipients.rb +67 -0
- data/lib/zm/client/common.rb +4 -0
- data/lib/zm/client/config.rb +12 -0
- data/lib/zm/client/connector/rest_account.rb +74 -0
- data/lib/zm/client/connector/soap_account.rb +562 -0
- data/lib/zm/client/connector/soap_admin.rb +512 -0
- data/lib/zm/client/connector/soap_base.rb +65 -0
- data/lib/zm/client/connector/soap_error.rb +26 -0
- data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
- data/lib/zm/client/constant.rb +217 -0
- data/lib/zm/client/contact/contact.rb +124 -0
- data/lib/zm/client/contact/contact_member.rb +73 -0
- data/lib/zm/client/contact/contacts_builder.rb +24 -0
- data/lib/zm/client/contact/contacts_collection.rb +26 -0
- data/lib/zm/client/contact/mod_group_contact.rb +74 -0
- data/lib/zm/client/contact.rb +7 -0
- data/lib/zm/client/cos/cos.rb +59 -0
- data/lib/zm/client/cos/coses_builder.rb +29 -0
- data/lib/zm/client/cos/coses_collection.rb +33 -0
- data/lib/zm/client/cos.rb +5 -0
- data/lib/zm/client/data_source.rb +5 -0
- data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
- data/lib/zm/client/distributionlist.rb +5 -0
- data/lib/zm/client/document/document.rb +47 -0
- data/lib/zm/client/document/documents_builder.rb +31 -0
- data/lib/zm/client/document/documents_collection.rb +93 -0
- data/lib/zm/client/document.rb +5 -0
- data/lib/zm/client/domain/domain.rb +74 -0
- data/lib/zm/client/domain/domains_builder.rb +32 -0
- data/lib/zm/client/domain/domains_collection.rb +36 -0
- data/lib/zm/client/domain.rb +5 -0
- data/lib/zm/client/folder/folder.rb +215 -0
- data/lib/zm/client/folder/folder_grant.rb +58 -0
- data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
- data/lib/zm/client/folder/folders_builder.rb +58 -0
- data/lib/zm/client/folder/folders_collection.rb +70 -0
- data/lib/zm/client/folder/mod_document_folder.rb +17 -0
- data/lib/zm/client/folder.rb +8 -0
- data/lib/zm/client/identity/identities_builder.rb +25 -0
- data/lib/zm/client/identity/identities_collection.rb +26 -0
- data/lib/zm/client/identity/identity.rb +75 -0
- data/lib/zm/client/identity.rb +5 -0
- data/lib/zm/client/license/license.rb +29 -0
- data/lib/zm/client/license/licenses_collection.rb +28 -0
- data/lib/zm/client/license.rb +4 -0
- data/lib/zm/client/message/message.rb +225 -0
- data/lib/zm/client/message/messages_builder.rb +31 -0
- data/lib/zm/client/message/messages_collection.rb +111 -0
- data/lib/zm/client/message.rb +5 -0
- data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
- data/lib/zm/client/mountpoint.rb +5 -0
- data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
- data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
- data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
- data/lib/zm/client/mta_queue.rb +5 -0
- data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
- data/lib/zm/client/mta_queue_item.rb +5 -0
- data/lib/zm/client/resource/resource.rb +149 -0
- data/lib/zm/client/resource/resources_builder.rb +29 -0
- data/lib/zm/client/resource/resources_collection.rb +41 -0
- data/lib/zm/client/resource.rb +5 -0
- data/lib/zm/client/search_folder/search_folder.rb +63 -0
- data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
- data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
- data/lib/zm/client/search_folder.rb +5 -0
- data/lib/zm/client/server/server.rb +516 -0
- data/lib/zm/client/server/servers_builder.rb +26 -0
- data/lib/zm/client/server/servers_collection.rb +37 -0
- data/lib/zm/client/server.rb +5 -0
- data/lib/zm/client/share/share.rb +60 -0
- data/lib/zm/client/share/shares_builder.rb +23 -0
- data/lib/zm/client/share/shares_collection.rb +48 -0
- data/lib/zm/client/share.rb +5 -0
- data/lib/zm/client/signature/signature.rb +62 -0
- data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
- data/lib/zm/client/signature/signatures_builder.rb +26 -0
- data/lib/zm/client/signature/signatures_collection.rb +28 -0
- data/lib/zm/client/signature.rb +6 -0
- data/lib/zm/client/tag/tag.rb +45 -0
- data/lib/zm/client/tag/tags_builder.rb +25 -0
- data/lib/zm/client/tag/tags_collection.rb +26 -0
- data/lib/zm/client/tag.rb +5 -0
- data/lib/zm/client/task/task.rb +74 -0
- data/lib/zm/client/task/tasks_builder.rb +31 -0
- data/lib/zm/client/task/tasks_collection.rb +100 -0
- data/lib/zm/client/task.rb +5 -0
- data/lib/zm/client/upload/upload.rb +154 -0
- data/lib/zm/client/upload.rb +3 -0
- data/lib/zm/client/version.rb +18 -0
- data/lib/zm/client.rb +5 -0
- data/lib/zm/modules/common/account_common.rb +71 -0
- data/lib/zm/modules/common/cos_common.rb +463 -0
- data/lib/zm/modules/common/dl_common.rb +33 -0
- data/lib/zm/modules/common/identity_common.rb +19 -0
- data/lib/zm/modules/common/resource_common.rb +59 -0
- data/lib/zm/modules/common/signature_common.rb +16 -0
- data/lib/zm/modules/common/zimbra-attrs.json +1 -0
- data/lib/zm/utils/thread_pool.rb +72 -0
- data/lib/zm-ruby-client.rb +1 -0
- data/test/accounts.rb +62 -0
- data/test/cluster_config.rb +30 -0
- data/test/coses.rb +26 -0
- data/test/domains.rb +62 -0
- data/zm-ruby-client.gemspec +24 -0
- metadata +243 -0
@@ -0,0 +1,225 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class message for account
|
6
|
+
class Message < Base::AccountObject
|
7
|
+
INSTANCE_VARIABLE_KEYS = %i[id date l su fr]
|
8
|
+
attr_accessor *INSTANCE_VARIABLE_KEYS
|
9
|
+
|
10
|
+
attr_accessor :subject
|
11
|
+
attr_reader :recipients, :attachments, :body, :folder
|
12
|
+
|
13
|
+
def initialize(parent, json = nil)
|
14
|
+
@parent = parent
|
15
|
+
@recipients = Recipients.new
|
16
|
+
@subject = ''
|
17
|
+
@body = Body.new
|
18
|
+
@attachments = Attachments.new
|
19
|
+
|
20
|
+
init_from_json(json) if json.is_a?(Hash)
|
21
|
+
|
22
|
+
yield(self) if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
def from
|
26
|
+
@from ||= @recipients.find { |r| r.field == Recipient::FROM }
|
27
|
+
end
|
28
|
+
|
29
|
+
def folder=(folder)
|
30
|
+
@folder = folder
|
31
|
+
@l = folder.id
|
32
|
+
end
|
33
|
+
|
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
|
+
def delete!
|
44
|
+
msg_action('delete')
|
45
|
+
end
|
46
|
+
|
47
|
+
def move!(folder_id = l)
|
48
|
+
msg_action('move', l: folder_id)
|
49
|
+
l = folder_id if l != folder_id
|
50
|
+
end
|
51
|
+
|
52
|
+
def unread!
|
53
|
+
msg_action('!read')
|
54
|
+
end
|
55
|
+
|
56
|
+
def read!
|
57
|
+
msg_action('read')
|
58
|
+
end
|
59
|
+
|
60
|
+
def unflag!
|
61
|
+
msg_action('!flag')
|
62
|
+
end
|
63
|
+
|
64
|
+
def flag!
|
65
|
+
msg_action('flag')
|
66
|
+
end
|
67
|
+
|
68
|
+
def untag!(tag_name)
|
69
|
+
msg_action('!tag', tn: tag_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
def tag!(tag_name)
|
73
|
+
msg_action('tag', tn: tag_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def unspam!
|
77
|
+
msg_action('!spam')
|
78
|
+
end
|
79
|
+
|
80
|
+
def spam!
|
81
|
+
msg_action('spam')
|
82
|
+
end
|
83
|
+
|
84
|
+
def trash!
|
85
|
+
msg_action('trash')
|
86
|
+
end
|
87
|
+
|
88
|
+
def send!
|
89
|
+
@parent.sacc.send_msg(@parent.token, to_jsns)
|
90
|
+
end
|
91
|
+
|
92
|
+
def init_from_json(json)
|
93
|
+
# puts json
|
94
|
+
@id = json[:id]
|
95
|
+
@date = Time.at(json[:d]/1000)
|
96
|
+
@l = json[:l]
|
97
|
+
@su = json[:su]
|
98
|
+
@fr = json[:fr]
|
99
|
+
|
100
|
+
json[:e].each do |e|
|
101
|
+
recipient = Recipient.new(e[:t], e[:a], e[:p])
|
102
|
+
@recipients.add(recipient)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def msg_action(action_name, options = {})
|
107
|
+
@parent.sacc.msg_action(@parent.token, action_name, id, options)
|
108
|
+
true
|
109
|
+
end
|
110
|
+
|
111
|
+
# content fo an email
|
112
|
+
class Body
|
113
|
+
attr_accessor :text, :html
|
114
|
+
|
115
|
+
def text_jsns
|
116
|
+
{ ct: 'text/plain', content: { _content: @text } }
|
117
|
+
end
|
118
|
+
|
119
|
+
def html_jsns
|
120
|
+
{ ct: 'text/html', content: { _content: @html } }
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_jsns
|
124
|
+
[
|
125
|
+
{
|
126
|
+
ct: 'multipart/alternative',
|
127
|
+
mp: [text_jsns, html_jsns]
|
128
|
+
}
|
129
|
+
]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# collection attachments
|
134
|
+
class Attachments
|
135
|
+
def initialize
|
136
|
+
@attachments = []
|
137
|
+
end
|
138
|
+
|
139
|
+
def add(attachment)
|
140
|
+
return unless attachment.is_a?(Attachment)
|
141
|
+
|
142
|
+
@attachments.push(attachment)
|
143
|
+
end
|
144
|
+
|
145
|
+
def to_jsns
|
146
|
+
@attachments.map(&:to_jsns)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# class attachment for email
|
151
|
+
class Attachment
|
152
|
+
attr_accessor :aid, :part, :mid
|
153
|
+
|
154
|
+
def initialize
|
155
|
+
yield(self) if block_given?
|
156
|
+
end
|
157
|
+
|
158
|
+
def to_jsns
|
159
|
+
{
|
160
|
+
part: @part,
|
161
|
+
mid: @mid,
|
162
|
+
aid: @aid
|
163
|
+
}.reject { |_, v| v.nil? }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Collection recipients
|
168
|
+
class Recipients
|
169
|
+
def initialize
|
170
|
+
@recipients = []
|
171
|
+
end
|
172
|
+
|
173
|
+
def to_jsns
|
174
|
+
@recipients.map(&:to_jsns)
|
175
|
+
end
|
176
|
+
|
177
|
+
def add(recipient)
|
178
|
+
return unless recipient.is_a?(Recipient)
|
179
|
+
|
180
|
+
@recipients.push(recipient)
|
181
|
+
end
|
182
|
+
|
183
|
+
def to
|
184
|
+
@recipients.select { |r| r.field == Recipient::TO }
|
185
|
+
end
|
186
|
+
|
187
|
+
def cc
|
188
|
+
@recipients.select { |r| r.field == Recipient::CC }
|
189
|
+
end
|
190
|
+
|
191
|
+
def bcc
|
192
|
+
@recipients.select { |r| r.field == Recipient::BCC }
|
193
|
+
end
|
194
|
+
|
195
|
+
def from
|
196
|
+
@recipients.select { |r| r.field == Recipient::FROM }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Class one recipient for email
|
201
|
+
class Recipient
|
202
|
+
FROM = :f
|
203
|
+
TO = :t
|
204
|
+
CC = :c
|
205
|
+
BCC = :b
|
206
|
+
|
207
|
+
attr_accessor :field, :email, :display_name
|
208
|
+
|
209
|
+
def initialize(field, email, display_name = nil)
|
210
|
+
@email = email
|
211
|
+
@field = field.to_sym
|
212
|
+
@display_name = display_name
|
213
|
+
end
|
214
|
+
|
215
|
+
def to_jsns
|
216
|
+
{
|
217
|
+
t: @field,
|
218
|
+
a: @email,
|
219
|
+
p: @display_name
|
220
|
+
}.reject { |_, v| v.nil? }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class factory [messages]
|
6
|
+
class MessagesBuilder < Base::ObjectsBuilder
|
7
|
+
def initialize(account, json)
|
8
|
+
@account = account
|
9
|
+
@json = json
|
10
|
+
end
|
11
|
+
|
12
|
+
def make
|
13
|
+
root.map do |s|
|
14
|
+
Message.new(@account, s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ids
|
19
|
+
root.map { |s| s[:id] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def root
|
23
|
+
root = @json[:Body][:SearchResponse][:m]
|
24
|
+
return [] if root.nil?
|
25
|
+
|
26
|
+
root = [root] unless root.is_a?(Array)
|
27
|
+
root
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# Collection Messages
|
6
|
+
class MessagesCollection < Base::ObjectsCollection
|
7
|
+
attr_accessor :more
|
8
|
+
|
9
|
+
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
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
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
|
+
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 }
|
99
|
+
end
|
100
|
+
|
101
|
+
def reset_query_params
|
102
|
+
super
|
103
|
+
@start_at = nil
|
104
|
+
@end_at = nil
|
105
|
+
@query = nil
|
106
|
+
@folder_ids = []
|
107
|
+
@folders = []
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class for account mountpoint
|
6
|
+
class MountPoint < Base::AccountObject
|
7
|
+
INSTANCE_VARIABLE_KEYS = %i[
|
8
|
+
owner rev reminder ms deletable l rid uuid url f broken
|
9
|
+
luuid ruuid activesyncdisabled absFolderPath view zid name id
|
10
|
+
webOfflineSyncDays color rgb
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
attr_accessor(*INSTANCE_VARIABLE_KEYS)
|
14
|
+
|
15
|
+
def concat
|
16
|
+
INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
|
17
|
+
end
|
18
|
+
|
19
|
+
alias parent_id l
|
20
|
+
|
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
|
+
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)
|
49
|
+
end
|
50
|
+
|
51
|
+
def update!(options)
|
52
|
+
@parent.sacc.folder_action(@parent.token, 'update', @id, options)
|
53
|
+
end
|
54
|
+
|
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
|
86
|
+
|
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
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class factory [mountpoints]
|
6
|
+
class MountPointsBuilder < Base::ObjectsBuilder
|
7
|
+
def initialize(account, json)
|
8
|
+
@account = account
|
9
|
+
@json = json
|
10
|
+
@key_link = :link
|
11
|
+
@key_folder = :folder
|
12
|
+
@list = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def make
|
16
|
+
root = @json[:Body][:GetFolderResponse][@key_folder]
|
17
|
+
|
18
|
+
construct_tree(root)
|
19
|
+
|
20
|
+
@list
|
21
|
+
end
|
22
|
+
|
23
|
+
def construct_tree(json_folders)
|
24
|
+
json_folders.each do |json_folder|
|
25
|
+
if json_folder[@key_link].is_a?(Array)
|
26
|
+
@list += json_folder[@key_link].map do |json_link|
|
27
|
+
MountPoint.new(@account, json_link)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
next if json_folder[@key_folder].nil? || json_folder[@key_folder].empty?
|
32
|
+
|
33
|
+
construct_tree(json_folder[@key_folder])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# collection of mountpoints
|
6
|
+
class MountPointsCollection < Base::ObjectsCollection
|
7
|
+
METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
|
8
|
+
|
9
|
+
attr_reader :root
|
10
|
+
|
11
|
+
def initialize(parent)
|
12
|
+
@parent = parent
|
13
|
+
@root = nil
|
14
|
+
reset_query_params
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
mountpoint = MountPoint.new(@parent)
|
19
|
+
yield(mountpoint) if block_given?
|
20
|
+
mountpoint
|
21
|
+
end
|
22
|
+
|
23
|
+
def where(view: nil, tr: nil)
|
24
|
+
@view = view
|
25
|
+
@tr = tr
|
26
|
+
@all = nil
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def all
|
31
|
+
@all || all!
|
32
|
+
end
|
33
|
+
|
34
|
+
def all!
|
35
|
+
build_response
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear
|
39
|
+
@all = nil
|
40
|
+
@root = nil
|
41
|
+
reset_query_params
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_response
|
47
|
+
@all = MountPointsBuilder.new(@parent, make_query).make
|
48
|
+
@all
|
49
|
+
end
|
50
|
+
|
51
|
+
def make_query
|
52
|
+
@parent.sacc.get_all_folders(@parent.token, @view, @tr)
|
53
|
+
end
|
54
|
+
|
55
|
+
def reset_query_params
|
56
|
+
@view = nil
|
57
|
+
@tr = nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zm/client/mta_queue_item'
|
4
|
+
|
5
|
+
module Zm
|
6
|
+
module Client
|
7
|
+
class MtaQueue < Base::AdminObject
|
8
|
+
attr_reader :name, :n
|
9
|
+
|
10
|
+
alias nb_items n
|
11
|
+
|
12
|
+
def server
|
13
|
+
parent
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
|
18
|
+
hashmap.delete_if { |_, v| v.nil? }
|
19
|
+
hashmap
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
to_h.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_instance_variable_keys
|
27
|
+
%w[name n]
|
28
|
+
end
|
29
|
+
|
30
|
+
def items
|
31
|
+
@items ||= MtaQueueItemsCollection.new self
|
32
|
+
end
|
33
|
+
|
34
|
+
def do_action(action_name, ids)
|
35
|
+
sac.mail_queue_action(parent.name, name, action_name, ids)
|
36
|
+
end
|
37
|
+
|
38
|
+
def hold!(ids)
|
39
|
+
do_action(Zm::Client::MtaQueueAction::HOLD, ids)
|
40
|
+
end
|
41
|
+
|
42
|
+
def release!(ids)
|
43
|
+
do_action(Zm::Client::MtaQueueAction::RELEASE, ids)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete!(ids)
|
47
|
+
do_action(Zm::Client::MtaQueueAction::DELETE, ids)
|
48
|
+
end
|
49
|
+
|
50
|
+
def requeue!(ids)
|
51
|
+
do_action(Zm::Client::MtaQueueAction::REQUEUE, ids)
|
52
|
+
end
|
53
|
+
|
54
|
+
def init_from_json(json)
|
55
|
+
@name = json[:name]
|
56
|
+
@n = json[:n].to_i
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class factory [MtaQueue]
|
6
|
+
class MtaQueuesBuilder < Base::ObjectsBuilder
|
7
|
+
def make
|
8
|
+
records = []
|
9
|
+
return records if json_items.nil?
|
10
|
+
|
11
|
+
json_items.each do |entry|
|
12
|
+
mta_queue = MtaQueue.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
|
+
@json_items ||= @json[:Body][json_key][:server].first[:queue]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|