Skip to content
Open

3b #104

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alnrLy3TmebbdWaIHlKAWXKDH03brz6D
36 changes: 28 additions & 8 deletions src/main/java/api/MongoGradeDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,33 @@ public Team getMyTeam() {
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
.build();

final Response response;
final JSONObject responseBody;

// TODO Task 3b: Implement the logic to get the team information
// HINT 1: Look at the formTeam method to get an idea on how to parse the response
// HINT 2: You may find it useful to just initially print the contents of the JSON
// then work on the details of how to parse it.
return null;

try {
final Response response = client.newCall(request).execute();
final JSONObject responseBody = new JSONObject(response.body().string());

if (responseBody.getInt(STATUS_CODE) == SUCCESS_CODE) {
JSONObject team = responseBody.getJSONObject("team");
String team_name = team.getString("name");
JSONArray team_members = team.getJSONArray("members");

String[] temp = new String[team_members.length()];

for (int i = 0; i < team_members.length(); i++) {
temp[i] = team_members.getString(i);
}

Team t = new Team(team_name, temp);

return t;

}
else {
throw new RuntimeException(responseBody.getString(MESSAGE));
}
}
catch (IOException | JSONException event) {
throw new RuntimeException(event);
}
}
}