Skip to content

Commit

Permalink
✨ added wrappers for a few other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stoez committed Feb 12, 2017
1 parent b5fe033 commit 8b4d726
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* ---------------------------------------------------------------------------- */

const w = require("./webuntisWrapper");
const w = require("./webuntis");
const e = require("./entities.js");

w.connectPromise.then(() => {
Expand All @@ -16,6 +16,18 @@ w.connectPromise.then(() => {

w.getClasses()
.then(data => console.log(data));

w.getRooms()
.then(data => console.log(data));

w.getSubjects()
.then(data => console.log(data));

w.getStatusData()
.then(data => console.log(data));

w.getHolidays()
.then(data => console.log(data));
});


Expand Down
File renamed without changes.
63 changes: 53 additions & 10 deletions webuntisWrapper.js → webuntis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
const isDate = require("util").isDate,
isUndefined = require("util").isUndefined,
moment = require("moment"),
webuntis = require("./webuntisRaw");
rpc = require("./rpcWrapper");

const DATE_FORMAT = "YYYYMMDD";
const TIME_FORMAT = "hhmm";

// webuntis.setup("username", "password", "schoolName");
webuntis.setupWithObject(require('./credentials.json'));
// rpc.setup("username", "password", "schoolName");
rpc.setupWithObject(require('./credentials.json'));

let connectPromise = webuntis.connect();
let connectPromise = rpc.connect();

exports.getTimetable = function(timeTableEntity, dateInWeek) {
return new Promise((resolve, reject) => {
Expand All @@ -35,34 +35,77 @@ exports.getTimetable = function(timeTableEntity, dateInWeek) {

let endDate = startDate.clone().add(5, 'days');

connectPromise.then(webuntis.rpc("getTimetable", {
connectPromise.then(rpc.rpc("getTimetable", {
type: timeTableEntity.type,
id: timeTableEntity.id,
startDate: parseInt(startDate.format(DATE_FORMAT)),
endDate: parseInt(endDate.format(DATE_FORMAT)),
}, data => {
if (data.error) {
reject(data.error);
} else if (data.result) {
} else {
resolve(data.result);
}
}))
});
};

exports.getClasses = function() {

return new Promise((resolve,reject) => {
connectPromise.then(webuntis.rpc("getKlassen", {}, data => {
connectPromise.then(rpc.rpc("getKlassen", {}, data => {
if (data.error) {
reject(data.error);
} else if (data.result) {
} else {
resolve(data.result);
}
}));
});
};

exports.getRooms = function() {
return new Promise((resolve, reject) => {
connectPromise.then(rpc.rpc("getRooms", {}, data => {
if(data.error)
reject(data.error);
else
resolve(data.result)
}))
});
};

exports.getSubjects = function() {
return new Promise((resolve, reject) => {
connectPromise.then(rpc.rpc("getSubjects", {}, data => {
if(data.error)
reject(data.error);
else
resolve(data.result)
}))
});
};

exports.getStatusData = function() {
return new Promise((resolve, reject) => {
connectPromise.then(rpc.rpc("getStatusData", {}, data => {
if(data.error)
reject(data.error);
else
resolve(data.result)
}))
});
};

exports.getHolidays = function() {
return new Promise((resolve, reject) => {
connectPromise.then(rpc.rpc("getHolidays", {}, data => {
if(data.error)
reject(data.error);
else
resolve(data.result)
}))
});
};

exports.getKlassen = exports.getClasses;
exports.info = webuntis.info;
exports.info = rpc.info;
exports.connectPromise = connectPromise;

0 comments on commit 8b4d726

Please sign in to comment.