feat: refactor city fecth

This commit is contained in:
Martin Eyben 2024-11-19 18:10:22 +01:00
parent ebf840a73d
commit d263a3b68f

View File

@ -7,6 +7,7 @@ import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import eirb.pg203.utils.JSONFetcher;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -28,17 +29,7 @@ public class City {
) )
).toURL(); ).toURL();
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); return JSONFetcher.fetch(url);
conn.setRequestMethod("GET");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()))) {
for (String line; (line = reader.readLine()) != null; ) {
result.append(line);
}
}
return new JSONObject(result.toString());
} }
private static Coords getCoordsFromName(String cityName) throws IOException { private static Coords getCoordsFromName(String cityName) throws IOException {