Created
August 8, 2018 22:59
-
-
Save faustofjunqueira/2b62f8c04a0bf13434477607aa7aea91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// APLICAÇÂO EM NODEJS | |
const http = require('http'); | |
const APIKey = "072c7dec10dd993bb47b5d7ffe9f5a60418b635a" | |
const datas = [ | |
['2018-06-20', 39127], | |
['2018-06-21', 39127], | |
['2018-06-22', 39127], | |
['2018-06-25', 39127], | |
['2018-06-26', 39127], | |
['2018-06-27', 39127], | |
['2018-06-28', 39127], | |
['2018-06-29', 39127], | |
['2018-07-02', 39127], | |
['2018-07-03', 39127], | |
['2018-07-04', 39127], | |
['2018-07-05', 39127], | |
['2018-07-06', 39127], | |
['2018-07-09', 39861], | |
['2018-07-10', 39861], | |
['2018-07-11', 39861], | |
['2018-07-12', 39861], | |
['2018-07-13', 39861], | |
['2018-07-16', 39861], | |
['2018-07-17', 39861], | |
['2018-07-18', 39861], | |
['2018-07-19', 39861], | |
['2018-07-20', 39861], | |
['2018-07-23', 39861], | |
['2018-07-24', 39861], | |
['2018-07-25', 39861], | |
['2018-07-26', 39861], | |
['2018-07-27', 39861], | |
['2018-07-30', 39855], | |
['2018-07-31', 39855], | |
['2018-08-01', 39855], | |
['2018-08-02', 39855], | |
['2018-08-03', 39855], | |
['2018-08-06', 39855], | |
['2018-08-07', 39855], | |
['2018-08-08', 39855] | |
]; | |
function enviar(data, ticket) { | |
return new Promise((resolve, reject) => { | |
const postData = `<time_entry><issue_id>${ticket}</issue_id><spent_on>${data}</spent_on><hours>9:00</hours><comments>Construção</comments></time_entry>`; | |
const req = http.request({ | |
host: "redmine.radixeng.com.br", | |
method: "POST", | |
path: "/time_entries.xml", | |
port: 80, | |
headers: { | |
'Content-Length': Buffer.byteLength(postData), | |
"Content-Type": "application/xml", | |
"X-Redmine-API-Key": APIKey | |
} | |
}, (res) => { | |
console.log(`STATUS: ${res.statusCode}`); | |
console.log(`HEADERS: ${JSON.stringify(res.headers)}`); | |
res.setEncoding('utf8'); | |
res.on('data', (chunk) => { | |
console.log(`BODY: ${chunk}`); | |
}); | |
res.on('end', () => { | |
resolve(); | |
}); | |
}); | |
req.on('error', (e) => { | |
console.error(`problem with request: ${e.message}`); | |
reject(e); | |
}); | |
// write data to request body | |
req.write(postData); | |
req.end(); | |
}); | |
} | |
async function enviarTudo() { | |
for (i in datas) { | |
await enviar(datas[i][0], datas[i][1]) | |
} | |
return "Enviado com sucesso"; | |
} | |
console.log("Enviando...") | |
enviarTudo().then(console.log, console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment