Skip to content

Commit 9761a1c

Browse files
committed
Renamed klasse / klassen to class / classes and improved README
1 parent 9672e4b commit 9761a1c

File tree

7 files changed

+176
-160
lines changed

7 files changed

+176
-160
lines changed

README.md

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,25 @@ public class Main {
3838
try {
3939
Session session = Session.login("your webuntis username", "your webuntis password", "https://example.webuntis.com", "myschool"); // create a new webuntis session
4040

41-
for (Timetable.Lesson lesson: session.getTimetableFromKlasseId(LocalDate.now(), LocalDate.now())) { // get the timetable and loop over it
42-
System.out.println("Lesson " + String.join(", ", lesson.getSubjectIds()) + " from " + lesson.getStartTime() + " to " + lesson.getEndTime()); // print the subject and the lesson time (from x to y)
41+
// print out all classes with their names and ids
42+
for (Classes.ClassObject classObject : session.getClasses()) {
43+
System.out.printf("Class name: '%s' - Class id: '%d'\n", classObject.getName(), classObject.getId());
4344
}
4445

45-
session.logout(); //logout
46-
} catch (LoginException e) { // this exception get thrown if something went wrong with Session.login
46+
// logout
47+
session.logout();
48+
} catch (LoginException e) {
49+
// this exception get thrown if something went wrong with Session.login
4750
System.out.println("Failed to login: " + e.getMessage());
48-
return;
49-
} catch (IOException e) { // if an error appears this get thrown
51+
} catch (IOException e) {
52+
// if an error appears this get thrown
5053
e.printStackTrace();
51-
return;
5254
}
5355
}
5456
}
5557
```
5658

57-
## Get a specific klasse
59+
## Find / search a specific class
5860

5961
```java
6062
public class Main {
@@ -63,18 +65,26 @@ public class Main {
6365
try {
6466
Session session = Session.login("your webuntis username", "your webuntis password", "https://example.webuntis.com", "myschool"); // creates a new webuntis session
6567

66-
Klassen klassen = session.getKlassen(); // get all klassen which are registered on the server
67-
Klassen.KlasseObject myKlasse = klassen.findById(1234); // find an klasse by its id
68+
Classes classes = session.getClasses();
6869

69-
System.out.println("Name of my klasse: " + myKlasse.getLongName());
70+
// get a class by its id
71+
// findBy(...) methods only returns one result
72+
System.out.println(classes.findById(1234));
7073

71-
session.logout(); //logout
72-
} catch (LoginException e) { // this exception get thrown if something went wrong with Session.login
74+
// this prints all classes which contains 's' in their name.
75+
// searchBy(...) methods can return multiple results / matches
76+
for (Classes.ClassObject classObject : classes.searchByName("s")) {
77+
System.out.println(classObject);
78+
}
79+
80+
// logout
81+
session.logout();
82+
} catch (LoginException e) {
83+
// this exception get thrown if something went wrong with Session.login
7384
System.out.println("Failed to login: " + e.getMessage());
74-
return;
75-
} catch (IOException e) { // if an error appears this get thrown
85+
} catch (IOException e) {
86+
// if an error appears this get thrown
7687
e.printStackTrace();
77-
return;
7888
}
7989
}
8090

@@ -88,25 +98,31 @@ public class Main {
8898

8999
public static void main(String[] args) {
90100
try {
91-
Session session = Session.login("your webuntis username", "your webuntis password", "webuntis.grupet.at", "demo_inf"); // creates a new webuntis session
101+
Session session = Session.login("your webuntis username", "your webuntis password", "webuntis.grupet.at", "demo_inf");
102+
// creates a new webuntis session
92103

93-
Response response = session.getCustomData("getAMethodThatIsNotImplemented"); // requests the custom method
94-
if (response.isError()) { // you can easily check if the response contains an error
104+
Response response = session.getCustomData("getAMethodThatIsNotImplemented");
105+
// requests the custom method
106+
if (response.isError()) {
107+
// you can easily check if the response contains an error
95108
return;
96109
} else {
97-
JSONObject responseObject = response.getResponse(); //get the response...
98-
JSONObject result = responseObject.getJSONObject("result"); //...and read it
110+
// get the response...
111+
JSONObject responseObject = response.getResponse();
112+
// ...and read it
113+
JSONObject result = responseObject.getJSONObject("result");
99114

100115
System.out.println(result.toString());
101116
}
102117

103-
session.logout(); //logout
104-
} catch (LoginException e) { // this exception get thrown if something went wrong with Session.login
118+
// logout
119+
session.logout();
120+
} catch (LoginException e) {
121+
// this exception get thrown if something went wrong with Session.login
105122
System.out.println("Failed to login: " + e.getMessage());
106-
return;
107-
} catch (IOException e) { // if an error appears this get thrown
123+
} catch (IOException e) {
124+
// if an error appears this get thrown
108125
e.printStackTrace();
109-
return;
110126
}
111127
}
112128
}

src/org/bytedream/untis4j/Infos.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Infos {
2020

2121
private final String sessionId;
2222
private final UntisUtils.ElementType personType;
23-
private final int klasseId;
23+
private final int classId;
2424

2525
/**
2626
* Initialize the {@link Infos} class
@@ -32,7 +32,7 @@ public class Infos {
3232
* @param userAgent the user agent used for the api
3333
* @since 1.0
3434
*/
35-
public Infos(String username, String password, String server, String schoolName, String userAgent, String sessionId, UntisUtils.ElementType personType, int klasseId) {
35+
public Infos(String username, String password, String server, String schoolName, String userAgent, String sessionId, UntisUtils.ElementType personType, int classId) {
3636
this.username = username;
3737
this.password = password;
3838
this.server = server;
@@ -41,7 +41,7 @@ public Infos(String username, String password, String server, String schoolName,
4141

4242
this.sessionId = sessionId;
4343
this.personType = personType;
44-
this.klasseId = klasseId;
44+
this.classId = classId;
4545
}
4646

4747
/**
@@ -115,13 +115,13 @@ public UntisUtils.ElementType getPersonType() {
115115
}
116116

117117
/**
118-
* Returns the klasse id used for the api
118+
* Returns the class id used for the api
119119
*
120-
* @return the klasse id used for the api
120+
* @return the class id used for the api
121121
* @since 1.1
122122
*/
123-
public int getKlasseId() {
124-
return klasseId;
123+
public int getClassId() {
124+
return classId;
125125
}
126126

127127
@Override
@@ -135,7 +135,7 @@ public String toString() {
135135
infosAsMap.put("userAgent", userAgent);
136136
infosAsMap.put("sessionId", sessionId);
137137
infosAsMap.put("personType", personType);
138-
infosAsMap.put("klasseId", klasseId);
138+
infosAsMap.put("classId", classId);
139139

140140
return new JSONObject(infosAsMap).toString();
141141
}

src/org/bytedream/untis4j/Session.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Session {
4040
/**
4141
* Class to do all the Untis stuff.
4242
*
43-
* <p>Main class to handle and get all Untis information<p/>
43+
* <p>org.bytedream.untis4j.Main class to handle and get all Untis information<p/>
4444
*
4545
* @param infos infos about the user
4646
* @param requestManager manager that handles all requests
@@ -221,13 +221,13 @@ public Response getClassRegEvents(LocalDate start, LocalDate end, UntisUtils.Ele
221221
}
222222

223223
/**
224-
* Get the Information about the ClassRegEvents for a specific time period and klasse id (<- from https://github.com/python-webuntis/python-webuntis).
224+
* Get the Information about the ClassRegEvents for a specific time period and class id (<- from https://github.com/python-webuntis/python-webuntis).
225225
*
226226
* @see Session#getClassRegEvents(LocalDate, LocalDate, UntisUtils.ElementType, Integer)
227227
* @since 1.0
228228
*/
229-
public Response getAllClassRegEventsFromKlasseId(LocalDate start, LocalDate end, int id) throws IOException {
230-
return this.getClassRegEvents(start, end, UntisUtils.ElementType.KLASSE, id);
229+
public Response getAllClassRegEventsFromClassId(LocalDate start, LocalDate end, int id) throws IOException {
230+
return this.getClassRegEvents(start, end, UntisUtils.ElementType.CLASS, id);
231231
}
232232

233233
/**
@@ -367,55 +367,55 @@ public Holidays getHolidays() throws IOException {
367367
}
368368

369369
/**
370-
* Returns all klassen registered on the given server.
370+
* Returns all classes registered on the given server.
371371
*
372-
* <p>Returns {@link Klassen} with all information about the klasse which are registered on the given server</p>
372+
* <p>Returns {@link Classes} with all information about the class which are registered on the given server</p>
373373
*
374-
* @see Session#getKlassen(Integer)
374+
* @see Session#getClasses(Integer)
375375
* @since 1.0
376376
*/
377-
public Klassen getKlassen() throws IOException {
378-
return getKlassen(null);
377+
public Classes getClasses() throws IOException {
378+
return getClasses(null);
379379
}
380380

381381
/**
382-
* Returns all klassen from the given school year registered on the given server.
382+
* Returns all classes from the given school year registered on the given server.
383383
*
384-
* <p>Returns {@link Klassen} with all information about the klassen from the given school year which are registered on the given server</p>
384+
* <p>Returns {@link Classes} with all information about the classes from the given school year which are registered on the given server</p>
385385
*
386-
* @param schoolYearId number of the school year from which you want to get the klassen
387-
* @return {@link Klassen} with all information about the klassen
386+
* @param schoolYearId number of the school year from which you want to get the classes
387+
* @return {@link Classes} with all information about the classes
388388
* @throws IOException if an IO Exception occurs
389389
* @since 1.0
390390
*/
391-
public Klassen getKlassen(Integer schoolYearId) throws IOException {
392-
ResponseConsumer<Klassen> responseConsumer = response -> {
391+
public Classes getClasses(Integer schoolYearId) throws IOException {
392+
ResponseConsumer<Classes> responseConsumer = response -> {
393393
JSONObject jsonResponse = response.getResponse();
394394

395395
if (response.isError()) {
396396
throw new IOException(response.getErrorMessage());
397397
}
398398
JSONArray jsonArray = jsonResponse.getJSONArray("result");
399399

400-
Klassen klassen = new Klassen();
400+
Classes classes = new Classes();
401401

402402
for (int i = 0; i < jsonArray.length(); i++) {
403-
JSONObject klassenInfo = jsonArray.getJSONObject(i);
404-
klassen.add(new Klassen.KlasseObject(klassenInfo.getString("name"),
405-
klassenInfo.getBoolean("active"),
406-
klassenInfo.getInt("id"),
407-
klassenInfo.getString("longName")));
403+
JSONObject classesInfo = jsonArray.getJSONObject(i);
404+
classes.add(new Classes.ClassObject(classesInfo.getString("name"),
405+
classesInfo.getBoolean("active"),
406+
classesInfo.getInt("id"),
407+
classesInfo.getString("longName")));
408408
}
409409

410-
return klassen;
410+
return classes;
411411
};
412412

413413
if (schoolYearId != null) {
414-
return requestSender(UntisUtils.Method.GETKLASSEN, new HashMap<String, Integer>() {{
414+
return requestSender(UntisUtils.Method.GETCLASSES, new HashMap<String, Integer>() {{
415415
put("schoolyearId", schoolYearId);
416416
}}, responseConsumer);
417417
} else {
418-
return requestSender(UntisUtils.Method.GETKLASSEN, responseConsumer);
418+
return requestSender(UntisUtils.Method.GETCLASSES, responseConsumer);
419419
}
420420
}
421421

@@ -682,7 +682,7 @@ public SchoolYears.SchoolYearObject getCurrentSchoolYear() throws IOException {
682682
/**
683683
* Returns the lessons / timetable for a specific time period.
684684
*
685-
* <p> Returns the lessons / timetable for a specific time period and klasse / teacher / subject / room / student id<p/>
685+
* <p> Returns the lessons / timetable for a specific time period and class / teacher / subject / room / student id<p/>
686686
*
687687
* @param start the beginning of the time period
688688
* @param end the end of the time period
@@ -709,7 +709,7 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element
709709

710710
Timetable timetable = new Timetable();
711711

712-
Klassen k = getKlassen();
712+
Classes k = getClasses();
713713
Teachers t = getTeachers();
714714
Subjects s = getSubjects();
715715
Rooms r = getRooms();
@@ -719,7 +719,7 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element
719719
for (int i = 0; i < jsonArray.length(); i++) {
720720
JSONObject timetableInfos = jsonArray.getJSONObject(i);
721721

722-
Klassen klassen = new Klassen();
722+
Classes classes = new Classes();
723723
Teachers teachers = new Teachers();
724724
Subjects subjects = new Subjects();
725725
Rooms rooms = new Rooms();
@@ -732,7 +732,7 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element
732732
try {
733733
switch (currentStringArray) {
734734
case "kl":
735-
arrayJSONArray.forEach(o -> klassen.add(k.findById(((JSONObject) o).getInt("id"))));
735+
arrayJSONArray.forEach(o -> classes.add(k.findById(((JSONObject) o).getInt("id"))));
736736
break;
737737
case "te":
738738
arrayJSONArray.forEach(o -> teachers.add(t.findById(((JSONObject) o).getInt("id"))));
@@ -806,7 +806,7 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element
806806
startTime,
807807
endTime,
808808
timeUnits.findByStartTime(startTime),
809-
klassen,
809+
classes,
810810
teachers,
811811
rooms,
812812
subjects,
@@ -819,13 +819,13 @@ public Timetable getTimetable(LocalDate start, LocalDate end, UntisUtils.Element
819819
}
820820

821821
/**
822-
* Returns the lessons / timetable for a specific time period and klasse id.
822+
* Returns the lessons / timetable for a specific time period and class id.
823823
*
824824
* @see Session#getTimetable(LocalDate, LocalDate, UntisUtils.ElementType, int)
825825
* @since 1.0
826826
*/
827-
public Timetable getTimetableFromKlasseId(LocalDate start, LocalDate end, int klasseId) throws IOException {
828-
return this.getTimetable(start, end, UntisUtils.ElementType.KLASSE, klasseId);
827+
public Timetable getTimetableFromClassId(LocalDate start, LocalDate end, int classId) throws IOException {
828+
return this.getTimetable(start, end, UntisUtils.ElementType.CLASS, classId);
829829
}
830830

831831
/**
@@ -907,13 +907,13 @@ public WeeklyTimetable getWeeklyTimetable(LocalDate anyDateOfWeek, UntisUtils.El
907907
}
908908

909909
/**
910-
* Requests the timetable for a whole week and a klasse id
910+
* Requests the timetable for a whole week and a class id
911911
*
912912
* @see Session#getWeeklyTimetable(LocalDate, UntisUtils.ElementType, int)
913913
* @since 1.1
914914
*/
915-
public WeeklyTimetable getWeeklyTimetableFromKlasseId(LocalDate anyDateOfWeek, int klasseId) throws IOException {
916-
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.KLASSE, klasseId);
915+
public WeeklyTimetable getWeeklyTimetableFromClassId(LocalDate anyDateOfWeek, int classId) throws IOException {
916+
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.CLASS, classId);
917917
}
918918

919919
/**
@@ -923,7 +923,7 @@ public WeeklyTimetable getWeeklyTimetableFromKlasseId(LocalDate anyDateOfWeek, i
923923
* @since 1.1
924924
*/
925925
public WeeklyTimetable getWeeklyTimetableFromTeacherId(LocalDate anyDateOfWeek, int teacherId) throws IOException {
926-
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.KLASSE, teacherId);
926+
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.CLASS, teacherId);
927927
}
928928

929929
/**
@@ -933,7 +933,7 @@ public WeeklyTimetable getWeeklyTimetableFromTeacherId(LocalDate anyDateOfWeek,
933933
* @since 1.1
934934
*/
935935
public WeeklyTimetable getWeeklyTimetableFromSubjectId(LocalDate anyDateOfWeek, int subjectId) throws IOException {
936-
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.KLASSE, subjectId);
936+
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.CLASS, subjectId);
937937
}
938938

939939
/**
@@ -943,7 +943,7 @@ public WeeklyTimetable getWeeklyTimetableFromSubjectId(LocalDate anyDateOfWeek,
943943
* @since 1.1
944944
*/
945945
public WeeklyTimetable getWeeklyTimetableFromRoomId(LocalDate anyDateOfWeek, int roomId) throws IOException {
946-
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.KLASSE, roomId);
946+
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.CLASS, roomId);
947947
}
948948

949949
/**
@@ -953,7 +953,7 @@ public WeeklyTimetable getWeeklyTimetableFromRoomId(LocalDate anyDateOfWeek, int
953953
* @since 1.1
954954
*/
955955
public WeeklyTimetable getWeeklyTimetableFromStudentId(LocalDate anyDateOfWeek, int studentId) throws IOException {
956-
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.KLASSE, studentId);
956+
return this.getWeeklyTimetable(anyDateOfWeek, UntisUtils.ElementType.CLASS, studentId);
957957
}
958958

959959
/**

src/org/bytedream/untis4j/UntisUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static boolean setContainsSetItem(Set<?> set1, Set<?> set2) {
102102
* @since 1.0
103103
*/
104104
public enum ElementType {
105-
KLASSE(1),
105+
CLASS(1),
106106
TEACHER(2),
107107
SUBJECT(3),
108108
ROOM(4),
@@ -164,7 +164,7 @@ public enum Method {
164164
GETEXAMS("getExams"),
165165
GETEXAMTYPES("getExamTypes"),
166166
GETHOLIDAYS("getHolidays"),
167-
GETKLASSEN("getKlassen"),
167+
GETCLASSES("getKlassen"),
168168
GETLATESTIMPORTTIME("getLatestImportTime"),
169169
GETROOMS("getRooms"),
170170
GETSCHOOLYEARS("getSchoolyears"),

0 commit comments

Comments
 (0)