Class: Zm::Client::AccountObject::TagsCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/tag/account_object_tags_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ TagsCollection



7
8
9
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 7

def initialize(parent)
  @parent = parent
end

Instance Method Details

#add!(*new_tags) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 19

def add!(*new_tags)
  new_tags.flatten!
  Utils.map_format(new_tags, String, :name)
  return false if new_tags.delete_if { |tag_name| all.include?(tag_name) }.empty?

  new_tags.each do |tag_name|
    attrs = {
      op: :tag,
      id: @parent.id,
      tn: tag_name
    }

    do_action(attrs)
  end

  @parent.tn += new_tags
  all!
end

#allObject



11
12
13
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 11

def all
  @all || all!
end

#all!Object



15
16
17
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 15

def all!
  @all = @parent.tn.split(',')
end

#do_action(attrs) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 57

def do_action(attrs)
  soap_request = SoapElement.mail(SoapMailConstants::ITEM_ACTION_REQUEST)
  node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
  soap_request.add_node(node_action)

  @parent.parent.sacc.invoke(soap_request)
end

#remove!(*tag_names) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zm/client/tag/account_object_tags_collection.rb', line 38

def remove!(*tag_names)
  tag_names.flatten!
  Utils.map_format(tag_names, String, :name)
  return false if tag_names.delete_if { |tag_name| !all.include?(tag_name) }.empty?

  tag_names.each do |tag_name|
    attrs = {
      op: '!tag',
      id: @parent.id,
      tn: tag_name
    }

    do_action(attrs)
  end

  @parent.tn -= tag_names
  all!
end