Vote count:
0
I want to create a Gists Editor in JavaScript. So I can get Gists and I can access the Github API with a token (/user is good), but I don't can edit a gist (I get not an error, but it dosn't work). Please help me :) If you want to try it in Browser (it isn't finish!) http://ift.tt/1w1S91u
Thanks and sorry for bad english, timia2109
Important methods:
function githubAPI(pM, pPost, pToken, pType) {
var myjson;
var typeOfThis = (pType !== null) ? pType : (pPost !== null) ? "POST": "GET";
var URL = "https://api.github.com/"+pM;
var PostData = JSON.stringify( pPost );
$.ajax({
url:URL,
async: false,
data: PostData,
type: typeOfThis,
contentType: "application/json; charset=utf-8",
headers: { Authorization: "token "+pToken },
dataType: "json",
}).done(function (data){
myjson = data;
});
return myjson;
}
function saveGist(pGO) {
var sendData = {};
sendData.description = pGO.description;
sendData.public = pGO.public;
sendData.files = {};
for (var i in pGO.files) {
sendData.files[i] = {};
sendData.files[i].content = pGO.files[i].content;
if (pGO.files[i].filename !== null) {
sendData.files[i].filename = pGO.files[i].filename;
}
console.log("Saved: "+i); //Shows all files.
}
return githubAPI("gists/"+pGO.id,sendData,token,"PATCH");
}
function sendExit() {
saveEditor(); //Save now edited file in gist
saveResult = saveGist(gist); //gist is the loaded gist. The editor edit the file in that Object
lastSave = new Date();
var sT = {
h:lastSave.getHours(),
m:lastSave.getMinutes(),
s:lastSave.getSeconds()
};
$("#saveInfo").html("<h4>Editor | Last Save: "+sT.h+":"+sT.m+":"+sT.s+"</h4>");
}
asked 42 secs ago
Can't edit a Gist over Javascript
Aucun commentaire:
Enregistrer un commentaire