-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjiraRest.js
63 lines (59 loc) · 2.07 KB
/
jiraRest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
define([
'utilities/validateAndThrow',
'request',
'configuration/pathAndQueryParams'
],
function (validate, request, pathAndQueryParams) {
'use strict';
var jiraRest,
jiraRestInstance,
isRequired,
// Options to pass to validate() to check for presence of a property.
// validate will return the message if the required property is not present.
isRequired = {presence: {message: 'is required'}};
/**
* Factory method that returns the jiraRestInstance given
* options.
*
* options must be an object with the following required and optional properties.
*
* required:
* baseUrl - The base url of the rest api call.
*/
jiraRest = function (options) {
var search;
validate(options, {baseUrl: isRequired});
search = function (query, callback) {
var url,
requestOptions,
requestCallback;
url = options.baseUrl + pathAndQueryParams.path + query + pathAndQueryParams.queryParams;
requestOptions = {
url: url,
auth: {
username: options.username,
password: options.password
},
strictSSL: options.strictSSL
};
requestCallback = function (err, response, body) {
if (err) {
callback(err);
}
if (response.statusCode !== 200) {
callback(JSON.stringify(response));
}
var results;
results = JSON.parse(body);
callback(err, results);
};
request(requestOptions, requestCallback);
};
jiraRestInstance = {
search: search
};
return jiraRestInstance;
};
return jiraRest;
}
);