function writeWorkoutToGist(url, day, existingGistData, workoutJson) {
var xhr = new XMLHttpRequest();
xhr.open("PATCH", url);
xhr.setRequestHeader("Authorization", ghToken);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
}
};
if (existingGistData === "") {
existingGistData = "[]";
}
var prevWorkoutJson = JSON.parse(existingGistData);
prevWorkoutJson.push(workoutJson);
var combinedWorkoutData = JSON.stringify(prevWorkoutJson);
var workoutData = {
files: {
[day]: {
content: combinedWorkoutData
}
}
};
var data = JSON.stringify(workoutData);
xhr.send(data);
}