From e09e8bcdc718a08d57abea55339ecbbb082d9c8a Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 20 Aug 2022 02:25:39 +0200 Subject: adding support for grabbing the api key from other mods: neu, cow, dsm, dg, st, soopy and sbe --- .../java/at/hannibal2/skyhanni/utils/APIUtil.kt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt index c321cf2d5..b66120f82 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt @@ -8,6 +8,11 @@ import org.apache.http.impl.client.HttpClientBuilder import org.apache.http.impl.client.HttpClients import org.apache.http.message.BasicHeader import org.apache.http.util.EntityUtils +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets object APIUtil { @@ -27,7 +32,7 @@ object APIUtil { ) .useSystemProperties() - fun getJSONResponse(urlString: String): JsonObject { + fun getJSONResponse(urlString: String, silentError: Boolean = false): JsonObject { val client = builder.build() try { client.execute(HttpGet(urlString)).use { response -> @@ -37,12 +42,20 @@ object APIUtil { return parser.parse(retSrc) as JsonObject } } - } catch (ex: Throwable) { - ex.printStackTrace() - LorenzUtils.error("SkyHanni ran into an ${ex::class.simpleName ?: "error"} whilst fetching a resource. See logs for more details.") + } catch (throwable: Throwable) { + if (silentError) { + throw throwable + } else { + throwable.printStackTrace() + LorenzUtils.error("SkyHanni ran into an ${throwable::class.simpleName ?: "error"} whilst fetching a resource. See logs for more details.") + } } finally { client.close() } return JsonObject() } + + fun readFile(file: File): BufferedReader { + return BufferedReader(InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8)) + } } \ No newline at end of file -- cgit