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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -5
  4. data/README.md +6 -0
  5. data/lib/zm/client/account/account.rb +29 -17
  6. data/lib/zm/client/account/account_jsns_initializer.rb +44 -0
  7. data/lib/zm/client/account/accounts_builder.rb +6 -3
  8. data/lib/zm/client/account/accounts_collection.rb +11 -20
  9. data/lib/zm/client/account.rb +1 -0
  10. data/lib/zm/client/ace/ace.rb +22 -9
  11. data/lib/zm/client/ace/ace_jsns_builder.rb +38 -0
  12. data/lib/zm/client/ace/ace_jsns_initializer.rb +26 -0
  13. data/lib/zm/client/ace/aces_builder.rb +6 -9
  14. data/lib/zm/client/ace/aces_collection.rb +23 -9
  15. data/lib/zm/client/ace.rb +2 -0
  16. data/lib/zm/client/appointment/appointment.rb +9 -6
  17. data/lib/zm/client/appointment/appointments_collection.rb +6 -90
  18. data/lib/zm/client/backup/backup.rb +8 -4
  19. data/lib/zm/client/base/account_object.rb +34 -0
  20. data/lib/zm/client/base/account_objects_collection.rb +14 -0
  21. data/lib/zm/client/base/account_search_objects_collection.rb +125 -0
  22. data/lib/zm/client/base/admin_object.rb +6 -0
  23. data/lib/zm/client/base/admin_objects_collection.rb +65 -0
  24. data/lib/zm/client/base/base_jsns_builder.rb +19 -0
  25. data/lib/zm/client/base/base_jsns_initializer.rb +29 -0
  26. data/lib/zm/client/base/folder_object.rb +41 -0
  27. data/lib/zm/client/base/ldap_filter.rb +33 -0
  28. data/lib/zm/client/base/object.rb +19 -0
  29. data/lib/zm/client/base/objects_builder.rb +4 -0
  30. data/lib/zm/client/base/objects_collection.rb +11 -32
  31. data/lib/zm/client/base/zimbra_attribute.rb +119 -0
  32. data/lib/zm/client/base/zimbra_attributes_collection.rb +38 -0
  33. data/lib/zm/client/base.rb +15 -0
  34. data/lib/zm/client/cluster/cluster.rb +43 -7
  35. data/lib/zm/client/cluster/cluster_config.rb +19 -17
  36. data/lib/zm/client/connector/rest_account.rb +0 -3
  37. data/lib/zm/client/connector/soap_account.rb +76 -177
  38. data/lib/zm/client/connector/soap_admin.rb +82 -51
  39. data/lib/zm/client/connector/soap_base.rb +12 -12
  40. data/lib/zm/client/contact/contact.rb +2 -1
  41. data/lib/zm/client/contact/contacts_builder.rb +3 -13
  42. data/lib/zm/client/contact/contacts_collection.rb +6 -12
  43. data/lib/zm/client/cos/cos.rb +11 -6
  44. data/lib/zm/client/cos/coses_builder.rb +1 -16
  45. data/lib/zm/client/cos/coses_collection.rb +6 -9
  46. data/lib/zm/client/distributionlist/distributionlist.rb +44 -6
  47. data/lib/zm/client/distributionlist/distributionlists_builder.rb +2 -17
  48. data/lib/zm/client/distributionlist/distributionlists_collection.rb +4 -11
  49. data/lib/zm/client/distributionlist/dls_membership_collection.rb +24 -0
  50. data/lib/zm/client/distributionlist.rb +1 -0
  51. data/lib/zm/client/document/document.rb +7 -9
  52. data/lib/zm/client/domain/domain.rb +11 -6
  53. data/lib/zm/client/domain/domain_accounts_collection.rb +13 -0
  54. data/lib/zm/client/domain/domains_builder.rb +1 -19
  55. data/lib/zm/client/domain/domains_collection.rb +7 -10
  56. data/lib/zm/client/domain.rb +1 -0
  57. data/lib/zm/client/folder/folder.rb +50 -124
  58. data/lib/zm/client/folder/folder_grant.rb +44 -22
  59. data/lib/zm/client/folder/folder_grant_jsns_builder.rb +43 -0
  60. data/lib/zm/client/folder/folder_grants_collection.rb +35 -0
  61. data/lib/zm/client/folder/folder_jsns_builder.rb +132 -0
  62. data/lib/zm/client/folder/folder_jsns_initializer.rb +49 -0
  63. data/lib/zm/client/folder/folder_retention_policies_collection.rb +40 -0
  64. data/lib/zm/client/folder/folder_retention_policy.rb +8 -30
  65. data/lib/zm/client/folder/folders_builder.rb +2 -2
  66. data/lib/zm/client/folder/folders_collection.rb +21 -19
  67. data/lib/zm/client/folder/folders_jsns_builder.rb +22 -0
  68. data/lib/zm/client/folder.rb +6 -0
  69. data/lib/zm/client/identity/identities_builder.rb +4 -15
  70. data/lib/zm/client/identity/identities_collection.rb +7 -13
  71. data/lib/zm/client/identity/identity.rb +19 -19
  72. data/lib/zm/client/message/message.rb +111 -21
  73. data/lib/zm/client/message/messages_builder.rb +1 -1
  74. data/lib/zm/client/message/messages_collection.rb +10 -92
  75. data/lib/zm/client/mountpoint/mountpoint.rb +15 -68
  76. data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +100 -0
  77. data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +33 -0
  78. data/lib/zm/client/mountpoint/mountpoints_builder.rb +1 -1
  79. data/lib/zm/client/mountpoint/mountpoints_collection.rb +14 -23
  80. data/lib/zm/client/mountpoint.rb +2 -0
  81. data/lib/zm/client/resource/resource.rb +5 -5
  82. data/lib/zm/client/resource/resources_builder.rb +1 -16
  83. data/lib/zm/client/resource/resources_collection.rb +5 -13
  84. data/lib/zm/client/search_folder/search_folder.rb +19 -39
  85. data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +86 -0
  86. data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +33 -0
  87. data/lib/zm/client/search_folder/search_folders_builder.rb +7 -11
  88. data/lib/zm/client/search_folder/search_folders_collection.rb +7 -15
  89. data/lib/zm/client/search_folder.rb +2 -0
  90. data/lib/zm/client/server/server.rb +7 -14
  91. data/lib/zm/client/server/server_accounts_collection.rb +19 -0
  92. data/lib/zm/client/server/servers_builder.rb +4 -16
  93. data/lib/zm/client/server/servers_collection.rb +5 -10
  94. data/lib/zm/client/server.rb +1 -0
  95. data/lib/zm/client/share/share.rb +2 -9
  96. data/lib/zm/client/share/shares_builder.rb +3 -12
  97. data/lib/zm/client/signature/signature.rb +17 -13
  98. data/lib/zm/client/signature/signature_jsns_builder.rb +5 -1
  99. data/lib/zm/client/signature/signature_jsns_initializer.rb +25 -0
  100. data/lib/zm/client/signature/signatures_builder.rb +7 -11
  101. data/lib/zm/client/signature/signatures_collection.rb +6 -14
  102. data/lib/zm/client/signature.rb +1 -0
  103. data/lib/zm/client/tag/tag.rb +27 -20
  104. data/lib/zm/client/tag/tag_jsns_builder.rb +55 -0
  105. data/lib/zm/client/tag/tag_jsns_initializer.rb +26 -0
  106. data/lib/zm/client/tag/tags_builder.rb +6 -9
  107. data/lib/zm/client/tag/tags_collection.rb +6 -12
  108. data/lib/zm/client/tag.rb +2 -0
  109. data/lib/zm/client/task/tasks_collection.rb +6 -90
  110. data/lib/zm/client/upload/upload.rb +1 -1
  111. data/lib/zm/client/version.rb +1 -1
  112. data/lib/zm/modules/common/dl_common.rb +3 -1
  113. data/lib/zm/modules/common/zimbra-attrs.json.bak +1 -0
  114. data/lib/zm/modules/zm_logger.rb +24 -0
  115. data/lib/zm/modules/zm_model.rb +41 -0
  116. data/test/accounts.rb +15 -1
  117. data/test/ace.rb +50 -0
  118. data/test/cluster.rb +41 -0
  119. data/test/cluster_zimbra_attributes.rb +38 -0
  120. data/test/folder.rb +125 -0
  121. data/test/folder_grant.rb +51 -0
  122. data/test/mountpoint.rb +49 -0
  123. data/test/retention_policies.rb +40 -0
  124. data/test/search_folder.rb +67 -0
  125. data/test/signature.rb +53 -0
  126. data/test/tag.rb +65 -0
  127. data/test/zimbra_attributes.rb +35 -0
  128. data/zm-ruby-client.gemspec +15 -10
  129. metadata +53 -26
  130. data/lib/zm/client/connector/soap_xml_builder.rb +0 -68
@@ -7,22 +7,7 @@ module Zm
7
7
  def initialize(parent, json)
8
8
  super(parent, json)
9
9
  @child_class = Resource
10
- end
11
-
12
- # def make
13
- # return [] if json_items.nil?
14
- #
15
- # json_items.map do |entry|
16
- # resource = Resource.new(@parent)
17
- # resource.init_from_json(entry)
18
- # resource
19
- # end
20
- # end
21
-
22
- private
23
-
24
- def json_items
25
- @json_items ||= @json[:Body][json_key][:calresource]
10
+ @json_item_key = :calresource
26
11
  end
27
12
  end
28
13
  end
@@ -3,34 +3,26 @@
3
3
  module Zm
4
4
  module Client
5
5
  # Collection Resources
6
- class ResourcesCollection < Base::ObjectsCollection
6
+ class ResourcesCollection < Base::AdminObjectsCollection
7
7
  def initialize(parent)
8
8
  @child_class = Resource
9
- @parent = parent
10
- reset_query_params
11
- end
12
-
13
- def ldap
14
- @apply_cos = 0
15
- self
9
+ @builder_class = ResourcesBuilder
10
+ @search_type = SearchType::RESOURCE
11
+ super(parent)
16
12
  end
17
13
 
18
14
  def find_by(hash)
19
15
  rep = sac.get_resource(hash.values.first, hash.keys.first, attrs_comma)
20
16
  entry = rep[:Body][:GetCalendarResourceResponse][:calresource].first
21
17
 
18
+ reset_query_params
22
19
  build_from_entry(entry)
23
20
  end
24
21
 
25
22
  private
26
23
 
27
- def build_response
28
- ResourcesBuilder.new(@parent, make_query).make
29
- end
30
-
31
24
  def reset_query_params
32
25
  super
33
- @search_type = SearchType::RESOURCE
34
26
  @attrs = SearchType::Attributes::RESOURCE.dup
35
27
  @all_servers = 1
36
28
  @refresh = 0
@@ -3,60 +3,40 @@
3
3
  module Zm
4
4
  module Client
5
5
  # class account SearchFolder
6
- class SearchFolder < Base::AccountObject
6
+ class SearchFolder < Base::FolderObject
7
+ include Zm::Model::AttributeChangeObserver
7
8
 
8
9
  INSTANCE_VARIABLE_KEYS = %i[id uuid deletable name absFolderPath l luuid color rgb rev ms webOfflineSyncDays activesyncdisabled query sortBy types]
9
10
 
10
- attr_accessor *INSTANCE_VARIABLE_KEYS
11
+ # attr_accessor *INSTANCE_VARIABLE_KEYS
12
+ attr_reader :id, :absFolderPath, :types
11
13
 
12
- def concat
13
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
14
+ define_changed_attributes :name, :color, :rgb, :l, :query, :sortBy
15
+
16
+ def initialize(parent)
17
+ super(parent)
18
+ @types = 'messages'
14
19
  end
15
20
 
16
- def init_from_json(json)
17
- INSTANCE_VARIABLE_KEYS.each do |key|
18
- var_name = "@#{key}"
19
- instance_variable_set(var_name, json[key])
20
- end
21
+ def all_instance_variable_keys
22
+ INSTANCE_VARIABLE_KEYS
21
23
  end
22
24
 
23
25
  def create!
24
- rep = @parent.sacc.create_search_folder(@parent.token, name, query, types, l, color, sortBy)
25
- init_from_json(rep[:Body][:CreateSearchFolderResponse][:search].first)
26
+ rep = @parent.sacc.create_search_folder(@parent.token, jsns_builder.to_jsns)
27
+ json = rep[:Body][:CreateSearchFolderResponse][:search].first
28
+ SearchFolderJsnsInitializer.update(self, json)
26
29
  end
27
30
 
28
31
  def modify!
29
- @parent.sacc.modify_search_folder(@parent.token, id, query, types)
30
- @parent.sacc.folder_action(@parent.token, :update, id, build_update_options)
31
- end
32
-
33
- def query!(new_query)
34
- @parent.sacc.modify_search_folder(@parent.token, id, new_query, types)
35
- instance_variable_set("@query", new_query)
36
- end
37
-
38
- def color!(new_color)
39
- key = new_color.to_i.zero? ? :rgb : :color
40
- options = {}
41
- options[key] = new_color
42
- @parent.sacc.folder_action(@parent.token, :color, @id, options)
43
- instance_variable_set("@#{key}", new_color)
44
- end
45
-
46
- def build_update_options
47
- {
48
- name: @name,
49
- color: @color,
50
- rgb: @rgb
51
- }.delete_if { |_, v| v.nil? }
32
+ @parent.sacc.modify_search_folder(@parent.token, jsns_builder.to_modify)
33
+ super
52
34
  end
53
35
 
54
- def delete!
55
- @parent.sacc.folder_action(@parent.token, :delete, id)
56
- end
36
+ private
57
37
 
58
- def rename!(new_name)
59
- # todo
38
+ def jsns_builder
39
+ @jsns_builder ||= SearchFolderJsnsBuilder.new(self)
60
40
  end
61
41
  end
62
42
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for account search folder jsns builder
6
+ class SearchFolderJsnsBuilder
7
+
8
+ def initialize(search_folder)
9
+ @item = search_folder
10
+ end
11
+
12
+ def to_jsns
13
+ search = {
14
+ name: @item.name,
15
+ query: @item.query,
16
+ types: @item.types,
17
+ l: @item.l,
18
+ color: @item.color,
19
+ sortBy: @item.sortBy
20
+ }.delete_if { |_, v| v.nil? }
21
+
22
+ { search: search }
23
+ end
24
+
25
+ alias to_create to_jsns
26
+
27
+ def to_modify
28
+ search = {
29
+ id: @item.id,
30
+ query: @item.query,
31
+ types: @item.types
32
+ }.reject { |_, v| v.nil? }
33
+
34
+ { search: search }
35
+ end
36
+
37
+ def to_update
38
+ action = {
39
+ op: :update,
40
+ id: @item.id,
41
+ name: @item.name,
42
+ color: @item.color,
43
+ rgb: @item.rgb
44
+ }.reject { |_, v| v.nil? }
45
+
46
+ { action: action }
47
+ end
48
+
49
+ def to_rename
50
+ action = {
51
+ op: :rename,
52
+ id: @item.id,
53
+ name: @item.name
54
+ }
55
+
56
+ { action: action }
57
+ end
58
+
59
+ def to_move
60
+ action = {
61
+ op: :move,
62
+ id: @item.id,
63
+ l: @item.l
64
+ }
65
+
66
+ { action: action }
67
+ end
68
+
69
+ def to_color
70
+ action = {
71
+ op: :color,
72
+ id: @item.id
73
+ }
74
+
75
+ action[:rgb] = @item.rgb if @item.rgb_changed?
76
+ action[:color] = @item.color if @item.color_changed?
77
+
78
+ { action: action }
79
+ end
80
+
81
+ def to_delete
82
+ { action: { op: :delete, id: @item.id } }
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account search folder
6
+ class SearchFolderJsnsInitializer
7
+ class << self
8
+ def create(parent, json)
9
+ item = SearchFolder.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
@@ -2,23 +2,19 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # class factory [folders]
5
+ # class factory [Search folders]
6
6
  class SearchFoldersBuilder < Base::ObjectsBuilder
7
7
  def initialize(parent, json)
8
- @parent = parent
9
- @json = json
8
+ super(parent, json)
9
+ @child_class = SearchFolder
10
+ @json_item_key = :search
10
11
  end
11
12
 
12
13
  def make
13
- root = @json[:Body][:GetSearchFolderResponse][:search]
14
- return [] if root.nil?
14
+ return [] if json_items.nil?
15
15
 
16
- root = [root] unless root.is_a?(Array)
17
-
18
- root.map do |s|
19
- f = SearchFolder.new(@parent)
20
- f.init_from_json(s)
21
- f
16
+ json_items.map do |entry|
17
+ SearchFolderJsnsInitializer.create(@parent, entry)
22
18
  end
23
19
  end
24
20
  end
@@ -2,26 +2,18 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # collection of folders
6
- class SearchFoldersCollection < Base::ObjectsCollection
7
- METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
-
5
+ # collection of search folders
6
+ class SearchFoldersCollection < Base::AccountObjectsCollection
9
7
  def initialize(parent)
10
- @parent = parent
11
- end
12
-
13
- def new
14
- folder = SearchFolder.new(@parent)
15
- yield(folder) if block_given?
16
- folder
8
+ @child_class = SearchFolder
9
+ @builder_class = SearchFoldersBuilder
10
+ super(parent)
17
11
  end
18
12
 
19
13
  private
20
14
 
21
- def build_response
22
- rep = @parent.sacc.get_all_search_folders(@parent.token)
23
- fb = SearchFoldersBuilder.new @parent, rep
24
- fb.make
15
+ def make_query
16
+ @parent.sacc.get_all_search_folders(@parent.token)
25
17
  end
26
18
  end
27
19
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zm/client/search_folder/search_folder'
4
+ require 'zm/client/search_folder/search_folder_jsns_builder'
5
+ require 'zm/client/search_folder/search_folder_jsns_initializer'
4
6
  require 'zm/client/search_folder/search_folders_builder'
5
7
  require 'zm/client/search_folder/search_folders_collection'
@@ -481,6 +481,10 @@ module Zm
481
481
  attr_accessor *INSTANCE_VARIABLE_KEYS
482
482
  attr_accessor :name, :id
483
483
 
484
+ def all_instance_variable_keys
485
+ INSTANCE_VARIABLE_KEYS
486
+ end
487
+
484
488
  def mta_queues
485
489
  @mta_queues ||= mta_queues!
486
490
  end
@@ -497,20 +501,9 @@ module Zm
497
501
  BackupsCollection.new self
498
502
  end
499
503
 
500
- # def accounts
501
- # @accounts ||= AccountsCollection.new @soap_admin_connector
502
- # end
503
-
504
- # def quotas
505
- # # todo
506
- # rep = @soap_admin_connector.get_quota_usage(name, 1)
507
- # AccountsBuilder.new(@soap_admin_connector, rep).make
508
- # end
509
-
510
- # def quotas!
511
- # @accounts = quotas
512
- # # todo il faudrait merger quotas dans @accounts
513
- # end
504
+ def accounts
505
+ @accounts ||= ServerAccountsCollection.new(self)
506
+ end
514
507
  end
515
508
  end
516
509
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # Collection Accounts from server
6
+ class ServerAccountsCollection < AccountsCollection
7
+ def initialize(parent)
8
+ @target_server_id = parent.id
9
+ super(parent)
10
+ end
11
+
12
+ private
13
+
14
+ def ldap_filter
15
+ @ldap_filter ||= LdapFilter.new("(zimbraMailHost=#{@parent.name})")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -4,22 +4,10 @@ module Zm
4
4
  module Client
5
5
  # class factory [servers]
6
6
  class ServersBuilder < Base::ObjectsBuilder
7
- def make
8
- return [] if json_items.nil?
9
-
10
- servers = json_items.map do |entry|
11
- server = Server.new(@parent)
12
- server.init_from_json(entry)
13
- server
14
- end
15
-
16
- servers
17
- end
18
-
19
- private
20
-
21
- def json_items
22
- @json_items ||= @json[:Body][json_key][:server]
7
+ def initialize(parent, json)
8
+ super(parent, json)
9
+ @child_class = Server
10
+ @json_item_key = :server
23
11
  end
24
12
  end
25
13
  end
@@ -3,19 +3,18 @@
3
3
  module Zm
4
4
  module Client
5
5
  # Collection servers
6
- class ServersCollection < Base::ObjectsCollection
6
+ class ServersCollection < Base::AdminObjectsCollection
7
7
  def initialize(parent)
8
- @parent = parent
9
- # @service = ServerServices::MAILBOX
8
+ @child_class = Server
9
+ @builder_class = ServersBuilder
10
10
  @service = nil
11
+ super(parent)
11
12
  end
12
13
 
13
14
  def find_by(hash)
14
15
  rep = sac.get_server(hash.values.first, hash.keys.first)
15
16
  entry = rep[:Body][:GetServerResponse][:server].first
16
- server = Server.new(@parent)
17
- server.init_from_json(entry)
18
- server
17
+ build_from_entry(entry)
19
18
  end
20
19
 
21
20
  def where(service)
@@ -25,10 +24,6 @@ module Zm
25
24
 
26
25
  private
27
26
 
28
- def build_response
29
- ServersBuilder.new(@parent, make_query).make
30
- end
31
-
32
27
  def make_query
33
28
  sac.get_all_servers(@service)
34
29
  end
@@ -3,3 +3,4 @@
3
3
  require 'zm/client/server/server'
4
4
  require 'zm/client/server/servers_builder'
5
5
  require 'zm/client/server/servers_collection'
6
+ require 'zm/client/server/server_accounts_collection'
@@ -17,8 +17,8 @@ module Zm
17
17
  yield(self) if block_given?
18
18
  end
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 create!
@@ -48,13 +48,6 @@ module Zm
48
48
  owner_name = (@ownerName || @ownerEmail).tr('/', '-')
49
49
  "#{folder_name} (#{owner_name})"
50
50
  end
51
-
52
- def init_from_json(json)
53
- INSTANCE_VARIABLE_KEYS.each do |key|
54
- var_name = "@#{key}"
55
- instance_variable_set(var_name, json[key])
56
- end
57
- end
58
51
  end
59
52
  end
60
53
  end
@@ -5,18 +5,9 @@ module Zm
5
5
  # class factory [shares]
6
6
  class ShareBuilder < Base::ObjectsBuilder
7
7
  def initialize(parent, json)
8
- @parent = parent
9
- @json = json
10
- end
11
-
12
- def make
13
- root = @json[:Body][:GetShareInfoResponse][:share]
14
- return [] if root.nil?
15
-
16
- root = [root] unless root.is_a?(Array)
17
- root.map do |s|
18
- Share.new(@parent, s)
19
- end
8
+ super(parent, json)
9
+ @child_class = Share
10
+ @json_item_key = :share
20
11
  end
21
12
  end
22
13
  end
@@ -4,37 +4,35 @@ module Zm
4
4
  module Client
5
5
  # class account signature
6
6
  class Signature < Base::AccountObject
7
+ include Zm::Model::AttributeChangeObserver
8
+
7
9
  TYPE_TXT = 'text/plain'
8
10
  TYPE_HTML = 'text/html'
9
11
 
10
12
  INSTANCE_VARIABLE_KEYS = %i[id name txt html]
11
13
 
12
- attr_accessor *INSTANCE_VARIABLE_KEYS
14
+ attr_reader :id
13
15
 
14
- def concat
15
- INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
16
- end
16
+ define_changed_attributes :name, :txt, :html
17
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)
18
+ def all_instance_variable_keys
19
+ INSTANCE_VARIABLE_KEYS
25
20
  end
26
21
 
27
22
  def create!
28
23
  rep = @parent.sacc.create_signature(@parent.token, as_jsns)
29
24
  @id = rep[:Body][:CreateSignatureResponse][:signature].first[:id]
25
+ super
30
26
  end
31
27
 
32
28
  def modify!
33
29
  @parent.sacc.modify_signature(@parent.token, as_jsns)
30
+ super
34
31
  end
35
32
 
36
33
  def delete!
37
- @parent.sacc.delete_signature(@parent.token, id)
34
+ @parent.sacc.delete_signature(@parent.token, jsns_builder.to_delete)
35
+ super
38
36
  end
39
37
 
40
38
  def type
@@ -54,8 +52,14 @@ module Zm
54
52
  html || txt
55
53
  end
56
54
 
55
+ private
56
+
57
+ def jsns_builder
58
+ @jsns_builder ||= SignatureJsnsBuilder.new(self)
59
+ end
60
+
57
61
  def as_jsns
58
- SignatureJsnsBuilder.new(self).to_jsns
62
+ jsns_builder.to_jsns
59
63
  end
60
64
  end
61
65
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # class for account signature
5
+ # class for account signature jsns builder
6
6
  class SignatureJsnsBuilder
7
7
 
8
8
  def initialize(signature)
@@ -24,6 +24,10 @@ module Zm
24
24
 
25
25
  jsns
26
26
  end
27
+
28
+ def to_delete
29
+ { signature: { id: @signature.id } }
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zm
4
+ module Client
5
+ # class for initialize account signature
6
+ class SignatureJsnsInitializer < Base::BaseJsnsInitializer
7
+
8
+ def initialize(parent, json)
9
+ super(parent, json)
10
+ @child_class = Signature
11
+ end
12
+
13
+ def create
14
+ super
15
+
16
+ @json[:content].each do |c|
17
+ @item.instance_variable_set(:@txt, c[:_content]) if c[:type] == Signature::TYPE_TXT
18
+ @item.instance_variable_set(:@html, c[:_content]) if c[:type] == Signature::TYPE_HTML
19
+ end if @json[:content].is_a?(Array)
20
+
21
+ @item
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,23 +2,19 @@
2
2
 
3
3
  module Zm
4
4
  module Client
5
- # class factory [folders]
5
+ # class factory [signatures]
6
6
  class SignaturesBuilder < Base::ObjectsBuilder
7
7
  def initialize(parent, json)
8
- @parent = parent
9
- @json = json
8
+ super(parent, json)
9
+ @child_class = Signature
10
+ @json_item_key = :signature
10
11
  end
11
12
 
12
13
  def make
13
- root = @json[:Body][:GetSignaturesResponse][:signature]
14
- return [] if root.nil?
14
+ return [] if json_items.nil?
15
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
16
+ json_items.map do |entry|
17
+ SignatureJsnsInitializer.new(@parent, entry).create
22
18
  end
23
19
  end
24
20
  end
@@ -3,25 +3,17 @@
3
3
  module Zm
4
4
  module Client
5
5
  # collection of signatures
6
- class SignaturesCollection < Base::ObjectsCollection
7
- METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
8
-
6
+ class SignaturesCollection < Base::AccountObjectsCollection
9
7
  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
8
+ @child_class = Signature
9
+ @builder_class = SignaturesBuilder
10
+ super(parent)
17
11
  end
18
12
 
19
13
  private
20
14
 
21
- def build_response
22
- rep = @parent.sacc.get_signatures(@parent.token)
23
- sb = SignaturesBuilder.new @parent, rep
24
- sb.make
15
+ def make_query
16
+ @parent.sacc.get_signatures(@parent.token)
25
17
  end
26
18
  end
27
19
  end