pagerduty-overlap-checker
Advanced tools
Comparing version 1.0.3 to 1.0.4
// Generated by CoffeeScript 1.10.0 | ||
var _, async, checkSchedulesIds, debug, getSchedule, getSchedulesIds, nconf, notify, pdGet, processSchedules, processSchedulesFromConfig, request, sendNotification; | ||
var _, async, checkSchedulesIds, debug, getSchedule, getSchedulesIds, getUserId, nconf, notify, overrideUser, pdGet, processSchedules, processSchedulesFromConfig, request, sendNotification; | ||
@@ -183,2 +183,57 @@ async = require('async'); | ||
getUserId = function(email, cb) { | ||
var userOptions; | ||
userOptions = { | ||
form: { | ||
query: email | ||
} | ||
}; | ||
return pdGet("/users", userOptions, function(err, res, body) { | ||
var userId; | ||
if (res.statusCode !== 200) { | ||
return cb(new Error("Entries returned status code " + res.statusCode)); | ||
} | ||
userId = body.users[0].id; | ||
return cb(err, userId); | ||
}); | ||
}; | ||
overrideUser = function(userId, scheduleId, durationInMinutes, cb) { | ||
var duration, endDate, sharedOptions, startDate; | ||
if (durationInMinutes == null) { | ||
durationInMinutes = 30; | ||
} | ||
if (userId && scheduleId) { | ||
duration = durationInMinutes * 60 * 1000; | ||
startDate = new Date(); | ||
endDate = new Date(startDate.getTime() + duration); | ||
sharedOptions = { | ||
uri: nconf.get('PAGERDUTY_API_URL') + ("/schedules/" + scheduleId + "/overrides"), | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Token token=' + nconf.get('PAGERDUTY_TOKEN') | ||
}, | ||
form: { | ||
override: { | ||
"user_id": userId, | ||
"start": startDate.toISOString(), | ||
"end": endDate.toISOString() | ||
} | ||
} | ||
}; | ||
debug('Calling request with: ', sharedOptions); | ||
return request(sharedOptions, function(err, res, body) { | ||
var reponseObject; | ||
if (err) { | ||
return cb(err); | ||
} | ||
if (res.statusCode !== 201) { | ||
return cb(new Error("Entries returned status code " + res.statusCode)); | ||
} | ||
reponseObject = JSON.parse(body); | ||
return cb(err, reponseObject.override); | ||
}); | ||
} | ||
}; | ||
module.exports = { | ||
@@ -190,3 +245,5 @@ pdGet: pdGet, | ||
processSchedulesFromConfig: processSchedulesFromConfig, | ||
sendNotification: sendNotification | ||
sendNotification: sendNotification, | ||
getUserId: getUserId, | ||
overrideUser: overrideUser | ||
}; |
{ | ||
"name": "pagerduty-overlap-checker", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "PagerDuty Overlap Duties Checker", | ||
@@ -5,0 +5,0 @@ "main": "lib/", |
16052
364