-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThothRawAPI.java
More file actions
68 lines (53 loc) · 2.89 KB
/
ThothRawAPI.java
File metadata and controls
68 lines (53 loc) · 2.89 KB
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
import com.google.gson.Gson;
import dtos.*;
import util.IRequest;
import java.text.MessageFormat;
import java.util.concurrent.CompletableFuture;
public class ThothRawAPI {
private static final String THOTH_URL = "https://adeetc.thothapp.com/api/v1";
private static final String THOTH_STUDENTS = "/students";
private static final String THOTH_STUDENT = "/students/{0, number, #}";
private static final String THOTH_TEACHERS = "/teachers";
private static final String THOTH_TEACHER = "/teachers/{0, number, #}";
private static final String THOTH_CLASS = "/classes/{0, number, #}";
private static final String THOTH_CLASSES = "/classes";
private static final String THOTH_CLASS_RESOURCES = "/classes/{0, number, #}/resources";
private static final String THOTH_CLASS_PARTICIPANTS = "/classes/{0, number, #}/participants";
private static final Gson JSON_CONVERTER = new Gson();
private IRequest req;
public ThothRawAPI(IRequest request) {
req = request;
}
public CompletableFuture<TeacherDto[]> getTeachers() {
return req.getBody(THOTH_URL.concat(THOTH_TEACHERS))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, TeachersDto.class).getTeachers());
}
public CompletableFuture<TeacherDto> getTeacher(int id) {
return req.getBody(MessageFormat.format(THOTH_URL + THOTH_TEACHER, id))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, TeacherDto.class));
}
public CompletableFuture<StudentDto[]> getStudents() {
return req.getBody(THOTH_URL.concat(THOTH_STUDENTS))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, StudentsDto.class).getStudents());
}
public CompletableFuture<StudentDto> getStudent(int id) {
return req.getBody(MessageFormat.format(THOTH_URL + THOTH_STUDENT, id))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, StudentDto.class));
}
public CompletableFuture<StudentDto[]> getStudentsForClass(int classId) {
return req.getBody(MessageFormat.format(THOTH_URL + THOTH_CLASS_PARTICIPANTS, classId))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, ClassParticipantsDto.class).getStudents());
}
public CompletableFuture<ClassDto[]> getClasses() {
return req.getBody(THOTH_URL.concat(THOTH_CLASSES))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, ClassesDto.class).getClasses());
}
public CompletableFuture<ClassDto> getClass(int id) {
return req.getBody(MessageFormat.format(THOTH_URL + THOTH_CLASS, id))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, ClassDto.class));
}
public CompletableFuture<ResourceDto[]> getClassResources(int id) {
return req.getBody(MessageFormat.format(THOTH_URL + THOTH_CLASS_RESOURCES, id))
.thenApply(resp -> JSON_CONVERTER.fromJson(resp, ClassResourcesDto.class).getClassResources());
}
}