Class: Zm::Client::Domain

Inherits:
Base::AdminObject show all
Defined in:
lib/zm/client/domain/domain.rb

Overview

objectClass: zimbraDomain

Constant Summary collapse

INSTANCE_VARIABLE_KEYS =
%i[name description zimbraDomainName zimbraDomainStatus zimbraId zimbraDomainType
zimbraDomainDefaultCOSId zimbraGalAccountId zimbraPreAuthKey zimbraGalLdapBindDn zimbraGalLdapBindPassword
zimbraGalLdapFilter zimbraGalLdapSearchBase zimbraGalLdapURL zimbraGalMode zimbraMailTransport
zimbraPublicServiceHostname zimbraPublicServiceProtocol]

Instance Attribute Summary

Attributes inherited from Base::Object

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

Instance Method Summary collapse

Methods inherited from Base::AdminObject

#soap_account_connector, #soap_admin_connector, #to_h

Methods inherited from Base::Object

#arrow_name, #clone, #concat, #convert_json_string_value, #disable_builder, #enable_builder, #instance_variables_array, #instance_variables_hash, #logger, #recorded?, #save!, #to_s, #use_builder?

Constructor Details

#initialize(parent) ⇒ Domain

Returns a new instance of Domain.



14
15
16
17
# File 'lib/zm/client/domain/domain.rb', line 14

def initialize(parent)
  super(parent)
  @grantee_type = 'dom'.freeze
end

Instance Method Details

#accountsObject



54
55
56
# File 'lib/zm/client/domain/domain.rb', line 54

def accounts
  @accounts ||= DomainAccountsCollection.new(self)
end

#all_instance_variable_keysObject

def to_h

hashmap = Hash[all_instance_variable_keys.map { |key| [key, instance_variable_get(arrow_name(key))] }]
hashmap.delete_if { |_, v| v.nil? }
hashmap

end



25
26
27
# File 'lib/zm/client/domain/domain.rb', line 25

def all_instance_variable_keys
  INSTANCE_VARIABLE_KEYS
end

#create!Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/zm/client/domain/domain.rb', line 29

def create!
  attrs_write = INSTANCE_VARIABLE_KEYS.dup
  attrs_write.delete(:name)

  rep = sac.create_domain(
    @name,
    instance_variables_array(attrs_write)
  )
  @id = rep[:Body][:CreateDomainResponse][:domain].first[:id]
end

#delete!Object



58
59
60
# File 'lib/zm/client/domain/domain.rb', line 58

def delete!
  sac.generic_delete(:DeleteDomainRequest, id)
end

#init_from_json(json) ⇒ Object

def account_quotas(server_id)

rep = sac.get_quota_usage(name, nil, nil, nil, nil, nil, nil, server_id)
AccountsBuilder.new(@parent, rep).make

end



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/zm/client/domain/domain.rb', line 67

def init_from_json(json)
  super(json)
  return unless json[:a].is_a? Array

  n_key = :n
  c_key = :_content
  at_key = '@'

  attrs = {}

  # TODO: definir ici le typage fort des attributs pour ne pas avoir
  # a faire des cases sur les class des attributs dans le code.

  json[:a].each do |a|
    k = "#{at_key}#{a[n_key]}".to_sym
    v = a[c_key]
    if !attrs[k].nil?
      attrs[k] = [attrs[k]] unless attrs[k].is_a?(Array)
      attrs[k].push(v)
    else
      attrs[k] = v
    end
  end

  attrs.each { |k, v| instance_variable_set(k, v) }
end

#update!(hash) ⇒ Object



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

def update!(hash)
  sac.modify_domain(@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