Commit 96008369 authored by Patricio Bruna's avatar Patricio Bruna

Its posible to get a Resource using the zimbraId or the name

parent 0b89d61d
This diff is collapsed.
This diff is collapsed.
......@@ -141,7 +141,7 @@ class ZimbraAdminApi {
return callback(null, response_array);
}
get(resource, name_or_id, callback){
get(resource, resource_identifier, callback){
let request_data = { }
request_data.params = this.requestParams();
request_data.request_name = `Get${resource}`;
......@@ -151,8 +151,8 @@ class ZimbraAdminApi {
request_data.parse_response = this.parseResponse;
let resource_name = this.dictionary.resourceResponseName(resource);
request_data.params.params[resource_name] = {
'by': 'name',
'_content': name_or_id
'by': this.dictionary.byIdOrName(resource_identifier),
'_content': resource_identifier
};
this.performRequest(request_data);
}
......
......@@ -14,6 +14,14 @@ export default class Dictionary {
return this.zimbra_resources[resource.toLowerCase()].class_name;
}
// Check if resource_identifier is a ZimbraId (UUID)
// and if it is return 'by': 'id' to params.
byIdOrName (resource_identifier) {
let uuid_regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
if (resource_identifier.match(uuid_regex)) return 'id';
return 'name';
}
classFactory (resource, object) {
const class_name = this.resourceToClass(resource.toLowerCase());
return new class_name(object);
......
......@@ -134,14 +134,14 @@
it('should get and return with name or id', function(done){
let api = new ZimbraAdminApi(auth_data);
let resource_id = null;
api.getDomain('zboxapp.dev', function(err, data){
resource_id = data.id;
});
api.getDomain(resource_id, function(err, data){
expect(data.name).to.equal('zboxapp.dev');
done();
});
let callback = function(err, data){
let domain_id = data.id;
api.getDomain(domain_id, function(err, data){
expect(data.name).to.equal('zboxapp.dev');
done();
});
};
api.getDomain('zboxapp.dev', callback);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment