From 048fcd3aceef10dca2c3f33158706897d68b3bab Mon Sep 17 00:00:00 2001 From: rohit Date: Thu, 19 Oct 2023 23:04:51 +0800 Subject: [PATCH] Remove API Class --- META-INF/MANIFEST.MF | 3 ++ .../controllers/ModulePlannerController.java | 15 ------ src/main/java/seedu/duke/models/Api.java | 48 ------------------- .../java/seedu/duke/models/JsonFormatter.java | 39 --------------- src/test/java/seedu/duke/ApiTest.java | 16 ------- 5 files changed, 3 insertions(+), 118 deletions(-) create mode 100644 META-INF/MANIFEST.MF delete mode 100644 src/main/java/seedu/duke/models/Api.java delete mode 100644 src/main/java/seedu/duke/models/JsonFormatter.java delete mode 100644 src/test/java/seedu/duke/ApiTest.java diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..e26fd17aea --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: seedu.duke.Duke + diff --git a/src/main/java/seedu/duke/controllers/ModulePlannerController.java b/src/main/java/seedu/duke/controllers/ModulePlannerController.java index 192d37639f..585561d4b2 100644 --- a/src/main/java/seedu/duke/controllers/ModulePlannerController.java +++ b/src/main/java/seedu/duke/controllers/ModulePlannerController.java @@ -1,16 +1,11 @@ package seedu.duke.controllers; -import org.json.simple.JSONObject; import seedu.duke.CompletePreqs; import seedu.duke.ModuleList; import seedu.duke.models.Major; import seedu.duke.models.Student; import seedu.duke.views.CommandLineView; import seedu.duke.utils.Parser; -import seedu.duke.models.Api; -import seedu.duke.views.ModuleInfo; - -import java.net.URISyntaxException; import java.io.InvalidObjectException; import java.util.ArrayList; @@ -91,16 +86,6 @@ public void start() { computePace(words, creditsLeft); break; } - case "info": { - String moduleCode = words[1]; - try { - JSONObject moduleInfo = Api.getModuleInfo(moduleCode); - ModuleInfo.printModule(moduleInfo); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - break; - } case "major": { updateMajor(words[1]); break; diff --git a/src/main/java/seedu/duke/models/Api.java b/src/main/java/seedu/duke/models/Api.java deleted file mode 100644 index 66665466c9..0000000000 --- a/src/main/java/seedu/duke/models/Api.java +++ /dev/null @@ -1,48 +0,0 @@ -package seedu.duke.models; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import seedu.duke.views.ModuleInfo; - - -public class Api { - public static JSONObject getModuleInfo(String moduleCode) throws URISyntaxException { - String url = "https://api.nusmods.com/v2/2023-2024/modules/" + moduleCode + ".json"; - HttpClient client = HttpClient.newHttpClient(); - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - try { - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - int statusCode = response.statusCode(); - String responseBody = response.body(); - JSONParser parser = new JSONParser(); - JSONObject moduleInfo = (JSONObject) parser.parse(responseBody); - ModuleInfo.printModule(moduleInfo); - return moduleInfo; - // Now you can access individual properties in the JSON - // String preclusionRule = (String) jsonObject.get("preclusionRule"); - // String additionalInformation = (String) jsonObject.get("additionalInformation"); - // JSONArray aliasesArray = (JSONArray) jsonObject.get("aliases"); - // System.out.println(JsonFormatter.formatJson(responseBody)); - // System.out.println(preclusionRule); - // System.out.println(additionalInformation); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - -} - // public static String getModuleName(JSONObject module) { -// return (String) module.get("moduleName"); -// } - - diff --git a/src/main/java/seedu/duke/models/JsonFormatter.java b/src/main/java/seedu/duke/models/JsonFormatter.java deleted file mode 100644 index e70f48e661..0000000000 --- a/src/main/java/seedu/duke/models/JsonFormatter.java +++ /dev/null @@ -1,39 +0,0 @@ -package seedu.duke.models; - -public class JsonFormatter { - public static String formatJson(String jsonString) { - int indentLevel = 0; - StringBuilder formattedJson = new StringBuilder(); - - for (char charFromJson : jsonString.toCharArray()) { - if (charFromJson == '{' || charFromJson == '[') { - indentLevel++; - formattedJson.append(charFromJson).append("\n").append(getIndentString(indentLevel)); - } else if (charFromJson == '}' || charFromJson == ']') { - indentLevel--; - formattedJson.append("\n").append(getIndentString(indentLevel)).append(charFromJson); - } else if (charFromJson == ',') { - formattedJson.append(charFromJson).append("\n").append(getIndentString(indentLevel)); - } else { - formattedJson.append(charFromJson); - } - } - - return formattedJson.toString(); - } - - private static String getIndentString(int indentLevel) { - StringBuilder indentString = new StringBuilder(); - for (int i = 0; i < indentLevel; i++) { - indentString.append("\t"); // Use tabs for indentation (you can change this to spaces if desired) - } - return indentString.toString(); - } -} - - - - - - - diff --git a/src/test/java/seedu/duke/ApiTest.java b/src/test/java/seedu/duke/ApiTest.java deleted file mode 100644 index bc80264b46..0000000000 --- a/src/test/java/seedu/duke/ApiTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package seedu.duke; - -import org.json.simple.JSONObject; -import seedu.duke.models.Api; -import seedu.duke.views.ModuleInfo; - -public class ApiTest { - public static void main(String[] args) throws Exception { - // test setup - String moduleCode = "CS2113"; - JSONObject moduleInfo = Api.getModuleInfo(moduleCode); - ModuleInfo.printModule(moduleInfo); - // more tests... - System.out.println("All tests passed"); - } -}