forked from runelite/runelite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor xp updater requests to use generic request sender method
- Loading branch information
Showing
1 changed file
with
23 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2018, Adam <[email protected]> | ||
* Copyright (c) 2020, Alexsuperfly <[email protected]> | ||
* Copyright (c) 2020, Psikoi <https://github.com/psikoi> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -43,7 +44,6 @@ | |
import okhttp3.Call; | ||
import okhttp3.Callback; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
|
@@ -108,7 +108,7 @@ else if (state == GameState.LOGIN_SCREEN) | |
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 void onGameTick(GameTick gameTick) | |
} | ||
} | ||
|
||
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 @@ private void sendUpdateRequest(String username) | |
.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 void onResponse(Call call, Response response) | |
.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(); | ||
} | ||
}); | ||
} | ||
} |