Select Git revision
ConsoleApplication1.csproj
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
fetch.dart 4.91 KiB
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import '../fetching/pageconfig.dart';
import '../fetching/timetable.dart';
import '../util/date_extension.dart';
import '../util/serializable.dart';
import 'class.dart';
import 'element_type.dart';
import 'lecture.dart';
typedef Cookie = (String key, String value);
typedef RequestOptions = (String path, String method, Json params);
typedef RequestResult = (Json json, List<Cookie> cookies, FetchStats stats);
class UntisFetch {
static const String apiBase = '/WebUntis/api/public';
static const String idHsReutlingen = '_aHMgcmV1dGxpbmdlbg==';
static const _sessionCookieNames = <String>{
'JSESSIONID',
'traceId',
};
final http.Client client = http.Client();
final Uri serverHost = Uri.https('poly.webuntis.com');
final List<Cookie> _sessionCookies = [];
late PageConfig<Class> allClasses = PageConfig(
this,
elementType: ElementType.classGroup,
convert: Class.new,
);
late PageConfig<Lecture> allLectures = PageConfig(
this,
elementType: ElementType.lecture,
convert: Lecture.new,
);
final Map<TimetableOptions, CacheableTimetable> _timetables = {};
CacheableTimetable timetableOf({
required ElementType type,
required int elementId,
required DateTime date,
}) {
final startOfWeek = date.atStartOfWeek();
final TimetableOptions options = (type, elementId, startOfWeek);
return _timetables.putIfAbsent(
options,
() => CacheableTimetable(this,
date: startOfWeek, type: type, elementId: elementId));
}
Uri _makeUri(RequestOptions options) {
final (String path, _, Json params) = options;
return serverHost.replace(
path: '$apiBase/$path',
queryParameters: params,
);
}
Future<http.StreamedResponse> _request(String method, Uri uri) async {
final request = http.Request(method, uri);