-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsignets_api_client.dart
171 lines (155 loc) · 6.07 KB
/
signets_api_client.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Dart imports:
import 'dart:io';
// Package imports:
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
// Project imports:
import 'package:notredame/features/app/signets-api/commands/authentificate_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_course_reviews_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_course_summary_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_courses_activities_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_courses_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_programs_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_schedule_activities_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_sessions_command.dart';
import 'package:notredame/features/app/signets-api/commands/get_student_info_command.dart';
import 'package:notredame/features/app/signets-api/models/course.dart';
import 'package:notredame/features/app/signets-api/models/course_activity.dart';
import 'package:notredame/features/app/signets-api/models/course_review.dart';
import 'package:notredame/features/app/signets-api/models/course_summary.dart';
import 'package:notredame/features/app/signets-api/models/profile_student.dart';
import 'package:notredame/features/app/signets-api/models/program.dart';
import 'package:notredame/features/app/signets-api/models/schedule_activity.dart';
import 'package:notredame/features/app/signets-api/models/session.dart';
/// A Wrapper for all calls to Signets API.
class SignetsAPIClient {
static const String tag = "SignetsApi";
static const String tagError = "$tag - Error";
final http.Client _httpClient;
SignetsAPIClient({http.Client? client})
: _httpClient = client ?? IOClient(HttpClient());
/// Expression to validate the format of a session short name (ex: A2020)
final RegExp _sessionShortNameRegExp = RegExp("^([A-É-H][0-9]{4})");
/// Expression to validate the format of a course (ex: MAT256-01)
final RegExp _courseGroupRegExp = RegExp("^([A-Z]{3}[0-9]{3}-[0-9]{2})");
/// Returns whether the user is logged in or not throught the SignetsAPI.
/// Deprecated('This function is deprecated in favor of `MonETSAPIClient.authenticate()`')
Future<bool> authenticate(
{required String username, required String password}) {
final command = AuthenticateCommand(this, _httpClient,
username: username, password: password);
return command.execute();
}
/// Call the SignetsAPI to get the courses activities for the [session] for
/// the student ([username]). By specifying [courseGroup] we can filter the
/// results to get only the activities for this course.
/// If the [startDate] and/or [endDate] are specified the results will contains
/// all the activities between these dates
Future<List<CourseActivity>> getCoursesActivities({
required String username,
required String password,
String session = "",
String courseGroup = "",
DateTime? startDate,
DateTime? endDate,
}) {
final command = GetCoursesActivitiesCommand(
this,
_httpClient,
_sessionShortNameRegExp,
_courseGroupRegExp,
username: username,
password: password,
session: session,
courseGroup: courseGroup,
startDate: startDate,
endDate: endDate,
);
return command.execute();
}
/// Call the SignetsAPI to get the courses activities for the [session] for
/// the student ([username]).
Future<List<ScheduleActivity>> getScheduleActivities({
required String username,
required String password,
String session = "",
}) {
final command = GetScheduleActivitiesCommand(
this,
_httpClient,
_sessionShortNameRegExp,
username: username,
password: password,
session: session,
);
return command.execute();
}
/// Call the SignetsAPI to get the courses of the student ([username]).
Future<List<Course>> getCourses({
required String username,
required String password,
}) {
final command = GetCoursesCommand(this, _httpClient,
username: username, password: password);
return command.execute();
}
/// Call the SignetsAPI to get all the evaluations (exams) and the summary
/// of [course] for the student ([username]).
Future<CourseSummary> getCourseSummary({
required String username,
required String password,
required Course course,
}) {
final command = GetCourseSummaryCommand(
this,
_httpClient,
username: username,
password: password,
course: course,
);
return command.execute();
}
/// Call the SignetsAPI to get the list of all the [Session] for the student ([username]).
Future<List<Session>> getSessions({
required String username,
required String password,
}) {
final command = GetSessionsCommand(this, _httpClient,
username: username, password: password);
return command.execute();
}
/// Call the SignetsAPI to get the [ProfileStudent] for the student.
Future<ProfileStudent> getStudentInfo({
required String username,
required String password,
}) {
final command = GetStudentInfoCommand(this, _httpClient,
username: username, password: password);
return command.execute();
}
/// Call the SignetsAPI to get the list of all the [Program] for the student ([username]).
Future<List<Program>> getPrograms({
required String username,
required String password,
}) {
final command = GetProgramsCommand(this, _httpClient,
username: username, password: password);
return command.execute();
}
/// Call the SignetsAPI to get the list of all [CourseReview] for the [session]
/// of the student ([username]).
Future<List<CourseReview>> getCourseReviews({
required String username,
required String password,
Session? session,
}) {
final command = GetCourseReviewsCommand(
this,
_httpClient,
username: username,
password: password,
session: session,
);
return command.execute();
}
}