Class: Zm::Client::Identity

Inherits:
Base::AccountObject show all
Defined in:
lib/zm/client/identity/identity.rb

Overview

class account identity

Constant Summary collapse

INSTANCE_VARIABLE_KEYS =
%i[id name zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
zimbraPrefWhenInFoldersEnabled]
ATTRS_WRITE =
%i[zimbraPrefIdentityName zimbraPrefFromDisplay zimbraPrefFromAddress
zimbraPrefFromAddressType zimbraPrefReplyToEnabled zimbraPrefReplyToDisplay zimbraPrefReplyToAddress
zimbraPrefDefaultSignatureId zimbraPrefForwardReplySignatureId zimbraPrefWhenSentToEnabled
zimbraPrefWhenInFoldersEnabled]

Instance Attribute Summary

Attributes inherited from Base::Object

#grantee_type, #id, #name, #parent, #token

Instance Method Summary collapse

Methods inherited from Base::AccountObject

#soap_account_connector

Methods inherited from Base::Object

#arrow_name, #convert_json_string_value, #initialize, #instance_variables_array, #instance_variables_hash, #recorded?, #save!, #to_s

Constructor Details

This class inherits a constructor from Zm::Client::Base::Object

Instance Method Details

#clone {|new_identity| ... } ⇒ Object

Yields:

  • (new_identity)


64
65
66
67
68
69
70
71
72
# File 'lib/zm/client/identity/identity.rb', line 64

def clone
  new_identity = super do |obj|
    [:@zimbraPrefDefaultSignatureId, :@zimbraPrefForwardReplySignatureId].each do |arrow_key|
      obj.remove_instance_variable(arrow_key) if obj.instance_variable_get(arrow_key)
    end
  end
  yield(new_identity) if block_given?
  new_identity
end

#concatObject



20
21
22
# File 'lib/zm/client/identity/identity.rb', line 20

def concat
  INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
end

#create!Object



34
35
36
37
# File 'lib/zm/client/identity/identity.rb', line 34

def create!
  rep = @parent.sacc.create_identity(@parent.token, name, instance_variables_array(ATTRS_WRITE))
  init_from_json(rep[:Body][:CreateIdentityResponse][:identity].first)
end

#delete!Object



57
58
59
# File 'lib/zm/client/identity/identity.rb', line 57

def delete!
  @parent.sacc.delete_identity(@parent.token, id)
end

#init_from_json(json) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/zm/client/identity/identity.rb', line 24

def init_from_json(json)
  super(json)
  INSTANCE_VARIABLE_KEYS.each do |key|
    value = json[:_attrs][key]
    next if value.nil?

    instance_variable_set(arrow_name(key), value)
  end
end

#modify!Object



53
54
55
# File 'lib/zm/client/identity/identity.rb', line 53

def modify!
  @parent.sacc.modify_identity(@parent.token, id, instance_variables_array(ATTRS_WRITE))
end

#rename!(new_name) ⇒ Object



61
62
# File 'lib/zm/client/identity/identity.rb', line 61

def rename!(new_name)
end

#update!(hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zm/client/identity/identity.rb', line 39

def update!(hash)
  @parent.sacc.modify_identity(@parent.token, id, hash)

  hash.each do |k, v|
    arrow_attr_sym = "@#{k}".to_sym

    if v.respond_to?(:empty?) && v.empty?
      self.remove_instance_variable(arrow_attr_sym) if self.instance_variable_get(arrow_attr_sym)
    else
      self.instance_variable_set(arrow_attr_sym, v)
    end
  end
end