diff --git a/src/main/java/api/.env b/src/main/java/api/.env new file mode 100644 index 00000000..af966f63 --- /dev/null +++ b/src/main/java/api/.env @@ -0,0 +1 @@ +alnrLy3TmebbdWaIHlKAWXKDH03brz6D \ No newline at end of file diff --git a/src/main/java/api/MongoGradeDataBase.java b/src/main/java/api/MongoGradeDataBase.java index 77e76548..c2c3cde4 100644 --- a/src/main/java/api/MongoGradeDataBase.java +++ b/src/main/java/api/MongoGradeDataBase.java @@ -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); + } } }