Class: Zm::Client::CosJsnsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/cos/cos_jsns_builder.rb

Overview

class for cos jsns builder

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ CosJsnsBuilder

Returns a new instance of CosJsnsBuilder.



7
8
9
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 7

def initialize(item)
  @item = item
end

Instance Method Details

#attrs_only_set_hObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 80

def attrs_only_set_h
  selected_attrs = @item.attrs_write.map { |a| Utils.arrow_name_sym(a) }
  attrs_only_set = @item.instance_variables & selected_attrs

  arr = attrs_only_set.map do |name|
    n = name.to_s[1..]
    values = @item.instance_variable_get(name)
    values = [values] unless values.is_a?(Array)
    [n, values]
  end

  Hash[arr]
end

#to_copy(new_name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 57

def to_copy(new_name)
  soap_request = SoapElement.admin(SoapAdminConstants::COPY_COS_REQUEST)
  node_name = SoapElement.create(SoapConstants::NAME).add_content(new_name)

  if @item.id
    node_cos = SoapElement.create(SoapConstants::COS).add_attribute(SoapConstants::BY, SoapConstants::ID).add_content(@item.id)
  elsif @item.name
    node_cos = SoapElement.create(SoapConstants::COS).add_attribute(SoapConstants::BY, SoapConstants::NAME).add_content(@item.name)
  else
    raise Zm::Client::ZmError, 'id or name attributes are required to clone cos'
  end

  soap_request.add_node(node_name)
  soap_request.add_node(node_cos)
  soap_request
end

#to_createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 11

def to_create
  soap_request = SoapElement.admin(SoapAdminConstants::CREATE_COS_REQUEST)
  node_cos = SoapElement.create(SoapConstants::NAME).add_content(@item.name)
  soap_request.add_node(node_cos)

  attrs_only_set_h.each do |key, values|
    values.each do |value|
      node_attr = SoapElement.create(SoapConstants::A).add_attribute(SoapConstants::N, key).add_content(value)
      soap_request.add_node(node_attr)
    end
  end

  soap_request
end

#to_deleteObject



74
75
76
77
78
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 74

def to_delete
  SoapElement.admin(SoapAdminConstants::DELETE_COS_REQUEST).add_node(
    SoapElement.create(SoapConstants::ID).add_content(@item.id)
  )
end

#to_patch(hash) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 41

def to_patch(hash)
  soap_request = SoapElement.admin(SoapAdminConstants::MODIFY_COS_REQUEST)
  node_cos = SoapElement.create(SoapConstants::ID).add_content(@item.id)
  soap_request.add_node(node_cos)

  hash.each do |key, values|
    values = [values] unless values.is_a?(Array)
    values.each do |value|
      node_attr = SoapElement.create(SoapConstants::A).add_attribute(SoapConstants::N, key).add_content(value)
      soap_request.add_node(node_attr)
    end
  end

  soap_request
end

#to_updateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zm/client/cos/cos_jsns_builder.rb', line 26

def to_update
  soap_request = SoapElement.admin(SoapAdminConstants::MODIFY_COS_REQUEST)
  node_cos = SoapElement.create(SoapConstants::ID).add_content(@item.id)
  soap_request.add_node(node_cos)

  attrs_only_set_h.each do |key, values|
    values.each do |value|
      node_attr = SoapElement.create(SoapConstants::A).add_attribute(SoapConstants::N, key).add_content(value)
      soap_request.add_node(node_attr)
    end
  end

  soap_request
end