Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user groups retrieval and GET parameters string builder #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions lib/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);