forked from nullp2ike/tutorid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutor.java
More file actions
81 lines (65 loc) · 2.56 KB
/
Tutor.java
File metadata and controls
81 lines (65 loc) · 2.56 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
69
70
71
72
73
74
75
76
77
78
79
80
81
package utils.domain;
import java.util.ArrayList;
import java.util.List;
import io.restassured.filter.cookie.CookieFilter;
import io.restassured.response.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import requests.Login;
import requests.Logout;
import requests.Profile;
import utils.Setup;
public class Tutor {
private final CookieFilter cookieFilter;
private final String nickname;
private final String email;
private final List publicLocations;
private final List privateLocations;
private final List onlineLocations;
public Tutor(final Response response, final CookieFilter cookieFilter){
final JSONObject responseObject = new JSONObject(response.body().asString()).getJSONObject("data");
this.nickname = responseObject.getString("tutorId");
this.email = responseObject.getString("email");
this.cookieFilter = cookieFilter;
this.publicLocations = parseLocations(responseObject.getJSONArray("publicLocations"));
this.privateLocations = parseLocations(responseObject.getJSONArray("privateLocations"));
this.onlineLocations = parseLocations(responseObject.getJSONArray("onlineLocations"));
}
public CookieFilter getCookieFilter() {
return this.cookieFilter;
}
public String getNickname() {
return this.nickname;
}
public String getEmail() {
return this.email;
}
public JSONObject profile(){
return new JSONObject(new Profile().get(this.nickname, this.cookieFilter).getBody().asString());
}
public Tutor login(){
return new Login().tutor(this.nickname, Setup.defaultPassword);
}
public Response logout(){
return new Logout().logout(this.cookieFilter);
}
private List<Location> parseLocations(final JSONArray responseLocations){
final List locations = new ArrayList<>();
for (int i = 0; i <responseLocations.length(); i++) {
final int id = responseLocations.getJSONObject(i).getInt("id");
final String type = responseLocations.getJSONObject(i).getString("type");
final Location location = new Location(id, type);
locations.add(location);
}
return locations;
}
public List<Location> getPublicLocations() {
return this.publicLocations;
}
public List<Location> getPrivateLocations() {
return this.privateLocations;
}
public List<Location> getOnlineLocations() {
return onlineLocations;
}
}