-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
65 lines (61 loc) · 2.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const Promise = require('bluebird');
const request = require('request');
const {username, password, eventguid} = require('./xml.js');
let { registrantArray } = require('./xml.js');
let successfullPushes = 0;
const headers = {'Content-Type' : 'text/xml; charset=utf-8', 'SOAPAction' : 'https://VALIDAR.ENDPOINT/PutRegistrationData', 'Accept' : 'text/xml'};
const url = 'https://VALIDAR.ENDPOINT.com/';
const requestStart = `<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<AuthenticationSoapHeader xmlns="https://VALIDAR.ENDPOINT.com/">
<Username>${username}</Username>
<Password>${password}</Password>
</AuthenticationSoapHeader>
</soap:Header>
<soap:Body>
<PutRegistrationData xmlns="https://VALIDAR.ENDPOINT.com/">
<eventGuid>${eventguid}</eventGuid>
<data><![CDATA[`;
const requestEnd = `]]></data>
</PutRegistrationData>
</soap:Body>
</soap:Envelope>`;
function analyzeArray() {
return new Promise((resolve, reject) => {
if(registrantArray){
console.log("Planning to make " + registrantArray.length + " requests.");
resolve();
}
reject("Registrant array is empty.");
});
}
function pushToEvent() {
return new Promise((resolve, reject) => {
let body = requestStart + registrantArray[0] + requestEnd;
request({method: 'POST', headers : headers, uri : url, body}, (err, response, body) => {
if(!err && response.statusCode == 200) {
if(body.indexOf('<Success>true</Success><') > -1){
successfullPushes += 1;
console.log('Successfully Pushed ' + successfullPushes);
registrantArray.shift();
if(registrantArray.length > 0) {
return resolve(pushToEvent());
} else {
return resolve("ALL PUSHES COMPLETE");
}
} else {
reject("ERROR:\n" + body);
}
}
return reject("ERROR:\n" + body);
});
});
}
analyzeArray().then(() => {
return pushToEvent();
}).then((result) => {
console.log(result);
}).catch((err) => {
console.log(err);
});