http-api: share a common gson instance
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.http.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
@@ -37,6 +38,7 @@ public class RuneliteAPI
|
||||
private static final Logger logger = LoggerFactory.getLogger(RuneliteAPI.class);
|
||||
|
||||
public static final OkHttpClient CLIENT = new OkHttpClient();
|
||||
public static final Gson GSON = new Gson();
|
||||
|
||||
private static final String BASE = "https://api.runelite.net/runelite-";
|
||||
private static final String WSBASE = "wss://api.runelite.net/runelite-";
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.http.api.account;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -40,8 +39,6 @@ public class LoginClient
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoginClient.class);
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public OAuthResponse login() throws IOException
|
||||
{
|
||||
HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder()
|
||||
@@ -61,7 +58,7 @@ public class LoginClient
|
||||
try (ResponseBody body = response.body())
|
||||
{
|
||||
InputStream in = body.byteStream();
|
||||
return gson.fromJson(new InputStreamReader(in), OAuthResponse.class);
|
||||
return RuneliteAPI.GSON.fromJson(new InputStreamReader(in), OAuthResponse.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.http.api.hiscore;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -40,8 +39,6 @@ public class HiscoreClient
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HiscoreClient.class);
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public HiscoreResult lookup(String username) throws IOException
|
||||
{
|
||||
HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder()
|
||||
@@ -61,7 +58,7 @@ public class HiscoreClient
|
||||
try (ResponseBody body = response.body())
|
||||
{
|
||||
InputStream in = body.byteStream();
|
||||
return gson.fromJson(new InputStreamReader(in), HiscoreResult.class);
|
||||
return RuneliteAPI.GSON.fromJson(new InputStreamReader(in), HiscoreResult.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.http.api.xtea;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.io.IOException;
|
||||
import net.runelite.http.api.RuneliteAPI;
|
||||
import okhttp3.HttpUrl;
|
||||
@@ -41,8 +40,6 @@ public class XteaClient
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(XteaClient.class);
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public Response submit(int revision, int region, int[] keys) throws IOException
|
||||
{
|
||||
XteaRequest xteaRequest = new XteaRequest();
|
||||
@@ -54,7 +51,7 @@ public class XteaClient
|
||||
|
||||
xteaRequest.addKey(xteaKey);
|
||||
|
||||
String json = gson.toJson(xteaRequest);
|
||||
String json = RuneliteAPI.GSON.toJson(xteaRequest);
|
||||
|
||||
HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("xtea");
|
||||
|
||||
Reference in New Issue
Block a user