-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathget_sessions_command.dart
38 lines (32 loc) · 1.3 KB
/
get_sessions_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
// 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/session.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 list of all the [Session] for the student ([username]).
class GetSessionsCommand implements Command<List<Session>> {
final SignetsAPIClient client;
final http.Client _httpClient;
final String username;
final String password;
GetSessionsCommand(this.client, this._httpClient,
{required this.username, required this.password});
@override
Future<List<Session>> execute() async {
// Generate initial soap envelope
final body = SoapService.buildBasicSOAPBody(
Urls.listSessionsOperation, username, password)
.buildDocument();
final responseBody = await SoapService.sendSOAPRequest(
_httpClient, body, Urls.listSessionsOperation);
/// Build and return the list of Session
return responseBody
.findAllElements("Trimestre")
.map((node) => Session.fromXmlNode(node))
.toList();
}
}