diff --git a/lib/jira.js b/lib/jira.js index e919d9da..f35386f5 100644 --- a/lib/jira.js +++ b/lib/jira.js @@ -188,6 +188,18 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor this.request(options, callback); }; + this.getParamsStringBuilder = function(json){ + if(json){ + params = []; + for(var item in json){ + params.push(item+'='+json[item]) + } + return '?'+params.join('&'); + } else { + return ''; + } + }; + }; (function() { @@ -1826,6 +1838,48 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + // ## Describe the user whith the user name provided as argument## + // ### Takes ### + // * username: the username of the target user + // * expand: 1 field to expand in json result + // * callback: for when it's done + // + // ### Returns ### + // * error string + // * user object + // + // [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e132) + + this.getUserByUsername = function(username, expand, callback) { + var query = {}; + query.username = username; + if(expand) + query.expand = expand; + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/user' + this.getParamsStringBuilder(query)), + method: 'GET', + json: true + }; + + this.doRequest(options, function(error, response, body) { + + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 200) { + callback(null, body); + return; + } + + callback(response.statusCode + ': Error while getting current user'); + + }); + }; + // ## Retrieve the backlog of a certain Rapid View ## // ### Takes ### // * rapidViewId: rapid view id @@ -1917,4 +1971,51 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor }); }; + + // ## Retrieve the groups that exist in Jira ## + // ### Takes ### + // * query: a json object with query constraints + // * callback: for when it's done + // + // ### Returns ### + // * error string + // * Jira groups + /** + * JSON object item is in the format: + * { + * "query" : "project", + * "exclude" : "admin", + * "maxResults" : 3 + * } + * + * JSON object can be null + * + * JSON object works with only 1 or 2 of the 3 fields. + * + */ + this.getGroups = function(query, callback){ + + var options = { + rejectUnauthorized: this.strictSSL, + uri: this.makeUri('/groups/picker' + this.getParamsStringBuilder(query)), + method: 'GET', + json: true, + }; + + this.doRequest(options, function(error, response) { + if (error) { + callback(error, null); + return; + } + + if (response.statusCode === 200) { + callback(null, response.body); + + return; + } + + callback(response.statusCode + ': Error while retrieving groups'); + }); + }; + }).call(JiraApi.prototype);