zm-ruby-client 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +674 -0
  5. data/README.md +47 -0
  6. data/SECURITY.md +21 -0
  7. data/lib/zm/client/account/account.rb +345 -0
  8. data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
  9. data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
  10. data/lib/zm/client/account/accounts_builder.rb +19 -0
  11. data/lib/zm/client/account/accounts_collection.rb +48 -0
  12. data/lib/zm/client/account.rb +7 -0
  13. data/lib/zm/client/ace/ace.rb +32 -0
  14. data/lib/zm/client/ace/aces_builder.rb +25 -0
  15. data/lib/zm/client/ace/aces_collection.rb +36 -0
  16. data/lib/zm/client/ace.rb +5 -0
  17. data/lib/zm/client/appointment/appointment.rb +143 -0
  18. data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
  19. data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
  20. data/lib/zm/client/appointment/appointments_builder.rb +33 -0
  21. data/lib/zm/client/appointment/appointments_collection.rb +106 -0
  22. data/lib/zm/client/appointment.rb +7 -0
  23. data/lib/zm/client/backup/backup.rb +59 -0
  24. data/lib/zm/client/backup/backups_builder.rb +26 -0
  25. data/lib/zm/client/backup/backups_collection.rb +22 -0
  26. data/lib/zm/client/backup.rb +5 -0
  27. data/lib/zm/client/base/account_object.rb +17 -0
  28. data/lib/zm/client/base/admin_object.rb +45 -0
  29. data/lib/zm/client/base/object.rb +80 -0
  30. data/lib/zm/client/base/objects_builder.rb +31 -0
  31. data/lib/zm/client/base/objects_collection.rb +135 -0
  32. data/lib/zm/client/base.rb +7 -0
  33. data/lib/zm/client/cluster/cluster.rb +121 -0
  34. data/lib/zm/client/cluster/cluster_config.rb +100 -0
  35. data/lib/zm/client/cluster.rb +4 -0
  36. data/lib/zm/client/common/message.rb +10 -0
  37. data/lib/zm/client/common/recipients.rb +67 -0
  38. data/lib/zm/client/common/token_metadata.rb +44 -0
  39. data/lib/zm/client/common.rb +5 -0
  40. data/lib/zm/client/config.rb +12 -0
  41. data/lib/zm/client/connector/rest_account.rb +74 -0
  42. data/lib/zm/client/connector/soap_account.rb +563 -0
  43. data/lib/zm/client/connector/soap_admin.rb +532 -0
  44. data/lib/zm/client/connector/soap_base.rb +65 -0
  45. data/lib/zm/client/connector/soap_error.rb +26 -0
  46. data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
  47. data/lib/zm/client/constant.rb +217 -0
  48. data/lib/zm/client/contact/contact.rb +124 -0
  49. data/lib/zm/client/contact/contact_member.rb +73 -0
  50. data/lib/zm/client/contact/contacts_builder.rb +24 -0
  51. data/lib/zm/client/contact/contacts_collection.rb +26 -0
  52. data/lib/zm/client/contact/mod_group_contact.rb +74 -0
  53. data/lib/zm/client/contact.rb +7 -0
  54. data/lib/zm/client/cos/cos.rb +59 -0
  55. data/lib/zm/client/cos/coses_builder.rb +29 -0
  56. data/lib/zm/client/cos/coses_collection.rb +33 -0
  57. data/lib/zm/client/cos.rb +5 -0
  58. data/lib/zm/client/data_source.rb +5 -0
  59. data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
  60. data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
  61. data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
  62. data/lib/zm/client/distributionlist.rb +5 -0
  63. data/lib/zm/client/document/document.rb +51 -0
  64. data/lib/zm/client/document/documents_builder.rb +31 -0
  65. data/lib/zm/client/document/documents_collection.rb +93 -0
  66. data/lib/zm/client/document.rb +5 -0
  67. data/lib/zm/client/domain/domain.rb +85 -0
  68. data/lib/zm/client/domain/domains_builder.rb +32 -0
  69. data/lib/zm/client/domain/domains_collection.rb +36 -0
  70. data/lib/zm/client/domain.rb +5 -0
  71. data/lib/zm/client/folder/folder.rb +215 -0
  72. data/lib/zm/client/folder/folder_grant.rb +58 -0
  73. data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
  74. data/lib/zm/client/folder/folders_builder.rb +58 -0
  75. data/lib/zm/client/folder/folders_collection.rb +95 -0
  76. data/lib/zm/client/folder/mod_document_folder.rb +17 -0
  77. data/lib/zm/client/folder.rb +8 -0
  78. data/lib/zm/client/identity/identities_builder.rb +25 -0
  79. data/lib/zm/client/identity/identities_collection.rb +26 -0
  80. data/lib/zm/client/identity/identity.rb +75 -0
  81. data/lib/zm/client/identity.rb +5 -0
  82. data/lib/zm/client/license/license.rb +29 -0
  83. data/lib/zm/client/license/licenses_collection.rb +28 -0
  84. data/lib/zm/client/license.rb +4 -0
  85. data/lib/zm/client/message/message.rb +225 -0
  86. data/lib/zm/client/message/messages_builder.rb +31 -0
  87. data/lib/zm/client/message/messages_collection.rb +111 -0
  88. data/lib/zm/client/message.rb +5 -0
  89. data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
  90. data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
  91. data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
  92. data/lib/zm/client/mountpoint.rb +5 -0
  93. data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
  94. data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
  95. data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
  96. data/lib/zm/client/mta_queue.rb +5 -0
  97. data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
  98. data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
  99. data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
  100. data/lib/zm/client/mta_queue_item.rb +5 -0
  101. data/lib/zm/client/resource/resource.rb +149 -0
  102. data/lib/zm/client/resource/resources_builder.rb +29 -0
  103. data/lib/zm/client/resource/resources_collection.rb +41 -0
  104. data/lib/zm/client/resource.rb +5 -0
  105. data/lib/zm/client/search_folder/search_folder.rb +63 -0
  106. data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
  107. data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
  108. data/lib/zm/client/search_folder.rb +5 -0
  109. data/lib/zm/client/server/server.rb +516 -0
  110. data/lib/zm/client/server/servers_builder.rb +26 -0
  111. data/lib/zm/client/server/servers_collection.rb +37 -0
  112. data/lib/zm/client/server.rb +5 -0
  113. data/lib/zm/client/share/share.rb +60 -0
  114. data/lib/zm/client/share/shares_builder.rb +23 -0
  115. data/lib/zm/client/share/shares_collection.rb +48 -0
  116. data/lib/zm/client/share.rb +5 -0
  117. data/lib/zm/client/signature/signature.rb +62 -0
  118. data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
  119. data/lib/zm/client/signature/signatures_builder.rb +26 -0
  120. data/lib/zm/client/signature/signatures_collection.rb +28 -0
  121. data/lib/zm/client/signature.rb +6 -0
  122. data/lib/zm/client/tag/tag.rb +45 -0
  123. data/lib/zm/client/tag/tags_builder.rb +25 -0
  124. data/lib/zm/client/tag/tags_collection.rb +26 -0
  125. data/lib/zm/client/tag.rb +5 -0
  126. data/lib/zm/client/task/task.rb +74 -0
  127. data/lib/zm/client/task/tasks_builder.rb +31 -0
  128. data/lib/zm/client/task/tasks_collection.rb +100 -0
  129. data/lib/zm/client/task.rb +5 -0
  130. data/lib/zm/client/upload/upload.rb +154 -0
  131. data/lib/zm/client/upload.rb +3 -0
  132. data/lib/zm/client/version.rb +18 -0
  133. data/lib/zm/client.rb +5 -0
  134. data/lib/zm/modules/common/account_common.rb +71 -0
  135. data/lib/zm/modules/common/cos_common.rb +463 -0
  136. data/lib/zm/modules/common/dl_common.rb +36 -0
  137. data/lib/zm/modules/common/identity_common.rb +19 -0
  138. data/lib/zm/modules/common/resource_common.rb +59 -0
  139. data/lib/zm/modules/common/signature_common.rb +16 -0
  140. data/lib/zm/modules/common/zimbra-attrs.json +1 -0
  141. data/lib/zm/utils/thread_pool.rb +72 -0
  142. data/lib/zm-ruby-client.rb +1 -0
  143. data/test/accounts.rb +62 -0
  144. data/test/cluster_config.rb +30 -0
  145. data/test/coses.rb +26 -0
  146. data/test/domains.rb +70 -0
  147. data/zm-ruby-client.gemspec +24 -0
  148. metadata +244 -0
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection of shares
6
+ class SharesCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ reset_query_params
10
+ end
11
+
12
+ def new(json)
13
+ share = Share.new(@parent, json)
14
+ yield(share) if block_given?
15
+ share
16
+ end
17
+
18
+ def where(owner_name: nil)
19
+ @owner_name = owner_name
20
+ self
21
+ end
22
+
23
+ private
24
+
25
+ def build_response
26
+ share_builder.make
27
+ end
28
+
29
+ def share_response
30
+ @parent.sacc.get_share_info @parent.token, build_options
31
+ end
32
+
33
+ def share_builder
34
+ ShareBuilder.new(@parent, share_response)
35
+ end
36
+
37
+ def build_options
38
+ return {} if @owner_name.nil?
39
+
40
+ { owner: { by: :name, _content: @owner_name } }
41
+ end
42
+
43
+ def reset_query_params
44
+ @owner_name = nil
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/share/share'
4
+ require 'zm/client/share/shares_builder'
5
+ require 'zm/client/share/shares_collection'
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account signature
6
+ class Signature < Base::AccountObject
7
+ TYPE_TXT = 'text/plain'
8
+ TYPE_HTML = 'text/html'
9
+
10
+ INSTANCE_VARIABLE_KEYS = %i[id name txt html]
11
+
12
+ attr_accessor *INSTANCE_VARIABLE_KEYS
13
+
14
+ def concat
15
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
16
+ end
17
+
18
+ def init_from_json(json)
19
+ @id = json[:id]
20
+ @name = json[:name]
21
+ json[:content].each do |c|
22
+ @txt = c[:_content] if c[:type] == TYPE_TXT
23
+ @html = c[:_content] if c[:type] == TYPE_HTML
24
+ end if json[:content].is_a?(Array)
25
+ end
26
+
27
+ def create!
28
+ rep = @parent.sacc.create_signature(@parent.token, as_jsns)
29
+ @id = rep[:Body][:CreateSignatureResponse][:signature].first[:id]
30
+ end
31
+
32
+ def modify!
33
+ @parent.sacc.modify_signature(@parent.token, as_jsns)
34
+ end
35
+
36
+ def delete!
37
+ @parent.sacc.delete_signature(@parent.token, id)
38
+ end
39
+
40
+ def type
41
+ return TYPE_HTML unless html.nil?
42
+ TYPE_TXT
43
+ end
44
+
45
+ def html?
46
+ type == TYPE_HTML
47
+ end
48
+
49
+ def txt?
50
+ type == TYPE_TXT
51
+ end
52
+
53
+ def content
54
+ html || txt
55
+ end
56
+
57
+ def as_jsns
58
+ SignatureJsnsBuilder.new(self).to_jsns
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account signature
6
+ class SignatureJsnsBuilder
7
+
8
+ def initialize(signature)
9
+ @signature = signature
10
+ end
11
+
12
+ def to_jsns
13
+ jsns = {
14
+ signature: {
15
+ name: @signature.name,
16
+ content: {
17
+ type: @signature.type,
18
+ _content: @signature.content
19
+ }
20
+ }
21
+ }
22
+
23
+ jsns[:signature][:id] = @signature.id unless @signature.id.nil?
24
+
25
+ jsns
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [folders]
6
+ class SignaturesBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root = @json[:Body][:GetSignaturesResponse][:signature]
14
+ return [] if root.nil?
15
+
16
+ root = [root] unless root.is_a?(Array)
17
+
18
+ root.map do |s|
19
+ signature = Signature.new(@parent)
20
+ signature.init_from_json(s)
21
+ signature
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection of signatures
6
+ class SignaturesCollection < Base::ObjectsCollection
7
+ METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
+
9
+ def initialize(parent)
10
+ @parent = parent
11
+ end
12
+
13
+ def new
14
+ signature = Signature.new(@parent)
15
+ yield(signature) if block_given?
16
+ signature
17
+ end
18
+
19
+ private
20
+
21
+ def build_response
22
+ rep = @parent.sacc.get_signatures(@parent.token)
23
+ sb = SignaturesBuilder.new @parent, rep
24
+ sb.make
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/signature/signature'
4
+ require 'zm/client/signature/signature_jsns_builder'
5
+ require 'zm/client/signature/signatures_builder'
6
+ require 'zm/client/signature/signatures_collection'
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class account tag
6
+ class Tag < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[id name color rgb u n d rev md ms]
9
+
10
+ attr_accessor *INSTANCE_VARIABLE_KEYS
11
+
12
+ def concat
13
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
14
+ end
15
+
16
+ def init_from_json(json)
17
+ INSTANCE_VARIABLE_KEYS.each do |key|
18
+ instance_variable_set(arrow_name(key), json[key])
19
+ end
20
+ end
21
+
22
+ def create!
23
+ rep = @parent.sacc.create_tag(@parent.token, @name, @color, @rgb)
24
+ init_from_json(rep[:Body][:CreateTagResponse][:tag].first)
25
+ end
26
+
27
+ def modify!
28
+ @parent.sacc.tag_action(@parent.token, :update, @id, { color: @color, rgb: @rgb })
29
+ end
30
+
31
+ def delete!
32
+ @parent.sacc.tag_action(@parent.token, :delete, @id)
33
+ end
34
+
35
+ def rename!(new_name)
36
+ @parent.sacc.tag_action(
37
+ @parent.token,
38
+ :rename,
39
+ @id,
40
+ name: new_name
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [tags]
6
+ class TagBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root = @json[:Body][:GetTagResponse][:tag]
14
+ return [] if root.nil?
15
+
16
+ root = [root] unless root.is_a?(Array)
17
+ root.map do |s|
18
+ tag = Tag.new(@parent)
19
+ tag.init_from_json(s)
20
+ tag
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection account tags
6
+ class TagsCollection < Base::ObjectsCollection
7
+ def initialize(parent)
8
+ @parent = parent
9
+ end
10
+
11
+ def new
12
+ tag = Tag.new(@parent)
13
+ yield(tag) if block_given?
14
+ tag
15
+ end
16
+
17
+ private
18
+
19
+ def build_response
20
+ rep = @parent.sacc.get_tag(@parent.token)
21
+ tb = TagBuilder.new @parent, rep
22
+ tb.make
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/tag/tag'
4
+ require 'zm/client/tag/tags_builder'
5
+ require 'zm/client/tag/tags_collection'
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account task
6
+ class Task < Base::AccountObject
7
+
8
+ INSTANCE_VARIABLE_KEYS = %i[id uid name l desc start_at dur end_at tn]
9
+
10
+ attr_accessor *INSTANCE_VARIABLE_KEYS
11
+ attr_writer :folder
12
+ attr_reader :json
13
+
14
+ alias description desc
15
+ alias parent_id l
16
+
17
+ def initialize(parent, json = nil)
18
+ @parent = parent
19
+ init_from_json(json) if json.is_a?(Hash)
20
+ yield(self) if block_given?
21
+ end
22
+
23
+ def concat
24
+ INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
25
+ end
26
+
27
+ def folder
28
+ @folder ||= @parent.folders.all.find { |folder| folder.id == l }
29
+ end
30
+
31
+ def download(dest_file_path, fmt = 'ics')
32
+ # @parent.uploader.download_file(folder.absFolderPath, 'ics', ['task'], [id], dest_file_path)
33
+ uploader = Upload.new(@parent, RestAccountConnector.new)
34
+ uploader.download_file(folder.absFolderPath, fmt, ['task'], [id], dest_file_path)
35
+ end
36
+
37
+ def create!
38
+ # rep = @parent.sacc.create_task(@parent.token, @l, @name, @view)
39
+ # init_from_json(rep[:Body][:CreateTaskResponse][:task].first)
40
+ end
41
+
42
+ def reload!
43
+ # rep = @parent.sacc.get_task(@parent.token, @id)
44
+ # init_from_json(rep[:Body][:GetTaskResponse][:task].first)
45
+ end
46
+
47
+ def delete!
48
+ # @parent.sacc.task_action(@parent.token, :delete, @id)
49
+ end
50
+
51
+ def init_from_json(json)
52
+ @json = json
53
+ @id = json[:id].to_i
54
+ @uid = json[:uid]
55
+ @tn = json[:tn]
56
+ @name = json[:name]
57
+ @l = json[:l]
58
+ @desc = json[:fr]
59
+ make_date(json)
60
+ end
61
+
62
+ def make_date(json)
63
+ return if json[:inst].nil? || json[:inst].first.empty? || json[:dur].nil?
64
+
65
+ @start_at = Time.at(json[:inst].first[:s] / 1000)
66
+ @end_at = Time.at((json[:inst].first[:s] + json[:dur]) / 1000)
67
+
68
+ return if json[:dur].nil?
69
+
70
+ @dur = json[:dur] / 1000
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class factory [tasks]
6
+ class TasksBuilder < Base::ObjectsBuilder
7
+ def initialize(parent, json)
8
+ @parent = parent
9
+ @json = json
10
+ end
11
+
12
+ def make
13
+ root.map do |s|
14
+ Task.new(@parent, 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][:task]
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,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # collection of tasks
6
+ class TasksCollection < 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
+ def new
16
+ task = Task.new(@parent)
17
+ yield(task) if block_given?
18
+ task
19
+ end
20
+
21
+ def start_at(start_at)
22
+ @start_at = start_at
23
+ self
24
+ end
25
+
26
+ def end_at(end_at)
27
+ @end_at = end_at
28
+ self
29
+ end
30
+
31
+ def folders(folders)
32
+ @folders = folders
33
+ @folder_ids = @folders.map(&:id)
34
+ self
35
+ end
36
+
37
+ def folder_ids(folder_ids)
38
+ @folder_ids = folder_ids
39
+ self
40
+ end
41
+
42
+ def where(query)
43
+ @query = query
44
+ self
45
+ end
46
+
47
+ def ids
48
+ search_builder.ids
49
+ end
50
+
51
+ private
52
+
53
+ def search_response
54
+ rep = @parent.sacc.search(@parent.token, 'task', @offset, @limit, 'taskDueAsc', query, build_options)
55
+ @more = rep[:Body][:SearchResponse][:more]
56
+ rep
57
+ end
58
+
59
+ def search_builder
60
+ TasksBuilder.new(@parent, search_response)
61
+ end
62
+
63
+ def build_response
64
+ tasks = search_builder.make
65
+ tasks.each { |appo| appo.folder = find_folder(appo) } unless @folders.empty?
66
+ tasks
67
+ end
68
+
69
+ def build_options
70
+ return {} if !@start_at.is_a?(Time) && !@end_at.is_a?(Time)
71
+
72
+ {
73
+ calExpandInstStart: (@start_at.to_f * 1000).to_i,
74
+ calExpandInstEnd: (@end_at.to_f * 1000).to_i,
75
+ }
76
+ end
77
+
78
+ def query
79
+ return @query unless @query.nil?
80
+
81
+ return nil if @folder_ids.empty?
82
+
83
+ @folder_ids.map { |id| %Q{inid:"#{id}"} }.join(' OR ')
84
+ end
85
+
86
+ def find_folder(task)
87
+ @folders.find { |folder| folder.id == task.l }
88
+ end
89
+
90
+ def reset_query_params
91
+ super
92
+ @start_at = nil
93
+ @end_at = nil
94
+ @query = nil
95
+ @folder_ids = []
96
+ @folders = []
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/task/task'
4
+ require 'zm/client/task/tasks_builder'
5
+ require 'zm/client/task/tasks_collection'
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for upload account file
6
+ class Upload
7
+ FMT_TYPES_H = {
8
+ 'ics' => ['appointment'],
9
+ 'vcard' => ['contact']
10
+ }
11
+
12
+ def initialize(parent, rac = nil)
13
+ @parent = parent
14
+ @rac = rac || @parent.rac
15
+ end
16
+
17
+ def download_file_with_url(url, dest_file_path)
18
+ url = File.join(@parent.home_url, url) unless url.start_with?('http')
19
+ @rac.download(url, dest_file_path)
20
+ end
21
+
22
+ def download_file(folder_path, fmt, types, ids, dest_file_path)
23
+ @rac.download(download_file_url(folder_path, fmt, types, ids), dest_file_path)
24
+ end
25
+
26
+ def download_folder(id, fmt, dest_file_path)
27
+ @rac.download(download_folder_url(id, fmt), dest_file_path)
28
+ end
29
+
30
+ def download_folder_url(id, fmt)
31
+ url_folder_path = @parent.home_url
32
+
33
+ h = {
34
+ fmt: fmt,
35
+ id: id,
36
+ emptyname: 'Vide',
37
+ charset: 'UTF-8',
38
+ auth: 'qp',
39
+ zauthtoken: @parent.token,
40
+ disp: 'a'
41
+ }
42
+
43
+ uri = Addressable::URI.new
44
+ uri.query_values = h
45
+ url_folder_path << '?' << uri.query
46
+
47
+ puts url_folder_path
48
+
49
+ url_folder_path
50
+ end
51
+
52
+ def download_file_url(folder_path, fmt, types, ids = [])
53
+ url_folder_path = File.join(@parent.home_url, folder_path.to_s)
54
+
55
+ h = {
56
+ fmt: fmt,
57
+ types: query_value_types(types, fmt),
58
+ emptyname: 'Vide',
59
+ charset: 'UTF-8',
60
+ auth: 'qp',
61
+ zauthtoken: @parent.token,
62
+ disp: 'a'
63
+ }
64
+
65
+ h.merge!(query_ids(ids))
66
+
67
+ h.reject! { |_, v| is_blank?(v) }
68
+
69
+ uri = Addressable::URI.new
70
+ uri.query_values = h
71
+ url_folder_path << '?' << uri.query
72
+
73
+ # puts url_folder_path
74
+
75
+ url_folder_path
76
+ end
77
+
78
+ def send_file(folder_path, fmt, types, resolve, src_file_path)
79
+ @rac.upload(send_file_url(folder_path, fmt, types, resolve), src_file_path)
80
+ end
81
+
82
+ def send_file_url(folder_path, fmt, types, resolve)
83
+ # resolve=[modfy|replace|reset|skip]
84
+ url_folder_path = File.join(@parent.home_url, folder_path.to_s)
85
+
86
+ h = {
87
+ fmt: fmt,
88
+ types: query_value_types(types, fmt),
89
+ resolve: resolve,
90
+ auth: 'qp',
91
+ zauthtoken: @parent.token
92
+ }
93
+
94
+ h.reject! { |_, v| is_blank?(v) }
95
+
96
+ uri = Addressable::URI.new
97
+ uri.query_values = h
98
+
99
+ url_folder_path << '?' << uri.query
100
+ url_folder_path
101
+ end
102
+
103
+ def send_attachment(src_file_path)
104
+ str = upload_attachment(src_file_path)
105
+ AttachmentResponse.new(str)
106
+ end
107
+
108
+ def upload_attachment(src_file_path)
109
+ @rac.upload(upload_attachment_url, src_file_path)
110
+ end
111
+
112
+ def upload_attachment_url
113
+ @rac.cookie("ZM_AUTH_TOKEN=#{@parent.token}")
114
+ uri = Addressable::URI.new
115
+ uri.query_values = {
116
+ fmt: 'extended,raw'
117
+ }
118
+ File.join(@parent.public_url, 'service/upload') << '?' << uri.query
119
+ end
120
+
121
+ def query_ids(ids)
122
+ return {} if ids.nil?
123
+ return { id: ids } unless ids.is_a?(Array)
124
+ return { id: ids.first } if ids.length == 1
125
+ return { list: ids.join(',') }
126
+ end
127
+
128
+ def query_value_types(types, fmt)
129
+ types = FMT_TYPES_H[fmt] if types.nil?
130
+
131
+ types = [types] unless types.is_a?(Array)
132
+ types.join(',')
133
+ end
134
+
135
+ def is_blank?(v)
136
+ return false if v.is_a?(Numeric)
137
+
138
+ v.nil? || v.empty?
139
+ end
140
+ end
141
+
142
+ # class to parse upload attachment response
143
+ class AttachmentResponse
144
+ def initialize(str)
145
+ @str = str
146
+ @str_h = JSON.parse(str[str.index('['), str.length], symbolize_names: true).first
147
+ end
148
+
149
+ def aid
150
+ @str_h[:aid]
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zm/client/upload/upload'