aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-22 03:54:59 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-22 03:54:59 +1000
commitd04771c7ef5cdab9554aa6aef506a39c8e2bd3d4 (patch)
tree919df0469bbd4bf6234b4ea07e0b59ee5e011f9a /src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
parent8499a98beeb556c16987fc375dbd7d05d6c27ab4 (diff)
downloadnotenoughupdates-d04771c7ef5cdab9554aa6aef506a39c8e2bd3d4.tar.gz
notenoughupdates-d04771c7ef5cdab9554aa6aef506a39c8e2bd3d4.tar.bz2
notenoughupdates-d04771c7ef5cdab9554aa6aef506a39c8e2bd3d4.zip
less scuffed profile viewer :)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
index 133619ae..05351629 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
@@ -27,24 +27,28 @@ public class HypixelApi {
private ExecutorService es = Executors.newCachedThreadPool();
public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer) {
- getHypixelApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer);
+ getHypixelApiAsync(apiKey, method, args, consumer, () -> {});
}
- public void getHypixelApiAsync(String urlS, Consumer<JsonObject> consumer) {
+ public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer, Runnable error) {
+ getHypixelApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer, error);
+ }
+
+ public void getHypixelApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
es.submit(() -> {
- consumer.accept(getHypixelApiSync(urlS));
+ try {
+ consumer.accept(getHypixelApiSync(urlS));
+ } catch(IOException e) {
+ error.run();
+ }
});
}
- public JsonObject getHypixelApiSync(String urlS) {
- URLConnection connection;
- try {
- URL url = new URL(urlS);
- connection = url.openConnection();
- connection.setConnectTimeout(3000);
- } catch(IOException e) {
- return null;
- }
+ public JsonObject getHypixelApiSync(String urlS) throws IOException {
+
+ URL url = new URL(urlS);
+ URLConnection connection = url.openConnection();
+ connection.setConnectTimeout(3000);
try(BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
@@ -56,8 +60,6 @@ public class HypixelApi {
JsonObject json = gson.fromJson(response, JsonObject.class);
return json;
- } catch(IOException e) {
- return null;
}
}