Skip to content

Commit

Permalink
added support for server setup and custom timetable get
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidM42 committed Aug 18, 2017
1 parent 3b1651d commit 3934dbf
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 7 deletions.
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A simple interface for accessing the webuntis API
const w = require("untis-api");
const e = w.entities;

w.connect("username", "password", "school").then(() => {
w.connect("username", "password", "school", "borys").then(() => {
w.getTeachers().then(teachers => {
console.log(teachers);
});
Expand All @@ -39,16 +39,17 @@ A __Promise__ that is either resolved if the connection was successful or reject

#### Usage
```js
w.connect("username", "password", "school");
w.connect("username", "password", "school", "servername");
```
#### Parameters
* Username, Password and Schoolname as Strings
* Username, Password, Schoolname and Servername as Strings
* An object containing the login information in the following structure
```json
{
"schoolName": "school",
"username": "username",
"password": "password"
"password": "password",
"servername": "borys",
}
```

Expand Down Expand Up @@ -341,6 +342,49 @@ A lot of data, better see for yourself...

***

## getCustomTimetable

#### Usage

```js
TimeTableEntity = require("untis-api").Entities.TimeTableEntity;

w.getTimetable(new TimeTableEntity(1, 5), {
showSubstText: true,
showLsText: true,
klasseFields: ["name"],
roomFields: ["name"],
subjectFields: ["name"]
}).then(data => console.log(data));
```
#### Parameters
`getTimetable(tte, paramsObject)`
* tte: a TimeTableEntity containing the person whose timetable you want to watch's id and personType
* paramsObject: a Object with all custom parameters as properties of this object with their respective value

##### Valid properties:
- startDate: number, format: YYYYMMDD, optional (default: monday of this week)
- endDate: number, format: YYYYMMDD, optional (default: friday of this week)
- showBooking: boolean, returns the period's booking info if available (default: false)
- showInfo: boolean, returns the period information if available (default: false)
- showSubstText: boolean, returns the Untis substitution text if available (default: false)
- showLsText: boolean, returns the text of the period's lesson (default: false)
- showLsNumber: boolean, returns the number of the period's lesson (default: false)
- showStudentgroup: boolean, returns the name(s) of the studentgroup(s) (default: false)
- klasseFields: array, optional, values: „id“, „name“, „longname“, „externalkey“
- roomFields: array, optional, values: „id“, „name“, „longname“, „externalkey“
- subjectFields: array, optional, values: „id“, „name“, „longname“, „externalkey“
- teacherFields: array, optional, values: „id“, „name“, „longname“, „externalkey“


If a Fields parameter (e.g. „teacherFields“) is not set explicitly, the return object will contain the
internal id („keyType“: „id“) of the references (e.g. the teachers of a period) by default.

#### Returns
A lot of data, better see for yourself...

***

## searchPerson

#### Usage
Expand Down
6 changes: 3 additions & 3 deletions rpcWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ function setupWithObject(options) {
return connect();
}

function setup(username, password, schoolName) {
function setup(username, password, schoolName, servername) {
config.userName = username;
config.password = password;
config.url = url(schoolName);

config.servername = UntisServer;
return connect();
}

Expand All @@ -113,7 +113,7 @@ function rpc(method, params, cb) {

let options = {
method: "POST",
hostname: "mese.webuntis.com",
hostname: config.servername + ".webuntis.com",
path: u,
headers: headers,
};
Expand Down
64 changes: 64 additions & 0 deletions webuntis.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,70 @@ function getTimetable(timeTableEntity, dateInWeek) {
});
}

function getCustomTimetable(timeTableEntity, paramsObject,dateInWeek) {
return new Promise((resolve, reject) => {
if (isUndefined(timeTableEntity)) {
throw Error("please pass a timeTableEntity");
}

if (isUndefined(dateInWeek) || !isDate(dateInWeek)) {
dateInWeek = moment();
}

let startDate = dateInWeek.subtract(dateInWeek.day(), 'days').add(1, 'days');

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

let optionsObject = {
element: {
id: timeTableEntity.id,
type: timeTableEntity.type
},
startDate: parseInt(startDate.format(DATE_FORMAT)),
endDate: parseInt(endDate.format(DATE_FORMAT)),
};

let validOptions = [
"startDate",
"endDate",
"showBooking",
"showInfo",
"showSubstText",
"showLsText",
"showLsNumber",
"showStudentgroup",
"klasseFields",
"roomFields",
"subjectFields",
"teacherFields",
];

for (var property in paramsObject) {
if (paramsObject.hasOwnProperty(property)) {

if (validOptions.indexOf(property) > -1)){
optionsObject[property] =
}
else {
throw Error("Option: " + property + " is not a valid option for this method");
}

}
}

connectPromise.then(rpc.rpc("getTimetable", {
options: optionsObject,

}, data => {
if (data.error) {
throw Error(data.error);
} else {
resolve(data.result);
}
}))
});
}

function getClassRegisterForPeriod(timeTableId) {
return new Promise((resolve, reject) => {
if(!isNumber(timeTableId)){
Expand Down

0 comments on commit 3934dbf

Please sign in to comment.