Javascript Fetch does not provide my content in Response message - javascript

I am struggling with the Response of the Javascript fetch() method. What is my objective: a) to send multiple lines to the backend to save those to a database and b) get a guid in return for further processing.
I succeed in objective a (save to database), but the return message fails to materialise. Response.ok is true, but no message is part of the return message.
What should I do to accomplish this?
My javascript is:
function saveAll(event) {
event.preventDefault();
var newDeelnemers = new Array();
var lijst = document.querySelectorAll('#tblDeelnemers tbody tr')
lijst.forEach(function (dnmr) {
var row = dnmr;
var deelnemer = {};
var nDnmr = row.children;
//deelnemer.Id = nDnmr[0].innerHTML;
deelnemer.FamilielidFirstName = nDnmr[0].innerHTML;
deelnemer.Achternaam = nDnmr[1].innerHTML;
deelnemer.DOB = nDnmr[2].innerHTML;
deelnemer.Programma = nDnmr[3].innerHTML;
deelnemer.EetMee = nDnmr[4].firstChild.checked;
deelnemer.Dieet = nDnmr[5].innerHTML;
deelnemer.Bedrag = nDnmr[6].innerHTML;
newDeelnemers.push(deelnemer);
});
fetch("/Familiedag/Registreer", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(newDeelnemers)
}).then(function (response) {
console.log('eerste keer: ' + response);
if (response.ok) {
alert('De registratie is gelukt');
//redirect("/Familiedag/RegistreerConfirm?")
}
});
}
The controller
[HttpPost]
public IActionResult Registreer([FromBody] List<FdDeelnemer> newDeelnemers)
{
if (newDeelnemers.Count == 0)
{
return null;
}
Guid registratieGuid = Guid.NewGuid();
foreach (var ndn in newDeelnemers)
{
FdDeelnemer VM = new FdDeelnemer();
VM.RegistratieGuid = registratieGuid;
VM.FamilielidFirstName = ndn.FamilielidFirstName;
VM.Achternaam = ndn.Achternaam;
VM.EetMee = ndn.EetMee;
VM.Dieet = ndn.Dieet;
VM.Programma = ndn.Programma;
VM.DOB = ndn.DOB;
VM.Bedrag = ndn.Bedrag;
VM.CreatedBy = User.Identity.Name;
VM.CreatedOn = DateTime.UtcNow;
_context.Add(VM);
}
Guid geregistreerdeDeelnemers = registratieGuid;
return Json(geregistreerdeDeelnemers);
}

add another .then that return the json
fetch("/echo/json/", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"tes": "data"
})
}).then(function(response) {
return response.json();
}).then(function(json) {
console.log('eerste keer: ', json);
alert('De registratie is gelukt');
//redirect("/Familiedag/RegistreerConfirm?")
});

You can try to return it like that:
return Json(new { AnythingYouWant = geregistreerdeDeelnemers });

Related

Fetch function for ExactOnline with multiple request fails on zapier and n8n

I've been working on a script that creates and updates stuff with the ExactOnline API.
when I run the script locally everything works fine but when I try to use it on a platform such as Zapier or n8n it doesn't work as intended.
on Zapier it only runs just before it does a fetch request
this my code that I use in zapier:
var token = 'token';
var divisionid = 'divisionid';
var AMRelatieData = {
"Name": "company name",
"City": "city name",
"Website": "website.com"
};
var AMContactData = {
"FirstName": "firstname",
"LastName": "lastname",
"City": "name city"
};
var testrlid;
async function actionHandeler(actionValue) {
var action = actionValue;
if (action == "cp_maken_&_relatie_maken") {
var maakRelatieWaarde = await maakRelatie(AMRelatieData);
var POSTrelatieID = maakRelatieWaarde;
AMContactData.Account = POSTrelatieID;
var maakContactwaarde = await maakContact(AMContactData);
var POSTcontactID = maakContactwaarde;
testcpid = POSTcontactID;
testrlid = POSTrelatieID;
return ('maakContactwaarde succes');
}
//functions
async function updateRelatie(updateData, relatieId) {
var UpdateRelatiePUT = await PUTreq(1, updateData, relatieId);
console.log(UpdateRelatiePUT);
return ("updateRelatie succes");
}
async function maakRelatie(createData) {
var relatieId;
console.log('maakRelatie: ');
var maakRelatiePOST = await POSTreq(1, createData);
console.log('maakRelatieFunc:' + JSON.stringify(maakRelatiePOST));
return await maakRelatiePOST.d.ID;
}
async function maakContact(createData) {
var contactId;
var maaktcontactPOST = await POSTreq(2, createData);
console.log('maaktcontactFunc:' + JSON.stringify(maaktcontactPOST));
var jsonData = {
MainContact: maaktcontactPOST.d.ID
};
var relatieIdUpdate = createData.Account;
await updateRelatie(jsonData, relatieIdUpdate);
}
async function POSTreq(type, DATA) {
console.log('postreq');
var POSTendpoint = 'https://start.exactonline.nl/api/v1/'+ divisionid +'/crm/';
if (type == 1) {
POSTendpoint += 'Accounts';
}
if (type == 2) {
POSTendpoint += 'Contacts';
}
var outputPOST;
console.log(DATA);
await fetch(POSTendpoint, {
method: "POST",
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(DATA)
}).then(response => {
return response.json();
}).then(jsonResponse => {
var responseOut = jsonResponse;
outputPOST = responseOut;
}).catch(error => {
console.log(error);
});
return outputPOST;
}
async function PUTreq(type, DATA, id) {
var PUTendpoint = 'https://start.exactonline.nl/api/v1/'+ divisionid +'/crm/';
console.log('put data');
console.log(id);
console.log('data' + DATA);
console.log(type);
if (type == 1) {
PUTendpoint += "Accounts(guid'" + id + "')";
}
if (type == 2) {
PUTendpoint += "Contacts(guid'" + id + "')";
}
console.log(PUTendpoint);
console.log(PUTendpoint);
await fetch(PUTendpoint, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify(DATA)
});
}
}
async function actionHandlerFunc(){
console.log("begin");
await actionHandeler("cp_maken_&_relatie_maken");
return ("done did sum stuff");
};
output = [actionHandlerFunc()]

How can i filter out undefined from string

Hello Im fetching some data from an api and returning the response als text. Then im passing the result to another function where i want to format that data to get an JSON Object. But i always get undefined when i want to trim the data. When i do indexOf(undefined) it returns index -1. Here is an example of the data:
,result,table,_start,_stop,_time,_value,Wizard,_field,_measurement,botName,errorLevel,errorLeveldescription,pcName,status,stepNr
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T07:02:30Z,1,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T07:03:40Z,1,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:27:00Z,1,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:28:30Z,1,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:28:45Z,1,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:29:20Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:35:40Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:43:40Z,4,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:45:05Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,0,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:51:10Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,1
,mean,1,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:35:45Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,2
,mean,1,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:43:45Z,4,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,2
,mean,1,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:45:10Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,2
,mean,1,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:51:10Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,2
,mean,2,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:35:50Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,3
,mean,2,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:43:45Z,4,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,3
,mean,2,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:45:10Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,3
,mean,2,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:51:15Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,3
,mean,3,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:35:55Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,4
,mean,3,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:43:50Z,4,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,4
,mean,3,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:45:15Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,4
,mean,3,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:51:15Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,4
,mean,4,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:36:00Z,2,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,5
,mean,4,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:43:50Z,4,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,5
,mean,4,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:45:15Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,5
,mean,4,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T09:51:20Z,5,IPA_BOT,value,ipaMeasurement,IPA_BOT_1,400,INFO,SCHWCL07347,OK,5
,mean,5,2021-03-19T19:33:44.870040506Z,2021-04-18T19:33:44.870040506Z,2021-04-15T08:38:10Z,2,IPA_BOT,value,ipaMeasurement,RestartMachine,400,INFO,SCHWCL07347,OK,7
export function get_influx_data() {
let url = "api/url";
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/vnd.flux");
myHeaders.append("Accept", "application/csv");
myHeaders.append(
"Authorization",
" api Token"
);
let raw =
'api query body';
let requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow",
};
return fetch(url, requestOptions)
.then(function (response) {
if (response.ok) {
return response.text();
} else {
return Promise.reject(response)
}
}).then(function (result) {
return result
}).catch(function (error) {
console.log("error: " + error)
})
};
export function clean_influx_data(result) {
var data = result.trim();
var lines = data.split("\n");
var result = [];
var headers = lines[0].split(",");
for (var i = 1; i < lines.length; i++) {
if (!lines[i]) {
continue;
}
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
var rawJsonData = JSON.stringify(result);
const parsedData = JSON.parse(rawJsonData);
import { get_influx_data } from './api.js'
import {clean_influx_data} from './clean_data.js'
var a = get_influx_data();
a.then((result) => clean_influx_data(result))
var b = clean_influx_data()
You need to use Promise.resolve(result).
return fetch(url, requestOptions)
.then(function (response) {
if (response.ok) {
return response.text();
} else {
return Promise.reject(response)
}
}).then(function (result) {
return Promise.resolve(result);
}).catch(function (error) {
console.log("error: " + error)
})
};

Return a value from a callback fyntuion in NodeJs. Help me to return a value from the callback [duplicate]

This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 2 years ago.
When I run the below code, I get undefined but on console.log(token) I receive data.
how can i get to return the response.body as my Engine function return value?
var request = require("request");
var randomstring = require("randomstring");
// Create Reference number
var external_ref_number = "c199-9f9-78f-967e-" + randomstring.generate(12);
//console.log(external_ref_number);
// Function to perform requests
function Engine (interface, token, request_type, external_ref_number, id, mpesa_code)
{
var data = JSON.stringify({
"message_validation":
{
"api_user": "testuser",
"api_password": "Ez[=8Ck#",
"token": token
},
"message_route": {
"interface": interface,
"request_type": request_type,
"external_ref_number": external_ref_number
},
"message_body": {
"Id": id,
"TelcoRef": mpesa_code
}
});
console.log(data);
var options = {
'method': 'POST',
'url': 'http://testurl/api/Solid/SubmitRequest',
'headers': {
'Content-Type': 'application/json'
},
body: data
};
let response;
request(options, function (error, response)
{
if (error) throw new Error(error);
var token = response.body;
response = response.body;
console.log(token);
});
return response;
}
var interface = 'TOKEN';
var token = '';
var request_type = ''
// var external_ref_number = external_ref_number;
var id = '';
var mpesa_code = '';
var data = Engine(interface, token, request_type, external_ref_number, id, mpesa_code);
console.log(data);
Try this
var request = require("request");
var randomstring = require("randomstring");
// Create Reference number
var external_ref_number = "c199-9f9-78f-967e-" + randomstring.generate(12);
//console.log(external_ref_number);
// Function to perform requests
function Engine (interface, token, request_type, external_ref_number, id, mpesa_code, callback)
{
var data = JSON.stringify({
"message_validation":
{
"api_user": "testuser",
"api_password": "Ez[=8Ck#",
"token": token
},
"message_route": {
"interface": interface,
"request_type": request_type,
"external_ref_number": external_ref_number
},
"message_body": {
"Id": id,
"TelcoRef": mpesa_code
}
});
console.log(data);
var options = {
'method': 'POST',
'url': 'http://testurl/api/Solid/SubmitRequest',
'headers': {
'Content-Type': 'application/json'
},
body: data
};
let response;
request(options, function (error, response)
{
if (error) throw new Error(error);
var token = response.body;
response = response.body;
console.log(token);
callback(null, response);
});
//return response;
}
var interface = 'TOKEN';
var token = '';
var request_type = ''
// var external_ref_number = external_ref_number;
var id = '';
var mpesa_code = '';
Engine(interface, token, request_type, external_ref_number, id, mpesa_code, function (err, data) {
console.log(data);
});

I can not fetch a post in JavaScript

I have a question about the code. Probably the solution is very simple, but I'm taking the first step in JavaScript and it is not obvious to me.
I have some backend ready, postman sending POST is ok. So backend is fine.
I wrote a simple application in which after pressing the button saves the given data in the database.
Unfortunately, this doesn't work with the debugger, everything is fine. However, by clicking the button in the view something is wrong and no fetch is called. The object is not saving to the database.
Please help.
Api = function() {
this.header = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
};
Api.prototype.buildUrl = function(id) {
return "http://localhost:3000/db/shop_name/" + id;
};
Api.prototype.post = function(id, data) {
const urlPost = api.buildUrl(id.value);
return fetch(urlPost, {
method: "post",
body: JSON.stringify(data),
headers: this.header
})
.then(res => res.json())
.then(res => {
console.log("Dodałem użytkownika:");
console.log(res);
})
};
Api.prototype.get = function(id) {
//const urlGet = api.buildUrl(id);
return fetch(id, {
method: "GET",
})
.then(resp => {
alert(resp.json());
return resp.json();
})
};
Api.prototype.getAlll = function() {
return fetch(url, {
method: "GET"
})
.then(resp => {
alert(resp.json());
return resp.json()
})
};
Api.prototype.update = function(id, data) {
const url = api.buildUrl(id);
return fetch(url, {
method: "PUT",
body: JSON.stringify(data)
})
.then(resp => {
return resp.json()
.catch(error => {
let notFound = "The server can not find requested resource";
document.getElementById("stars").innerHTML = notFound + error.status;
})
})
};
Api.prototype.addProduct = function(id, data) {
return this.post(id, data);
};
Api.prototype.deleteProduct = function(id) {
return this.delete(id);
};
Api.prototype.updateProduct = function(id, data) {
return this.update(id, data);
};
Api.prototype.getProduct = function(id) {
return this.get(id);
};
Api.prototype.getAllProducts = function() {
return this.getAlll;
};
const Main = function() {
this.id = document.getElementById("id");
this.addCount = document.getElementById("count");
this.addName = document.getElementById("name");
this.addPrice = document.getElementById("price");
};
Main.prototype.add = function() {
// const ido = this.id.value;
const data = {
"price": this.addPrice.value,
"name": this.addName.value,
"count": this.addCount.value,
};
// let id = api.buildUrl(this.id.value);
api.addProduct(this.id, data);
};
Main.prototype.update = function() {
const data = {
"price": this.price,
"name": this.name,
"count": this.count,
};
api.updateProduct(id, data);
};
Main.prototype.delete = function() {
let id = api.buildUrl(this.id);
api.deleteProduct(id);
};
Main.prototype.get = function() {
let id = api.buildUrl(this.id.value);
api.getProduct(id);
};
Main.prototype.getAll = function() {
api.getAllProducts();
};
const api = new Api();
const main = new Main();
let addButton = document.getElementById('postBtn');
addButton.addEventListener('click', function() {
main.add();
});
/*
addButton.addEventListener("click",main.add.bind(main));
*/
let updateButton = document.getElementById("updateBtn");
updateButton.addEventListener("click", function() {
main.update();
});
let deleteButton = document.getElementById("deleteBtn");
deleteButton.addEventListener("click", function() {
main.delete();
});
let getButton = document.getElementById("getBtn");
getButton.addEventListener("click", function() {
main.get();
});
let getAllButton = document.getElementById("getAllBtn");
getAllButton.addEventListener("click", function() {
let tst = main.getAll();
console.log(tst);
});

can't update json on a github repository by GAS

I'm a very beginner about GAS, and As you can see, my English is not perfect.
I want to upload json file on a github repository by GooleAppsScript.
I can update markdown file, but I cannot do json file.
There is no error on GAS, but when I check the commit log, it says '0 changed files'.
where part should I change the following code?
github repository
function editJson() {
var prop = PropertiesService.getScriptProperties().getProperties();
const date = new Date();
var option = { name: prop.NAME, email: prop.EMAIL };
var github = new GitHubAPI(prop.GITHUB_USERNAME, prop.GITHUB_REPO, prop.GITHUB_TOKEN, option);
var content = ['a', 'b', 'c']
var branch = github.getBranch(prop.GITHUB_BRANCH);
var pTree = github.getTree(branch['commit']['commit']['tree']['sha']);
var blob = github.createBlob(JSON.stringify(content));
var data = {
'tree': pTree['tree'].concat([{
'path': 'json/test.json',
'mode': '100644',
'type': 'blob',
'sha': blob['sha']
}])
};
var tree = github.createTree(data);
var commit = github.createCommit('commit!!', tree['sha'], branch['commit']['sha']);
var result = github.updateReference(prop.GITHUB_BRANCH, commit['sha']);
Logger.log(result);
}
(function(exports) {
var GitHubAPI;
GitHubAPI = (function(){
GitHubAPI.name = 'GitHubAPI';
function GitHubAPI(userid, repo, token, option) {
this.userid = userid;
this.repo = repo;
this.token = token;
this.option = option != null ? option : {};
if(!this.option.tz) this.option.tz = Session.getScriptTimeZone();
this.BASE_URL = 'https://api.github.com/repos/';
this.API_ENDPOINT = "" + this.BASE_URL + this.userid + '/' + this.repo;
}
GitHubAPI.prototype.runREST = function(method, endpoint, data) {
var params;
switch (method) {
case 'GET':
params = { headers : { Authorization: 'token ' + this.token } };
break;
case 'POST':
case 'PATCH':
params = {
headers: {
Authorization: 'token ' + this.token
},
method: method,
contentType: 'application/json',
payload: JSON.stringify(data)
};
break;
default:
throw 'undefined HTTP method: ' + method;
}
var response = UrlFetchApp.fetch(this.API_ENDPOINT + endpoint, params);
return JSON.parse(response);
};
GitHubAPI.prototype.get = function(endpoint){ return this.runREST('GET', endpoint, null); };
GitHubAPI.prototype.post = function(endpoint, data){ return this.runREST('POST', endpoint, data); };
GitHubAPI.prototype.patch = function(endpoint, data){ return this.runREST('PATCH', endpoint, data); };
GitHubAPI.prototype.toISOFormat = function(date, tz) {
return Utilities.formatDate(date, tz, "yyyy-MM-dd'T'HH:mm:ssXXX");
};
GitHubAPI.prototype.getBranch = function(branchName) {
return this.get('/branches/' + branchName);
};
GitHubAPI.prototype.createBlob = function(content) {
return this.post('/git/blobs', { 'content': content, 'encoding': 'utf-8' });
};
GitHubAPI.prototype.createCommit = function(message, treeSha, parentSha) {
var data = {
'message': message,
'author': {
'name': this.option.name,
'email': this.option.email,
'date': this.toISOFormat(new Date(), this.option.tz)
},
'parents': [parentSha],
'tree': treeSha
}
return this.post('/git/commits', data);
};
GitHubAPI.prototype.updateReference = function(branchName, commitSha) {
return this.patch('/git/refs/heads/' + branchName, { 'sha': commitSha });
};
GitHubAPI.prototype.getTree = function(treeSha) {
return this.get('/git/trees/' + treeSha);
};
GitHubAPI.prototype.createTree = function(data) {
return this.post('/git/trees', data);
};
return GitHubAPI;
})();
return exports.GitHubAPI = GitHubAPI;
})(this);

Categories