-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
122 lines (99 loc) · 3.93 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const soap = require('soap');
const xml2json = require('xml2json');
class StudentVueClient {
constructor(username, password, client) {
this.username = username;
this.password = password;
this.client = client;
}
getMessages() {
return this._xmlJsonSerialize(this._makeServiceRequest('GetPXPMessages'));
}
getCalendar() {
return this._xmlJsonSerialize(this._makeServiceRequest('StudentCalendar'));
}
getAttendance() {
return this._xmlJsonSerialize(this._makeServiceRequest('Attendance'));
}
getGradebook(reportPeriod) {
let params = {};
if (typeof reportPeriod !== 'undefined') {
params.ReportPeriod = reportPeriod;
}
return this._xmlJsonSerialize(this._makeServiceRequest('Gradebook', params));
}
getClassNotes() {
return this._xmlJsonSerialize(this._makeServiceRequest('StudentHWNotes'));
}
getStudentInfo() {
return this._xmlJsonSerialize(this._makeServiceRequest('StudentInfo'));
}
getSchedule(termIndex) {
let params = {};
if (typeof termIndex !== 'undefined') {
params.TermIndex = termIndex;
}
return this._xmlJsonSerialize(this._makeServiceRequest('StudentClassList', params));
}
getSchoolInfo() {
return this._xmlJsonSerialize(this._makeServiceRequest('StudentSchoolInfo'));
}
listReportCards() {
return this._xmlJsonSerialize(this._makeServiceRequest('GetReportCardInitialData'));
}
getReportCard(documentGuid) {
return this._xmlJsonSerialize(this._makeServiceRequest('GetReportCardDocumentData', { DocumentGU: documentGuid }));
}
listDocuments() {
return this._xmlJsonSerialize(this._makeServiceRequest('GetStudentDocumentInitialData'));
}
getDocument(documentGuid) {
return this._xmlJsonSerialize(this._makeServiceRequest('GetContentOfAttachedDoc', { DocumentGU: documentGuid }));
}
_xmlJsonSerialize(servicePromise) {
return servicePromise.then(result => xml2json.toJson(result[0].ProcessWebServiceRequestResult));
}
_makeServiceRequest(methodName, params = {}, serviceHandle = 'PXPWebServices') {
let paramStr = '<Parms>';
Object.entries(params).forEach(([key, value]) => {
paramStr += '<' + key + '>';
paramStr += value;
paramStr += '</' + key + '>';
});
paramStr += '</Parms>';
return this.client.ProcessWebServiceRequestAsync({
userID: this.username,
password: this.password,
skipLoginLog: 1,
parent: 0,
webServiceHandleName: serviceHandle,
methodName,
paramStr
});
}
}
function login(url, username, password, soapOptions = {}) {
const host = new URL(url).host;
const endpoint = `https://${ host }/Service/PXPCommunication.asmx`;
const resolvedOptions = Object.assign({
endpoint: endpoint, // enforces https
escapeXML: false
}, soapOptions);
const wsdlURL = endpoint + '?WSDL';
return soap.createClientAsync(wsdlURL, resolvedOptions)
.then(client => new StudentVueClient(username, password, client));
}
function getDistrictUrls(zipCode) {
return soap.createClientAsync('https://support.edupoint.com/Service/HDInfoCommunication.asmx?WSDL', {
endpoint: 'https://support.edupoint.com/Service/HDInfoCommunication.asmx',
escapeXML: false
})
.then(client => {
const supportClient = new StudentVueClient('EdupointDistrictInfo', 'Edup01nt', client);
return supportClient._xmlJsonSerialize(supportClient._makeServiceRequest('GetMatchingDistrictList', {
MatchToDistrictZipCode: zipCode,
Key: '5E4B7859-B805-474B-A833-FDB15D205D40' // idk how safe this is
}, 'HDInfoServices'));
});
}
module.exports = { login, getDistrictUrls };