Module: ZimbraRestApi::ZimbraObject::InstanceMethods

Defined in:
lib/zimbra_rest_api/zimbra_object.rb

Instance Method Summary collapse

Instance Method Details

#acl_factory(attrs = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 36

def acl_factory(attrs = {})
  fail ArgumentError.new('Hash expected') unless attrs.is_a?Hash
  return if attrs.empty?
  attrs['grantee_class'] = Zimbra::ACL::TARGET_MAPPINGS[attrs['grantee_class']]
  Zimbra::ACL.new(grantee_name: attrs['grantee_name'],
                        grantee_class: attrs['grantee_class'],
                        name: attrs['name']
                        )
end

#add_grant(grant) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 46

def add_grant(grant)
  acl = acl_factory(grant)
  if Zimbra::Directory::add_grant(self.zmobject, acl)
    self.class.find(self.id)
  else
    fail ZimbraRestApi::NotFound, "ZimbraRestApi::NotFound Grant #{acl.grantee_name}"
  end
end

#deleteObject



32
33
34
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 32

def delete
  zmobject.delete
end

#from_json!(string) ⇒ Object



20
21
22
23
24
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 20

def from_json! string
  JSON.load(string).each do |var, val|
      self.instance_variable_set var, val
  end
end

#revoke_grant(grant) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 55

def revoke_grant(grant)
  acl = acl_factory(grant)
  if Zimbra::Directory::revoke_grant(self.zmobject, acl)
    return self.class.find(self.id)
  else
    fail ZimbraRestApi::NotFound, "ZimbraRestApi::NotFound Grant #{acl.grantee_name}"
  end
end

#to_json(arg = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 11

def to_json(arg = nil)
  hash = {}
  self.instance_variables.each do |var|
    name = var.to_s.gsub(/@/, '')
    hash[name] = self.instance_variable_get var
  end
  hash.to_json
end

#update_attributes(attributes) ⇒ Object



26
27
28
29
30
# File 'lib/zimbra_rest_api/zimbra_object.rb', line 26

def update_attributes(attributes)
  fail ArgumentError.new('Hash expected') unless attributes.is_a?Hash
  result = zmobject.modify(attributes)
  self.class.new(result) if result
end