Class: Zm::Client::AccountJsnsBuilder
- Inherits:
-
Object
- Object
- Zm::Client::AccountJsnsBuilder
- Defined in:
- lib/zm/client/account/account_jsns_builder.rb
Overview
class for account jsns builder
Instance Method Summary collapse
- #add_soap_request_node(soap_request, key, value) ⇒ Object
- #add_soap_request_nodes(soap_request) ⇒ Object
- #attrs_only_set_h ⇒ Object
-
#initialize(item) ⇒ AccountJsnsBuilder
constructor
A new instance of AccountJsnsBuilder.
- #to_create ⇒ Object
- #to_delete ⇒ Object
- #to_patch(hash) ⇒ Object
- #to_rename(new_name) ⇒ Object
- #to_update ⇒ Object
Constructor Details
#initialize(item) ⇒ AccountJsnsBuilder
Returns a new instance of AccountJsnsBuilder.
7 8 9 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 7 def initialize(item) @item = item end |
Instance Method Details
#add_soap_request_node(soap_request, key, value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 34 def add_soap_request_node(soap_request, key, value) node_attr = SoapElement.create(SoapConstants::A) .add_attribute(SoapConstants::N, key) .add_content(value) soap_request.add_node(node_attr) end |
#add_soap_request_nodes(soap_request) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 26 def add_soap_request_nodes(soap_request) attrs_only_set_h.each do |key, values| values.each do |value| add_soap_request_node(soap_request, key, value) end end end |
#attrs_only_set_h ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 74 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 arr.to_h end |
#to_create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 11 def to_create req = { name: @item.name, password: @item.password } req.compact! soap_request = SoapElement.admin(SoapAdminConstants::CREATE_ACCOUNT_REQUEST) .add_attributes(req) add_soap_request_nodes(soap_request) soap_request end |
#to_delete ⇒ Object
64 65 66 67 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 64 def to_delete SoapElement.admin(SoapAdminConstants::DELETE_ACCOUNT_REQUEST) .add_attribute(SoapConstants::ID, @item.id) end |
#to_patch(hash) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 50 def to_patch(hash) soap_request = SoapElement.admin(SoapAdminConstants::MODIFY_ACCOUNT_REQUEST) .add_attribute(SoapConstants::ID, @item.id) hash.each do |key, values| values = [values] unless values.is_a?(Array) values.each do |value| add_soap_request_node(soap_request, key, value) end end soap_request end |
#to_rename(new_name) ⇒ Object
69 70 71 72 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 69 def to_rename(new_name) SoapElement.admin(SoapAdminConstants::RENAME_ACCOUNT_REQUEST) .add_attributes({ id: @item.id, newName: new_name }) end |
#to_update ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/zm/client/account/account_jsns_builder.rb', line 41 def to_update soap_request = SoapElement.admin(SoapAdminConstants::MODIFY_ACCOUNT_REQUEST) .add_attribute(SoapConstants::ID, @item.id) add_soap_request_nodes(soap_request) soap_request end |