http-api: share a common http client
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ public class RuneliteAPI
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RuneliteAPI.class);
|
private static final Logger logger = LoggerFactory.getLogger(RuneliteAPI.class);
|
||||||
|
|
||||||
|
public static final OkHttpClient CLIENT = new OkHttpClient();
|
||||||
|
|
||||||
private static final String BASE = "https://api.runelite.net/runelite-";
|
private static final String BASE = "https://api.runelite.net/runelite-";
|
||||||
private static final String WSBASE = "wss://api.runelite.net/runelite-";
|
private static final String WSBASE = "wss://api.runelite.net/runelite-";
|
||||||
private static final Properties properties = new Properties();
|
private static final Properties properties = new Properties();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import net.runelite.http.api.RuneliteAPI;
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
@@ -41,7 +40,6 @@ public class LoginClient
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LoginClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(LoginClient.class);
|
||||||
|
|
||||||
private final OkHttpClient client = new OkHttpClient();
|
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
public OAuthResponse login() throws IOException
|
public OAuthResponse login() throws IOException
|
||||||
@@ -58,7 +56,7 @@ public class LoginClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
|
|
||||||
try (ResponseBody body = response.body())
|
try (ResponseBody body = response.body())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import net.runelite.http.api.RuneliteAPI;
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
@@ -41,7 +40,6 @@ public class HiscoreClient
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(HiscoreClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(HiscoreClient.class);
|
||||||
|
|
||||||
private final OkHttpClient client = new OkHttpClient();
|
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
public HiscoreResult lookup(String username) throws IOException
|
public HiscoreResult lookup(String username) throws IOException
|
||||||
@@ -58,7 +56,7 @@ public class HiscoreClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
|
|
||||||
try (ResponseBody body = response.body())
|
try (ResponseBody body = response.body())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import java.io.IOException;
|
|||||||
import net.runelite.http.api.RuneliteAPI;
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
@@ -42,7 +41,6 @@ public class XteaClient
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(XteaClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(XteaClient.class);
|
||||||
|
|
||||||
private final OkHttpClient client = new OkHttpClient();
|
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
public Response submit(int revision, int region, int[] keys) throws IOException
|
public Response submit(int revision, int region, int[] keys) throws IOException
|
||||||
@@ -70,6 +68,6 @@ public class XteaClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return client.newCall(request).execute();
|
return RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ package net.runelite.http.service.hiscore;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||||
import net.runelite.http.api.hiscore.Skill;
|
import net.runelite.http.api.hiscore.Skill;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
@@ -41,7 +41,6 @@ public class HiscoreService
|
|||||||
{
|
{
|
||||||
private static final HttpUrl RUNESCAPE_HISCORE_SERVICE = HttpUrl.parse("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws");
|
private static final HttpUrl RUNESCAPE_HISCORE_SERVICE = HttpUrl.parse("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws");
|
||||||
|
|
||||||
private final OkHttpClient client = new OkHttpClient();
|
|
||||||
private HttpUrl url = RUNESCAPE_HISCORE_SERVICE;
|
private HttpUrl url = RUNESCAPE_HISCORE_SERVICE;
|
||||||
|
|
||||||
public HiscoreResult lookup(String username) throws IOException, URISyntaxException
|
public HiscoreResult lookup(String username) throws IOException, URISyntaxException
|
||||||
@@ -53,7 +52,7 @@ public class HiscoreService
|
|||||||
.url(builder.build())
|
.url(builder.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
String responseStr;
|
String responseStr;
|
||||||
|
|
||||||
try (ResponseBody body = response.body())
|
try (ResponseBody body = response.body())
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ import java.net.URISyntaxException;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import net.runelite.http.api.worlds.World;
|
import net.runelite.http.api.worlds.World;
|
||||||
import net.runelite.http.api.worlds.WorldResult;
|
import net.runelite.http.api.worlds.WorldResult;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
@@ -41,7 +41,6 @@ public class WorldsService
|
|||||||
{
|
{
|
||||||
private static final HttpUrl WORLD_URL = HttpUrl.parse("http://www.runescape.com/g=oldscape/slr.ws?order=LPWM");
|
private static final HttpUrl WORLD_URL = HttpUrl.parse("http://www.runescape.com/g=oldscape/slr.ws?order=LPWM");
|
||||||
|
|
||||||
private final OkHttpClient client = new OkHttpClient();
|
|
||||||
private HttpUrl url = WORLD_URL;
|
private HttpUrl url = WORLD_URL;
|
||||||
|
|
||||||
public WorldResult listWorlds() throws IOException, URISyntaxException
|
public WorldResult listWorlds() throws IOException, URISyntaxException
|
||||||
@@ -50,7 +49,7 @@ public class WorldsService
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
byte[] b;
|
byte[] b;
|
||||||
|
|
||||||
try (ResponseBody body = response.body())
|
try (ResponseBody body = response.body())
|
||||||
|
|||||||
Reference in New Issue
Block a user