Class: Zm::Client::Resource
Overview
objectClass: zimbraCalendarResource
Instance Attribute Summary collapse
Attributes inherited from Base::Object
#grantee_type, #id, #name, #parent, #token
Instance Method Summary
collapse
#init_from_json, #soap_account_connector, #soap_admin_connector, #to_h
#arrow_name, #clone, #concat, #convert_json_string_value, #disable_builder, #enable_builder, #init_from_json, #instance_variables_array, #instance_variables_hash, #logger, #recorded?, #save!, #to_s, #use_builder?
Constructor Details
#initialize(parent) ⇒ Resource
Returns a new instance of Resource.
12
13
14
15
16
|
# File 'lib/zm/client/resource/resource.rb', line 12
def initialize(parent)
extend(ResourceCommon)
super(parent)
@grantee_type = 'usr'.freeze
end
|
Instance Attribute Details
#home_url ⇒ Object
attr_reader :name, :id, :domainkey, :used, :token
10
11
12
|
# File 'lib/zm/client/resource/resource.rb', line 10
def home_url
@home_url
end
|
Instance Method Details
#account_login_password ⇒ Object
53
54
55
56
57
|
# File 'lib/zm/client/resource/resource.rb', line 53
def account_login_password
raise ZmError, 'password is required to login !' if password.nil?
@token = sacc.auth_password(@name, @password)
end
|
#account_login_preauth ⇒ Object
46
47
48
49
50
51
|
# File 'lib/zm/client/resource/resource.rb', line 46
def account_login_preauth
domain_key
raise ZmError, 'domain key is required to login !' if @domainkey.nil?
@token = sacc.auth_preauth(@name, @domainkey)
end
|
#admin_login ⇒ Object
59
60
61
|
# File 'lib/zm/client/resource/resource.rb', line 59
def admin_login
@token = sac.delegate_auth(@name)
end
|
#all_instance_variable_keys ⇒ Object
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
24
25
26
|
# File 'lib/zm/client/resource/resource.rb', line 24
def all_instance_variable_keys
ResourceCommon::ALL_ATTRS
end
|
#create! ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/zm/client/resource/resource.rb', line 104
def create!
rep = sac.create_resource(
@name,
@password,
instance_variables_array(attrs_write)
)
@id = rep[:Body][:CreateCalendarResourceResponse][:calresource].first[:id]
end
|
#delete! ⇒ Object
88
89
90
|
# File 'lib/zm/client/resource/resource.rb', line 88
def delete!
sac.delete_resource(@id)
end
|
#domain_key ⇒ Object
67
68
69
|
# File 'lib/zm/client/resource/resource.rb', line 67
def domain_key
@domainkey ||= @parent.domain_key(domain_name)
end
|
#domain_name ⇒ Object
63
64
65
|
# File 'lib/zm/client/resource/resource.rb', line 63
def domain_name
@name.split('@').last
end
|
#folders ⇒ Object
84
85
86
|
# File 'lib/zm/client/resource/resource.rb', line 84
def folders
@folders ||= FoldersCollection.new(self)
end
|
#infos ⇒ Object
71
72
73
|
# File 'lib/zm/client/resource/resource.rb', line 71
def infos
@infos ||= read_infos
end
|
#logged? ⇒ Boolean
34
35
36
|
# File 'lib/zm/client/resource/resource.rb', line 34
def logged?
!@token.nil?
end
|
#login ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/zm/client/resource/resource.rb', line 38
def login
if @parent.logged?
admin_login
else
account_login
end
end
|
#modify! ⇒ Object
97
98
99
100
101
102
|
# File 'lib/zm/client/resource/resource.rb', line 97
def modify!
attrs_to_modify = instance_variables_array(attrs_write)
return if attrs_to_modify.empty?
sac.modify_resource(@id, attrs_to_modify)
end
|
#read_infos ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/zm/client/resource/resource.rb', line 75
def read_infos
@infos = sacc.get_info(@token)[:Body][:GetInfoResponse]
@id = @infos[:id]
@used = @infos[:used]
@public_url = @infos[:publicURL]
@zimbraCOSId = @infos[:cos][:id]
@home_url = @infos[:rest]
end
|
#rest_account_connector ⇒ Object
Also known as:
rac
28
29
30
|
# File 'lib/zm/client/resource/resource.rb', line 28
def rest_account_connector
@rest_account_connector ||= RestAccountConnector.new
end
|
#update!(hash) ⇒ Object
92
93
94
95
|
# File 'lib/zm/client/resource/resource.rb', line 92
def update!(hash)
sac.modify_resource(@id, hash)
hash.each { |k, v| send "#{k}=", v }
end
|
#uploader ⇒ Object
113
114
115
|
# File 'lib/zm/client/resource/resource.rb', line 113
def uploader
@uploader ||= Upload.new(self)
end
|