From 1778d5d79bd912dac55517ae65b7b71f9cb70c48 Mon Sep 17 00:00:00 2001 From: Psikoi Date: Tue, 28 Apr 2020 17:52:26 +0100 Subject: [PATCH] Refactor xp updater requests to use generic request sender method --- .../plugins/xpupdater/XpUpdaterPlugin.java | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xpupdater/XpUpdaterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/xpupdater/XpUpdaterPlugin.java index 8e45584edf..5af93e1aaa 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xpupdater/XpUpdaterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xpupdater/XpUpdaterPlugin.java @@ -1,6 +1,7 @@ /* * Copyright (c) 2018, Adam * Copyright (c) 2020, Alexsuperfly + * Copyright (c) 2020, Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +44,6 @@ import net.runelite.http.api.RuneLiteAPI; import okhttp3.Call; import okhttp3.Callback; import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -108,7 +108,7 @@ public class XpUpdaterPlugin extends Plugin if (Math.abs(totalXp - lastXp) > XP_THRESHOLD) { log.debug("Submitting update for {}", local.getName()); - sendUpdateRequest(local.getName()); + update(local.getName()); lastXp = totalXp; } } @@ -124,10 +124,9 @@ public class XpUpdaterPlugin extends Plugin } } - private void sendUpdateRequest(String username) + private void update(String username) { String reformedUsername = username.replace(" ", "_"); - OkHttpClient httpClient = RuneLiteAPI.CLIENT; if (config.cml()) { @@ -145,20 +144,7 @@ public class XpUpdaterPlugin extends Plugin .url(url) .build(); - httpClient.newCall(request).enqueue(new Callback() - { - @Override - public void onFailure(Call call, IOException e) - { - log.warn("Error submitting CML update, caused by {}.", e.getMessage()); - } - - @Override - public void onResponse(Call call, Response response) - { - response.close(); - } - }); + sendRequest("CrystalMathLabs", request); } if (config.templeosrs()) @@ -176,20 +162,25 @@ public class XpUpdaterPlugin extends Plugin .url(url) .build(); - httpClient.newCall(request).enqueue(new Callback() - { - @Override - public void onFailure(Call call, IOException e) - { - log.warn("Error submitting TempleOSRS update, caused by {}.", e.getMessage()); - } - - @Override - public void onResponse(Call call, Response response) - { - response.close(); - } - }); + sendRequest("TempleOSRS", request); } } + + private static void sendRequest(String platform, Request request) + { + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + log.warn("Error submitting {} update, caused by {}.", platform, e.getMessage()); + } + + @Override + public void onResponse(Call call, Response response) + { + response.close(); + } + }); + } }