Skip to content

Commit

Permalink
Updated readme and fixed error (#4)
Browse files Browse the repository at this point in the history
* Corrected mistakes

* Fixed error where _parseTimeGrid always returned null
  • Loading branch information
hairy-tortoise authored Sep 12, 2023
1 parent c93e1c7 commit d65b459
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ The basic tool used to interact with the API is the Session object.
// .init(server, school, username, password, Optional: useragent)
Session mySession = await Session.init("demo.server.com", "demo_school", "demo_user", "demo_pass")
// The ID of the account which credentials you used should now be available over the .userId attribute
var myId = session.userId;
var myId = mySession.userId!;
// Alternatively you can also search for a student
var myId = (await mySession.searchStudent("demo_forename", "demo_surname"))!.surnameMatches![0].id;
```
Basic methods act just as you expect them to.
```dart
// To get cancellations for a specific day, simply call the .getCancellations method with a startDate
List<Period> cancellationsTmwr = await mySession.getCancellations(mySession.userId, startDate: DateTime.now().add(Duration(days: 1)));
List<Period> cancellationsTmwr = await mySession.getCancellations(mySession.userId!, startDate: DateTime.now().add(Duration(days: 1)));
// The same principle applies to the .getTimetable method, startDate and endDate (inclusive) are optional and will default to the current day
List<Period> timetable = await mySession.getTimetable(mySession.userId);
List<Period> timetable = await mySession.getTimetable(mySession.userId!);
```
Some methods like getStudent will cache their result for 30minutes by default.
```dart
Expand All @@ -41,7 +41,7 @@ mySession.cacheDisposeTime = 60; // Cached values will now stay available for 60
You want to program a timetable app? These methods might be useful.
```dart
// Get a timegrid that specifies the period time spans for each day
Timegrid myTimegrid = await mySession.getTimegrid();
TimeGrid myTimeGrid = await mySession.getTimeGrid();
// Get the timetable of the current week
DateTime mostRecentWeekday(DateTime date, int weekday) => DateTime(date.year, date.month, date.day - (date.weekday - weekday) % 7);
DateTime monday = mostRecentWeekday(DateTime.now(), DateTime.monday), friday = mostRecentWeekday(DateTime.now(), DateTime.friday);
Expand Down
3 changes: 1 addition & 2 deletions lib/untis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Session {
var dayDict = rawTimeGrid.firstWhere((element) => (element["day"] == day));
List<dynamic> dayData = dayDict["timeUnits"];

List.generate(
return List.generate(
dayData.length,
(timePeriod) => List.generate(2, (periodBorder) {
String border = List.from(["startTime", "endTime"])[periodBorder];
Expand All @@ -196,7 +196,6 @@ class Session {
} else {
return null;
}
return null;
}));
}

Expand Down

0 comments on commit d65b459

Please sign in to comment.