/
eclass_api_example.dart
76 lines (66 loc) · 1.89 KB
/
eclass_api_example.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
import 'package:eclass_api/eclass_api.dart' as eclass;
Future<void> main() async {
// Creating an instance of: EclassUser...
final user = eclass.User(instituteId: "instituteId");
// Institute: ${await user.institute}.
// Getting institute's info
final info = await user.getInfo();
print(info.toString());
// Logging in https://eclass.${user.instituteId}.gr...
try {
await user.login(username: 'username', password: 'password');
} on Exception {
// Handle failed login request
}
// Checking if token is expired...
if (await user.isTokenExpired) {
// Token is expired
} else {
// Token is valid
}
// Getting user's messages...
final messages = await user.getMessages();
// Messages:
for (var message in messages) {
print(message.toString());
}
// Getting user's course's announcements...
final announcements = await user.getAnnouncements(courseId: 'courseId');
// Announcements:
for (final announcement in announcements) {
print(announcement.toString());
}
// Getting user's portfolio courses and tools...
final portfolio = await user.getPortfolio();
// Portfolio Courses:
for (var course in portfolio.courses) {
print(course.toString());
}
// Portfolio Tools:
for (var tool in portfolio.tools) {
print(tool.toString());
}
// Portfolio Tools:
for (var profileTool in portfolio.profileTools) {
print(profileTool.toString());
}
// Getting user's registered courses...
final courses = await user.getCourses();
// Courses:
for (var course in courses) {
print(course.toString());
}
// Getting course's tools...
final tools = await user.getTools(courseId: 'courseId');
// Tools:
for (var tool in tools) {
print(tool.toString());
}
// Logging out of https://eclass.${user.instituteId}.gr...
try {
await user.logout();
// Logged out
} on Exception {
// Handle failed logout request
}
}