Clean up httpapi a bit
This commit is contained in:
@@ -37,7 +37,6 @@ import org.w3c.dom.Document;
|
|||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
@@ -52,26 +51,28 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class RuneLiteAPI
|
public class RuneLiteAPI
|
||||||
{
|
{
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class);
|
||||||
|
|
||||||
|
public static final String RUNELITE_AUTH = "RUNELITE-AUTH";
|
||||||
|
|
||||||
|
public static final OkHttpClient CLIENT;
|
||||||
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
private static final String BASE = "https://api.runelite.net";
|
||||||
|
private static final String WSBASE = "https://api.runelite.net/ws";
|
||||||
|
private static final String STATICBASE = "https://static.runelite.net";
|
||||||
|
|
||||||
|
private static final String OPENOSRS_BASE = /*"https://api.openosrs.com*/ "https://api.runelitepl.us";
|
||||||
|
private static final String OPENOSRS_SESSION = "https://session.openosrs.com";
|
||||||
|
private static final String MAVEN_METADATA = "http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
|
||||||
|
|
||||||
|
private static final Properties properties = new Properties();
|
||||||
|
private static String userAgent;
|
||||||
|
|
||||||
private static String version;
|
private static String version;
|
||||||
private static String upstreamVersion;
|
private static String upstreamVersion;
|
||||||
private static int rsVersion;
|
private static int rsVersion;
|
||||||
|
|
||||||
public static final String RUNELITE_AUTH = "RUNELITE-AUTH";
|
|
||||||
public static final OkHttpClient CLIENT;
|
|
||||||
public static final OkHttpClient RLP_CLIENT;
|
|
||||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class);
|
|
||||||
private static final String BASE = "https://api.runelite.net";
|
|
||||||
private static final String OPENOSRS_BASE = /*"https://api.openosrs.com*/ "https://api.runelitepl.us";
|
|
||||||
private static final String OPENOSRS_SESSION = "https://session.openosrs.com";
|
|
||||||
private static final String WSBASE = "https://api.runelite.net/ws";
|
|
||||||
private static final String STATICBASE = "https://static.runelite.net";
|
|
||||||
private static final String MAVEN_METADATA =
|
|
||||||
"http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
|
|
||||||
private static final Properties properties = new Properties();
|
|
||||||
private static String rlUserAgent;
|
|
||||||
private static String openosrsUserAgent;
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -80,11 +81,11 @@ public class RuneLiteAPI
|
|||||||
properties.load(in);
|
properties.load(in);
|
||||||
|
|
||||||
version = properties.getProperty("runelite.version");
|
version = properties.getProperty("runelite.version");
|
||||||
String rlpCommit = properties.getProperty("runelite.commit");
|
String commit = properties.getProperty("runelite.commit");
|
||||||
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
|
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
|
||||||
|
|
||||||
openosrsUserAgent = "openosrs/" + version + "-" + rlpCommit + (dirty ? "+" : "");
|
userAgent = "OpenOSRS/" + version + "-" + commit + (dirty ? "+" : "");
|
||||||
rlUserAgent = "openosrs/" + version;
|
|
||||||
rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
|
rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
|
||||||
|
|
||||||
parseMavenVersion();
|
parseMavenVersion();
|
||||||
@@ -101,8 +102,6 @@ public class RuneLiteAPI
|
|||||||
|
|
||||||
CLIENT = new OkHttpClient.Builder()
|
CLIENT = new OkHttpClient.Builder()
|
||||||
.pingInterval(30, TimeUnit.SECONDS)
|
.pingInterval(30, TimeUnit.SECONDS)
|
||||||
.connectTimeout(8655, TimeUnit.MILLISECONDS)
|
|
||||||
.writeTimeout(8655, TimeUnit.MILLISECONDS)
|
|
||||||
.addNetworkInterceptor(new Interceptor()
|
.addNetworkInterceptor(new Interceptor()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -110,25 +109,7 @@ public class RuneLiteAPI
|
|||||||
{
|
{
|
||||||
Request userAgentRequest = chain.request()
|
Request userAgentRequest = chain.request()
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.header("User-Agent", rlUserAgent)
|
.header("User-Agent", userAgent)
|
||||||
.build();
|
|
||||||
return chain.proceed(userAgentRequest);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
RLP_CLIENT = new OkHttpClient.Builder()
|
|
||||||
.pingInterval(30, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(5655, TimeUnit.MILLISECONDS)
|
|
||||||
.connectTimeout(2655, TimeUnit.MILLISECONDS)
|
|
||||||
.addNetworkInterceptor(new Interceptor()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Response intercept(Chain chain) throws IOException
|
|
||||||
{
|
|
||||||
Request userAgentRequest = chain.request()
|
|
||||||
.newBuilder()
|
|
||||||
.header("User-Agent", openosrsUserAgent)
|
|
||||||
.build();
|
.build();
|
||||||
return chain.proceed(userAgentRequest);
|
return chain.proceed(userAgentRequest);
|
||||||
}
|
}
|
||||||
@@ -136,7 +117,7 @@ public class RuneLiteAPI
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl getopenosrsSessionBase()
|
public static HttpUrl getSessionBase()
|
||||||
{
|
{
|
||||||
return HttpUrl.parse(OPENOSRS_SESSION);
|
return HttpUrl.parse(OPENOSRS_SESSION);
|
||||||
}
|
}
|
||||||
@@ -153,7 +134,7 @@ public class RuneLiteAPI
|
|||||||
return HttpUrl.parse(BASE + "/runelite-" + getVersion());
|
return HttpUrl.parse(BASE + "/runelite-" + getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl getPlusApiBase()
|
public static HttpUrl getOpenOSRSApiBase()
|
||||||
{
|
{
|
||||||
return HttpUrl.parse(OPENOSRS_BASE + "/http-service-" + getRlpVersion());
|
return HttpUrl.parse(OPENOSRS_BASE + "/http-service-" + getRlpVersion());
|
||||||
}
|
}
|
||||||
@@ -206,7 +187,7 @@ public class RuneLiteAPI
|
|||||||
byte[] chunk = new byte[4096];
|
byte[] chunk = new byte[4096];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
URLConnection conn = toDownload.openConnection();
|
URLConnection conn = toDownload.openConnection();
|
||||||
conn.setRequestProperty("User-Agent", openosrsUserAgent);
|
conn.setRequestProperty("User-Agent", userAgent);
|
||||||
stream = conn.getInputStream();
|
stream = conn.getInputStream();
|
||||||
|
|
||||||
while ((bytesRead = stream.read(chunk)) > 0)
|
while ((bytesRead = stream.read(chunk)) > 0)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class AnimationClient
|
|||||||
{
|
{
|
||||||
String json = RuneLiteAPI.GSON.toJson(animationRequest);
|
String json = RuneLiteAPI.GSON.toJson(animationRequest);
|
||||||
|
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("animation")
|
.addPathSegment("animation")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class AnimationClient
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
logger.debug("animation response " + response.code());
|
logger.debug("animation response " + response.code());
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ public class AnimationClient
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
RuneLiteAPI.RLP_CLIENT.newCall(request).enqueue(new Callback()
|
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call call, IOException e)
|
public void onFailure(Call call, IOException e)
|
||||||
@@ -103,7 +103,7 @@ public class AnimationClient
|
|||||||
|
|
||||||
public List<AnimationKey> get() throws IOException
|
public List<AnimationKey> get() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("animation")
|
.addPathSegment("animation")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ public class AnimationClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
InputStream in = response.body().byteStream();
|
InputStream in = response.body().byteStream();
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
@@ -128,7 +128,7 @@ public class AnimationClient
|
|||||||
|
|
||||||
public AnimationKey get(int npcid) throws IOException
|
public AnimationKey get(int npcid) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("animation")
|
.addPathSegment("animation")
|
||||||
.addPathSegment(Integer.toString(npcid))
|
.addPathSegment(Integer.toString(npcid))
|
||||||
.build();
|
.build();
|
||||||
@@ -137,7 +137,7 @@ public class AnimationClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
InputStream in = response.body().byteStream();
|
InputStream in = response.body().byteStream();
|
||||||
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), AnimationKey.class);
|
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), AnimationKey.class);
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ public class ChatClient
|
|||||||
throw new IOException("Layout " + layout + " is not valid!");
|
throw new IOException("Layout " + layout + " is not valid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
.addPathSegment("layout")
|
.addPathSegment("layout")
|
||||||
.addQueryParameter("name", username)
|
.addQueryParameter("name", username)
|
||||||
@@ -287,7 +287,7 @@ public class ChatClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
return response.isSuccessful();
|
return response.isSuccessful();
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ public class ChatClient
|
|||||||
|
|
||||||
public String getLayout(String username) throws IOException
|
public String getLayout(String username) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
.addPathSegment("layout")
|
.addPathSegment("layout")
|
||||||
.addQueryParameter("name", username)
|
.addQueryParameter("name", username)
|
||||||
@@ -328,7 +328,7 @@ public class ChatClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
if (!response.isSuccessful())
|
if (!response.isSuccessful())
|
||||||
{
|
{
|
||||||
@@ -353,7 +353,7 @@ public class ChatClient
|
|||||||
|
|
||||||
public House[] getHosts(int world, String location) throws IOException
|
public House[] getHosts(int world, String location) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
.addPathSegment("hosts")
|
.addPathSegment("hosts")
|
||||||
.addQueryParameter("world", Integer.toString(world))
|
.addQueryParameter("world", Integer.toString(world))
|
||||||
@@ -364,7 +364,7 @@ public class ChatClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
if (!response.isSuccessful())
|
if (!response.isSuccessful())
|
||||||
{
|
{
|
||||||
@@ -411,7 +411,7 @@ public class ChatClient
|
|||||||
|
|
||||||
public boolean submitHost(int world, String location, House house) throws IOException
|
public boolean submitHost(int world, String location, House house) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
.addPathSegment("hosts")
|
.addPathSegment("hosts")
|
||||||
.addQueryParameter("world", Integer.toString(world))
|
.addQueryParameter("world", Integer.toString(world))
|
||||||
@@ -431,7 +431,7 @@ public class ChatClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
return response.isSuccessful();
|
return response.isSuccessful();
|
||||||
}
|
}
|
||||||
@@ -439,7 +439,7 @@ public class ChatClient
|
|||||||
|
|
||||||
public boolean removeHost(int world, String location, House house) throws IOException
|
public boolean removeHost(int world, String location, House house) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
.addPathSegment("hosts")
|
.addPathSegment("hosts")
|
||||||
.addQueryParameter("world", Integer.toString(world))
|
.addQueryParameter("world", Integer.toString(world))
|
||||||
@@ -460,7 +460,7 @@ public class ChatClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
{
|
{
|
||||||
return response.isSuccessful();
|
return response.isSuccessful();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class XteaClient
|
|||||||
{
|
{
|
||||||
String json = RuneLiteAPI.GSON.toJson(xteaRequest);
|
String json = RuneLiteAPI.GSON.toJson(xteaRequest);
|
||||||
|
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("xtea")
|
.addPathSegment("xtea")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class XteaClient
|
|||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
RuneLiteAPI.RLP_CLIENT.newCall(request).enqueue(new Callback()
|
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call call, IOException e)
|
public void onFailure(Call call, IOException e)
|
||||||
@@ -91,7 +91,7 @@ public class XteaClient
|
|||||||
|
|
||||||
public List<XteaKey> get() throws IOException
|
public List<XteaKey> get() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("xtea")
|
.addPathSegment("xtea")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public class XteaClient
|
|||||||
|
|
||||||
public XteaKey get(int region) throws IOException
|
public XteaKey get(int region) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
||||||
.addPathSegment("xtea")
|
.addPathSegment("xtea")
|
||||||
.addPathSegment(Integer.toString(region))
|
.addPathSegment(Integer.toString(region))
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user