-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathget_schedule_activities_command.dart
65 lines (56 loc) · 2.08 KB
/
get_schedule_activities_command.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Package imports:
import 'package:http/http.dart' as http;
import 'package:xml/xml.dart';
// Project imports:
import 'package:notredame/constants/urls.dart';
import 'package:notredame/features/app/signets-api/models/schedule_activity.dart';
import 'package:notredame/features/app/signets-api/signets_api_client.dart';
import 'package:notredame/features/app/signets-api/soap_service.dart';
import 'package:notredame/utils/command.dart';
/// Call the SignetsAPI to get the courses activities for the [session] for
/// the student ([username]).
class GetScheduleActivitiesCommand implements Command<List<ScheduleActivity>> {
final SignetsAPIClient client;
final http.Client _httpClient;
final RegExp _sessionShortNameRegExp;
final String username;
final String password;
final String session;
GetScheduleActivitiesCommand(
this.client,
this._httpClient,
this._sessionShortNameRegExp, {
required this.username,
required this.password,
required this.session,
});
@override
Future<List<ScheduleActivity>> execute() async {
if (!_sessionShortNameRegExp.hasMatch(session)) {
throw FormatException("Session $session isn't correctly formatted");
}
// Generate initial soap envelope
final body = SoapService.buildBasicSOAPBody(
Urls.listeHoraireEtProf, username, password)
.buildDocument();
final operationContent = XmlBuilder();
// Add the content needed by the operation
operationContent.element("pSession", nest: () {
operationContent.text(session);
});
// Add the parameters needed inside the request.
body
.findAllElements(Urls.listeHoraireEtProf,
namespace: Urls.signetsOperationBase)
.first
.children
.add(operationContent.buildFragment());
final responseBody = await SoapService.sendSOAPRequest(
_httpClient, body, Urls.listeHoraireEtProf);
/// Build and return the list of CourseActivity
return responseBody
.findAllElements("HoraireActivite")
.map((node) => ScheduleActivity.fromXmlNode(node))
.toList();
}
}