From 66cd5391904f2bcc0f27cc20f1a692df3f1a80fe Mon Sep 17 00:00:00 2001 From: zeruth Date: Fri, 7 Jun 2019 01:32:05 -0400 Subject: [PATCH] Various Adds http-api for our session service Also fixes HA values, for some reason GE values arent working, will look into. --- RuneLitePlus/pom.xml | 2 +- http-api/pom.xml | 126 +++++++++ .../net/runelite/http/api/RuneLiteAPI.java | 167 +++++++++++ .../http/api/account/AccountClient.java | 123 +++++++++ .../http/api/account/OAuthResponse.java | 53 ++++ .../net/runelite/http/api/cache/Cache.java | 104 +++++++ .../runelite/http/api/cache/CacheArchive.java | 97 +++++++ .../runelite/http/api/cache/CacheIndex.java | 85 ++++++ .../runelite/http/api/chat/ChatClient.java | 261 ++++++++++++++++++ .../java/net/runelite/http/api/chat/Task.java | 36 +++ .../http/api/examine/ExamineClient.java | 91 ++++++ .../runelite/http/api/feed/FeedClient.java | 70 +++++ .../net/runelite/http/api/feed/FeedItem.java | 42 +++ .../runelite/http/api/feed/FeedItemType.java | 32 +++ .../runelite/http/api/feed/FeedResult.java | 36 +++ .../http/api/ge/GrandExchangeClient.java | 78 ++++++ .../http/api/ge/GrandExchangeTrade.java | 38 +++ .../http/api/hiscore/HiscoreClient.java | 148 ++++++++++ .../http/api/hiscore/HiscoreEndpoint.java | 59 ++++ .../http/api/hiscore/HiscoreResult.java | 144 ++++++++++ .../api/hiscore/HiscoreResultBuilder.java | 92 ++++++ .../http/api/hiscore/HiscoreSkill.java | 75 +++++ .../api/hiscore/SingleHiscoreSkillResult.java | 111 ++++++++ .../net/runelite/http/api/hiscore/Skill.java | 101 +++++++ .../java/net/runelite/http/api/item/Item.java | 36 +++ .../runelite/http/api/item/ItemClient.java | 241 ++++++++++++++++ .../http/api/item/ItemEquipmentStats.java | 54 ++++ .../net/runelite/http/api/item/ItemPrice.java | 37 +++ .../net/runelite/http/api/item/ItemStats.java | 82 ++++++ .../net/runelite/http/api/item/ItemType.java | 48 ++++ .../runelite/http/api/item/SearchResult.java | 42 +++ .../http/api/loottracker/GameItem.java | 38 +++ .../http/api/loottracker/LootRecord.java | 42 +++ .../http/api/loottracker/LootRecordType.java | 33 +++ .../api/loottracker/LootTrackerClient.java | 147 ++++++++++ .../api/osbuddy/OSBGrandExchangeClient.java | 69 +++++ .../api/osbuddy/OSBGrandExchangeResult.java | 38 +++ .../net/runelite/http/api/worlds/World.java | 41 +++ .../runelite/http/api/worlds/WorldClient.java | 72 +++++ .../runelite/http/api/worlds/WorldResult.java | 54 ++++ .../runelite/http/api/worlds/WorldType.java | 39 +++ .../api/ws/RuntimeTypeAdapterFactory.java | 240 ++++++++++++++++ .../http/api/ws/WebsocketGsonFactory.java | 86 ++++++ .../http/api/ws/WebsocketMessage.java | 35 +++ .../http/api/ws/messages/Handshake.java | 43 +++ .../http/api/ws/messages/LoginResponse.java | 52 ++++ .../http/api/ws/messages/party/Join.java | 38 +++ .../http/api/ws/messages/party/Part.java | 31 +++ .../ws/messages/party/PartyMemberMessage.java | 12 + .../api/ws/messages/party/PartyMessage.java | 35 +++ .../http/api/ws/messages/party/UserJoin.java | 39 +++ .../http/api/ws/messages/party/UserPart.java | 37 +++ .../http/api/ws/messages/party/UserSync.java | 34 +++ .../net/runelite/http/api/xp/XpClient.java | 69 +++++ .../java/net/runelite/http/api/xp/XpData.java | 85 ++++++ .../runelite/http/api/xtea/XteaClient.java | 135 +++++++++ .../net/runelite/http/api/xtea/XteaKey.java | 51 ++++ .../runelite/http/api/xtea/XteaRequest.java | 54 ++++ .../src/main/resources/runelite.properties | 4 + .../runelite/http/api/RuneLiteAPITest.java | 65 +++++ pom.xml | 1 + 61 files changed, 4429 insertions(+), 1 deletion(-) create mode 100644 http-api/pom.xml create mode 100644 http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java create mode 100644 http-api/src/main/java/net/runelite/http/api/account/AccountClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/account/OAuthResponse.java create mode 100644 http-api/src/main/java/net/runelite/http/api/cache/Cache.java create mode 100644 http-api/src/main/java/net/runelite/http/api/cache/CacheArchive.java create mode 100644 http-api/src/main/java/net/runelite/http/api/cache/CacheIndex.java create mode 100644 http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/chat/Task.java create mode 100644 http-api/src/main/java/net/runelite/http/api/examine/ExamineClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/feed/FeedClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/feed/FeedItem.java create mode 100644 http-api/src/main/java/net/runelite/http/api/feed/FeedItemType.java create mode 100644 http-api/src/main/java/net/runelite/http/api/feed/FeedResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeTrade.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreEndpoint.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResultBuilder.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreSkill.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/SingleHiscoreSkillResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/hiscore/Skill.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/Item.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/ItemClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/ItemEquipmentStats.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/ItemPrice.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/ItemStats.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/ItemType.java create mode 100644 http-api/src/main/java/net/runelite/http/api/item/SearchResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/loottracker/GameItem.java create mode 100644 http-api/src/main/java/net/runelite/http/api/loottracker/LootRecord.java create mode 100644 http-api/src/main/java/net/runelite/http/api/loottracker/LootRecordType.java create mode 100644 http-api/src/main/java/net/runelite/http/api/loottracker/LootTrackerClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/worlds/World.java create mode 100644 http-api/src/main/java/net/runelite/http/api/worlds/WorldClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/worlds/WorldResult.java create mode 100644 http-api/src/main/java/net/runelite/http/api/worlds/WorldType.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/RuntimeTypeAdapterFactory.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/WebsocketGsonFactory.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/WebsocketMessage.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/Handshake.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/LoginResponse.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/Join.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/Part.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMemberMessage.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMessage.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserJoin.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserPart.java create mode 100644 http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserSync.java create mode 100644 http-api/src/main/java/net/runelite/http/api/xp/XpClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/xp/XpData.java create mode 100644 http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java create mode 100644 http-api/src/main/java/net/runelite/http/api/xtea/XteaKey.java create mode 100644 http-api/src/main/java/net/runelite/http/api/xtea/XteaRequest.java create mode 100644 http-api/src/main/resources/runelite.properties create mode 100644 http-api/src/test/java/net/runelite/http/api/RuneLiteAPITest.java diff --git a/RuneLitePlus/pom.xml b/RuneLitePlus/pom.xml index 5443daf34c..32af1e137e 100644 --- a/RuneLitePlus/pom.xml +++ b/RuneLitePlus/pom.xml @@ -219,7 +219,7 @@ net.runelite http-api - 1.5.26-SNAPSHOT + 1.5.27.1-SNAPSHOT net.runelite diff --git a/http-api/pom.xml b/http-api/pom.xml new file mode 100644 index 0000000000..64abf9646a --- /dev/null +++ b/http-api/pom.xml @@ -0,0 +1,126 @@ + + + + 4.0.0 + + net.runelite + runelite-parent + 1.5.27-SNAPSHOT + + + Web API + http-api + 1.5.27.1-SNAPSHOT + + + 1.4 + + 2.2.6 + + nogit + false + + + + + com.squareup.okhttp3 + okhttp + 3.14.1 + + + com.google.code.gson + gson + 2.8.5 + + + org.slf4j + slf4j-api + 1.8.0-beta4 + + + org.projectlombok + lombok + 1.18.6 + provided + + + org.apache.commons + commons-csv + ${commons.csv.version} + + + + junit + junit + 4.13-beta-3 + + + org.slf4j + slf4j-simple + 1.8.0-beta4 + + + com.squareup.okhttp3 + mockwebserver + 3.14.1 + + + + + + + src/main/resources + true + + + + + pl.project13.maven + git-commit-id-plugin + ${maven.git.commit.id.version} + + + query-git-info + + revision + + + false + false + + true + + + git.commit.id.abbrev + git.dirty + + + + + + + + diff --git a/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java b/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java new file mode 100644 index 0000000000..9155b39ecf --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api; + +import com.google.gson.Gson; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.TimeUnit; +import okhttp3.HttpUrl; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 Gson(); + public static String userAgent; + + private static final String BASE = "https://api.runelite.net"; + private static final String RLPLUS = "https://session.runelitepl.us"; + private static final String WSBASE = "https://api.runelite.net/ws"; + private static final String STATICBASE = "https://static.runelite.net"; + private static final Properties properties = new Properties(); + private static String version; + private static int rsVersion; + + static + { + try + { + InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties"); + properties.load(in); + + version = properties.getProperty("runelite.version"); + rsVersion = Integer.parseInt(properties.getProperty("rs.version")); + String commit = properties.getProperty("runelite.commit"); + boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty")); + + userAgent = "RuneLite/" + version + "-" + commit + (dirty ? "+" : ""); + } + catch (NumberFormatException e) + { + throw new RuntimeException("Version string has not been substituted; Re-run maven"); + } + catch (IOException ex) + { + logger.error(null, ex); + } + + CLIENT = new OkHttpClient.Builder() + .pingInterval(30, TimeUnit.SECONDS) + .addNetworkInterceptor(new Interceptor() + { + + @Override + public Response intercept(Chain chain) throws IOException + { + Request userAgentRequest = chain.request() + .newBuilder() + .header("User-Agent", userAgent) + .build(); + return chain.proceed(userAgentRequest); + } + }) + .build(); + } + + public static HttpUrl getSessionBase() + { + final String prop = System.getProperty("runelite.session.url"); + + if (prop != null && !prop.isEmpty()) + { + return HttpUrl.parse(prop); + } + + return HttpUrl.parse(BASE + "/session"); + } + + public static HttpUrl getRuneLitePlusSessionBase() + { + return HttpUrl.parse(RLPLUS); + } + + public static HttpUrl getApiBase() + { + final String prop = System.getProperty("runelite.http-service.url"); + + if (prop != null && !prop.isEmpty()) + { + return HttpUrl.parse(prop); + } + + return HttpUrl.parse(BASE + "/runelite-" + getVersion()); + } + + public static HttpUrl getStaticBase() + { + final String prop = System.getProperty("runelite.static.url"); + + if (prop != null && !prop.isEmpty()) + { + return HttpUrl.parse(prop); + } + + return HttpUrl.parse(STATICBASE); + } + + public static HttpUrl getWsEndpoint() + { + final String prop = System.getProperty("runelite.ws.url"); + + if (prop != null && !prop.isEmpty()) + { + return HttpUrl.parse(prop); + } + + return HttpUrl.parse(WSBASE); + } + + public static String getVersion() + { + return version; + } + + public static void setVersion(String version) + { + RuneLiteAPI.version = version; + } + + public static int getRsVersion() + { + return rsVersion; + } + +} diff --git a/http-api/src/main/java/net/runelite/http/api/account/AccountClient.java b/http-api/src/main/java/net/runelite/http/api/account/AccountClient.java new file mode 100644 index 0000000000..3f66167367 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/account/AccountClient.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.account; + +import com.google.gson.JsonParseException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.UUID; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AccountClient +{ + private static final Logger logger = LoggerFactory.getLogger(AccountClient.class); + + private UUID uuid; + + public AccountClient() + { + } + + public AccountClient(UUID uuid) + { + this.uuid = uuid; + } + + public OAuthResponse login() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("account") + .addPathSegment("login") + .addQueryParameter("uuid", uuid.toString()) + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), OAuthResponse.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public void logout() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("account") + .addPathSegment("logout") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + logger.debug("Sent logout request"); + } + } + + public boolean sesssionCheck() + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("account") + .addPathSegment("session-check") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + catch (IOException ex) + { + logger.debug("Unable to verify session", ex); + return true; // assume it is still valid if the server is unreachable + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/account/OAuthResponse.java b/http-api/src/main/java/net/runelite/http/api/account/OAuthResponse.java new file mode 100644 index 0000000000..dc9d3c34ad --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/account/OAuthResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.account; + +import java.util.UUID; + +public class OAuthResponse +{ + private String oauthUrl; + private UUID uid; + + public String getOauthUrl() + { + return oauthUrl; + } + + public void setOauthUrl(String oauthUrl) + { + this.oauthUrl = oauthUrl; + } + + public UUID getUid() + { + return uid; + } + + public void setUid(UUID uid) + { + this.uid = uid; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/cache/Cache.java b/http-api/src/main/java/net/runelite/http/api/cache/Cache.java new file mode 100644 index 0000000000..0fe91d6f98 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/cache/Cache.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.cache; + +import java.time.Instant; +import java.util.Objects; + +public class Cache +{ + private final int id; + private final int revision; + private final Instant date; + + public Cache(int id, int revision, Instant date) + { + this.id = id; + this.revision = revision; + this.date = date; + } + + @Override + public String toString() + { + return "Cache{" + "id=" + id + ", revision=" + revision + ", date=" + date + '}'; + } + + @Override + public int hashCode() + { + int hash = 5; + hash = 29 * hash + this.id; + hash = 29 * hash + this.revision; + hash = 29 * hash + Objects.hashCode(this.date); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final Cache other = (Cache) obj; + if (this.id != other.id) + { + return false; + } + if (this.revision != other.revision) + { + return false; + } + if (!Objects.equals(this.date, other.date)) + { + return false; + } + return true; + } + + public int getId() + { + return id; + } + + public int getRevision() + { + return revision; + } + + public Instant getDate() + { + return date; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/cache/CacheArchive.java b/http-api/src/main/java/net/runelite/http/api/cache/CacheArchive.java new file mode 100644 index 0000000000..a642f1fe4e --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/cache/CacheArchive.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.cache; + +public class CacheArchive +{ + private final int archiveId; + private final int nameHash; + private final int revision; + + public CacheArchive(int archiveId, int nameHash, int revision) + { + this.archiveId = archiveId; + this.nameHash = nameHash; + this.revision = revision; + } + + @Override + public String toString() + { + return "CacheArchive{" + "archiveId=" + archiveId + ", nameHash=" + nameHash + ", revision=" + revision + '}'; + } + + @Override + public int hashCode() + { + int hash = 5; + hash = 71 * hash + this.archiveId; + hash = 71 * hash + this.nameHash; + hash = 71 * hash + this.revision; + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final CacheArchive other = (CacheArchive) obj; + if (this.archiveId != other.archiveId) + { + return false; + } + if (this.nameHash != other.nameHash) + { + return false; + } + if (this.revision != other.revision) + { + return false; + } + return true; + } + + public int getArchiveId() + { + return archiveId; + } + + public int getNameHash() + { + return nameHash; + } + + public int getRevision() + { + return revision; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/cache/CacheIndex.java b/http-api/src/main/java/net/runelite/http/api/cache/CacheIndex.java new file mode 100644 index 0000000000..17558e4531 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/cache/CacheIndex.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.cache; + +public class CacheIndex +{ + private final int indexId; + private final int revision; + + public CacheIndex(int indexId, int revision) + { + this.indexId = indexId; + this.revision = revision; + } + + @Override + public String toString() + { + return "CacheIndex{" + "indexId=" + indexId + ", revision=" + revision + '}'; + } + + @Override + public int hashCode() + { + int hash = 5; + hash = 61 * hash + this.indexId; + hash = 61 * hash + this.revision; + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final CacheIndex other = (CacheIndex) obj; + if (this.indexId != other.indexId) + { + return false; + } + if (this.revision != other.revision) + { + return false; + } + return true; + } + + public int getIndexId() + { + return indexId; + } + + public int getRevision() + { + return revision; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java new file mode 100644 index 0000000000..2ab1d0c8ed --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.chat; + +import com.google.gson.JsonParseException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class ChatClient +{ + public boolean submitKc(String username, String boss, int kc) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("kc") + .addQueryParameter("name", username) + .addQueryParameter("boss", boss) + .addQueryParameter("kc", Integer.toString(kc)) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public int getKc(String username, String boss) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("kc") + .addQueryParameter("name", username) + .addQueryParameter("boss", boss) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up killcount!"); + } + return Integer.parseInt(response.body().string()); + } + } + + public boolean submitQp(String username, int qp) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("qp") + .addQueryParameter("name", username) + .addQueryParameter("qp", Integer.toString(qp)) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public int getQp(String username) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("qp") + .addQueryParameter("name", username) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up quest points!"); + } + return Integer.parseInt(response.body().string()); + } + } + + public boolean submitTask(String username, String task, int amount, int initialAmount, String location) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("task") + .addQueryParameter("name", username) + .addQueryParameter("task", task) + .addQueryParameter("amount", Integer.toString(amount)) + .addQueryParameter("initialAmount", Integer.toString(initialAmount)) + .addQueryParameter("location", location) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public Task getTask(String username) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("task") + .addQueryParameter("name", username) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up task!"); + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), Task.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public boolean submitPb(String username, String boss, int pb) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("pb") + .addQueryParameter("name", username) + .addQueryParameter("boss", boss) + .addQueryParameter("pb", Integer.toString(pb)) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public int getPb(String username, String boss) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("pb") + .addQueryParameter("name", username) + .addQueryParameter("boss", boss) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up personal best!"); + } + return Integer.parseInt(response.body().string()); + } + } + + public boolean submitGc(String username, int gc) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("gc") + .addQueryParameter("name", username) + .addQueryParameter("gc", Integer.toString(gc)) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public int getGc(String username) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("gc") + .addQueryParameter("name", username) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up gamble count!"); + } + return Integer.parseInt(response.body().string()); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/chat/Task.java b/http-api/src/main/java/net/runelite/http/api/chat/Task.java new file mode 100644 index 0000000000..db38c90109 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/chat/Task.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.chat; + +import lombok.Data; + +@Data +public class Task +{ + private String task; + private int amount; + private int initialAmount; + private String location; +} diff --git a/http-api/src/main/java/net/runelite/http/api/examine/ExamineClient.java b/http-api/src/main/java/net/runelite/http/api/examine/ExamineClient.java new file mode 100644 index 0000000000..5997799c2e --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/examine/ExamineClient.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.examine; + +import java.io.IOException; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ExamineClient +{ + private static final Logger logger = LoggerFactory.getLogger(ExamineClient.class); + + private static final MediaType TEXT = MediaType.parse("text"); + + public void submitObject(int id, String text) + { + submit("object", id, text); + } + + public void submitNpc(int id, String text) + { + submit("npc", id, text); + } + + public void submitItem(int id, String text) + { + submit("item", id, text); + } + + private void submit(String type, int id, String text) + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("examine") + .addPathSegment(type) + .addPathSegment(Integer.toString(id)) + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(TEXT, text)) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + logger.warn("Error submitting examine", e); + } + + @Override + public void onResponse(Call call, Response response) + { + response.close(); + logger.debug("Submitted examine info for {} {}: {}", type, id, text); + } + }); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/feed/FeedClient.java b/http-api/src/main/java/net/runelite/http/api/feed/FeedClient.java new file mode 100644 index 0000000000..6b05ad20ba --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/feed/FeedClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.feed; + +import com.google.gson.JsonParseException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FeedClient +{ + private static final Logger logger = LoggerFactory.getLogger(FeedClient.class); + + public FeedResult lookupFeed() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("feed.js") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error looking up feed: {}", response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), FeedResult.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/feed/FeedItem.java b/http-api/src/main/java/net/runelite/http/api/feed/FeedItem.java new file mode 100644 index 0000000000..620f639d15 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/feed/FeedItem.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.feed; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor +@AllArgsConstructor +public class FeedItem +{ + private final FeedItemType type; + private String avatar; + private final String title; + private final String content; + private final String url; + private final long timestamp; +} diff --git a/http-api/src/main/java/net/runelite/http/api/feed/FeedItemType.java b/http-api/src/main/java/net/runelite/http/api/feed/FeedItemType.java new file mode 100644 index 0000000000..e3cc9443cd --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/feed/FeedItemType.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.feed; + +public enum FeedItemType +{ + BLOG_POST, + TWEET, + OSRS_NEWS +} diff --git a/http-api/src/main/java/net/runelite/http/api/feed/FeedResult.java b/http-api/src/main/java/net/runelite/http/api/feed/FeedResult.java new file mode 100644 index 0000000000..cf862b5be0 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/feed/FeedResult.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.feed; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class FeedResult +{ + private List items; +} diff --git a/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java new file mode 100644 index 0000000000..a1b97bc390 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ge; + +import com.google.gson.Gson; +import java.io.IOException; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +@Slf4j +@AllArgsConstructor +public class GrandExchangeClient +{ + private static final MediaType JSON = MediaType.parse("application/json"); + private static final Gson GSON = RuneLiteAPI.GSON; + + private final UUID uuid; + + public void submit(GrandExchangeTrade grandExchangeTrade) + { + final HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("ge") + .build(); + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .post(RequestBody.create(JSON, GSON.toJson(grandExchangeTrade))) + .url(url) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + log.debug("unable to submit trade", e); + } + + @Override + public void onResponse(Call call, Response response) + { + log.debug("Submitted trade"); + response.close(); + } + }); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeTrade.java b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeTrade.java new file mode 100644 index 0000000000..b5d0012b16 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeTrade.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ge; + +import java.time.Instant; +import lombok.Data; + +@Data +public class GrandExchangeTrade +{ + private boolean buy; + private int itemId; + private int quantity; + private int price; + private Instant time; +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java new file mode 100644 index 0000000000..a725089de4 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreClient.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; + +@Slf4j +public class HiscoreClient +{ + public HiscoreResult lookup(String username, HiscoreEndpoint endpoint) throws IOException + { + return lookup(username, endpoint.getHiscoreURL()); + } + + public HiscoreResult lookup(String username, HttpUrl endpoint) throws IOException + { + HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint); + + if (resultBuilder == null) + { + return null; + } + + return resultBuilder.build(); + } + + public HiscoreResult lookup(String username) throws IOException + { + return lookup(username, HiscoreEndpoint.NORMAL); + } + + public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill, HiscoreEndpoint endpoint) throws IOException + { + HiscoreResultBuilder resultBuilder = lookupUsername(username, endpoint.getHiscoreURL()); + + if (resultBuilder == null) + { + return null; + } + + HiscoreResult result = resultBuilder.build(); + + Skill requested = result.getSkill(skill); + SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); + skillResult.setPlayer(username); + skillResult.setSkillName(skill.getName()); + skillResult.setSkill(requested); + return skillResult; + } + + public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill) throws IOException + { + return lookup(username, skill, HiscoreEndpoint.NORMAL); + } + + private HiscoreResultBuilder lookupUsername(String username, HttpUrl hiscoreUrl) throws IOException + { + HttpUrl url = hiscoreUrl.newBuilder() + .addQueryParameter("player", username) + .build(); + + log.debug("Built URL {}", url); + + Request okrequest = new Request.Builder() + .url(url) + .build(); + + String responseStr; + + try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) + { + if (!okresponse.isSuccessful()) + { + switch (okresponse.code()) + { + case 404: + return null; + default: + throw new IOException("Error retrieving data from Jagex Hiscores: " + okresponse); + } + } + + responseStr = okresponse.body().string(); + } + + CSVParser parser = CSVParser.parse(responseStr, CSVFormat.DEFAULT); + + HiscoreResultBuilder hiscoreBuilder = new HiscoreResultBuilder(); + hiscoreBuilder.setPlayer(username); + + int count = 0; + + for (CSVRecord record : parser.getRecords()) + { + if (count++ >= HiscoreSkill.values().length) + { + log.warn("Jagex Hiscore API returned unexpected data"); + break; // rest is other things? + } + + // rank, level, experience + int rank = Integer.parseInt(record.get(0)); + int level = Integer.parseInt(record.get(1)); + + // items that are not skills do not have an experience parameter + long experience = -1; + if (record.size() == 3) + { + experience = Long.parseLong(record.get(2)); + } + + Skill skill = new Skill(rank, level, experience); + hiscoreBuilder.setNextSkill(skill); + } + + return hiscoreBuilder; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreEndpoint.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreEndpoint.java new file mode 100644 index 0000000000..a88f2e208e --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreEndpoint.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.runelite.http.api.hiscore; + +import okhttp3.HttpUrl; + +public enum HiscoreEndpoint +{ + NORMAL("Normal", "https://services.runescape.com/m=hiscore_oldschool/index_lite.ws"), + IRONMAN("Ironman", "https://services.runescape.com/m=hiscore_oldschool_ironman/index_lite.ws"), + HARDCORE_IRONMAN("Hardcore Ironman", "https://services.runescape.com/m=hiscore_oldschool_hardcore_ironman/index_lite.ws"), + ULTIMATE_IRONMAN("Ultimate Ironman", "https://services.runescape.com/m=hiscore_oldschool_ultimate/index_lite.ws"), + DEADMAN("Deadman", "https://services.runescape.com/m=hiscore_oldschool_deadman/index_lite.ws"), + SEASONAL_DEADMAN("Seasonal Deadman", "https://services.runescape.com/m=hiscore_oldschool_seasonal/index_lite.ws"), + DEADMAN_TOURNAMENT("Deadman Tournament", "https://services.runescape.com/m=hiscore_oldschool_tournament/index_lite.ws"); + + private final String name; + private final HttpUrl hiscoreURL; + + HiscoreEndpoint(String name, String hiscoreURL) + { + this.name = name; + this.hiscoreURL = HttpUrl.parse(hiscoreURL); + } + + public String getName() + { + return name; + } + + public HttpUrl getHiscoreURL() + { + return hiscoreURL; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResult.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResult.java new file mode 100644 index 0000000000..9af6f6e4b9 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResult.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +import lombok.Data; + +@Data +public class HiscoreResult +{ + private String player; + private Skill overall; + private Skill attack; + private Skill defence; + private Skill strength; + private Skill hitpoints; + private Skill ranged; + private Skill prayer; + private Skill magic; + private Skill cooking; + private Skill woodcutting; + private Skill fletching; + private Skill fishing; + private Skill firemaking; + private Skill crafting; + private Skill smithing; + private Skill mining; + private Skill herblore; + private Skill agility; + private Skill thieving; + private Skill slayer; + private Skill farming; + private Skill runecraft; + private Skill hunter; + private Skill construction; + private Skill bountyHunterHunter; + private Skill bountyHunterRogue; + private Skill clueScrollAll; + private Skill clueScrollBeginner; + private Skill clueScrollEasy; + private Skill clueScrollMedium; + private Skill clueScrollHard; + private Skill clueScrollElite; + private Skill clueScrollMaster; + private Skill lastManStanding; + + public Skill getSkill(HiscoreSkill skill) + { + switch (skill) + { + case ATTACK: + return getAttack(); + case DEFENCE: + return getDefence(); + case STRENGTH: + return getStrength(); + case HITPOINTS: + return getHitpoints(); + case RANGED: + return getRanged(); + case PRAYER: + return getPrayer(); + case MAGIC: + return getMagic(); + case COOKING: + return getCooking(); + case WOODCUTTING: + return getWoodcutting(); + case FLETCHING: + return getFletching(); + case FISHING: + return getFishing(); + case FIREMAKING: + return getFiremaking(); + case CRAFTING: + return getCrafting(); + case SMITHING: + return getSmithing(); + case MINING: + return getMining(); + case HERBLORE: + return getHerblore(); + case AGILITY: + return getAgility(); + case THIEVING: + return getThieving(); + case SLAYER: + return getSlayer(); + case FARMING: + return getFarming(); + case RUNECRAFT: + return getRunecraft(); + case HUNTER: + return getHunter(); + case CONSTRUCTION: + return getConstruction(); + case OVERALL: + return getOverall(); + case BOUNTY_HUNTER_HUNTER: + return getBountyHunterHunter(); + case BOUNTY_HUNTER_ROGUE: + return getBountyHunterRogue(); + case CLUE_SCROLL_ALL: + return getClueScrollAll(); + case CLUE_SCROLL_BEGINNER: + return getClueScrollBeginner(); + case CLUE_SCROLL_EASY: + return getClueScrollEasy(); + case CLUE_SCROLL_MEDIUM: + return getClueScrollMedium(); + case CLUE_SCROLL_HARD: + return getClueScrollHard(); + case CLUE_SCROLL_ELITE: + return getClueScrollElite(); + case CLUE_SCROLL_MASTER: + return getClueScrollMaster(); + case LAST_MAN_STANDING: + return getLastManStanding(); + } + + throw new IllegalArgumentException("Invalid hiscore item"); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResultBuilder.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResultBuilder.java new file mode 100644 index 0000000000..a6117160a4 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreResultBuilder.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +import java.util.ArrayList; +import java.util.List; +import net.runelite.http.api.hiscore.HiscoreResult; +import net.runelite.http.api.hiscore.Skill; + +public class HiscoreResultBuilder +{ + private String player; + private final List skills = new ArrayList<>(); + + public void setPlayer(String player) + { + this.player = player; + } + + public void setNextSkill(Skill skill) + { + skills.add(skill); + } + + public Skill getSkill(int index) + { + return skills.get(index); + } + + public HiscoreResult build() + { + HiscoreResult hiscoreResult = new HiscoreResult(); + hiscoreResult.setPlayer(player); + hiscoreResult.setOverall(skills.get(0)); + hiscoreResult.setAttack(skills.get(1)); + hiscoreResult.setDefence(skills.get(2)); + hiscoreResult.setStrength(skills.get(3)); + hiscoreResult.setHitpoints(skills.get(4)); + hiscoreResult.setRanged(skills.get(5)); + hiscoreResult.setPrayer(skills.get(6)); + hiscoreResult.setMagic(skills.get(7)); + hiscoreResult.setCooking(skills.get(8)); + hiscoreResult.setWoodcutting(skills.get(9)); + hiscoreResult.setFletching(skills.get(10)); + hiscoreResult.setFishing(skills.get(11)); + hiscoreResult.setFiremaking(skills.get(12)); + hiscoreResult.setCrafting(skills.get(13)); + hiscoreResult.setSmithing(skills.get(14)); + hiscoreResult.setMining(skills.get(15)); + hiscoreResult.setHerblore(skills.get(16)); + hiscoreResult.setAgility(skills.get(17)); + hiscoreResult.setThieving(skills.get(18)); + hiscoreResult.setSlayer(skills.get(19)); + hiscoreResult.setFarming(skills.get(20)); + hiscoreResult.setRunecraft(skills.get(21)); + hiscoreResult.setHunter(skills.get(22)); + hiscoreResult.setConstruction(skills.get(23)); + hiscoreResult.setBountyHunterHunter(skills.get(24)); + hiscoreResult.setBountyHunterRogue(skills.get(25)); + hiscoreResult.setLastManStanding(skills.get(26)); + hiscoreResult.setClueScrollAll(skills.get(27)); + hiscoreResult.setClueScrollBeginner(skills.get(28)); + hiscoreResult.setClueScrollEasy(skills.get(29)); + hiscoreResult.setClueScrollMedium(skills.get(30)); + hiscoreResult.setClueScrollHard(skills.get(31)); + hiscoreResult.setClueScrollElite(skills.get(32)); + hiscoreResult.setClueScrollMaster(skills.get(33)); + return hiscoreResult; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreSkill.java b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreSkill.java new file mode 100644 index 0000000000..db043dfcfb --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/HiscoreSkill.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +public enum HiscoreSkill +{ + OVERALL("Overall"), + ATTACK("Attack"), + DEFENCE("Defence"), + STRENGTH("Strength"), + HITPOINTS("Hitpoints"), + RANGED("Ranged"), + PRAYER("Prayer"), + MAGIC("Magic"), + COOKING("Cooking"), + WOODCUTTING("Woodcutting"), + FLETCHING("Fletching"), + FISHING("Fishing"), + FIREMAKING("Firemaking"), + CRAFTING("Crafting"), + SMITHING("Smithing"), + MINING("Mining"), + HERBLORE("Herblore"), + AGILITY("Agility"), + THIEVING("Thieving"), + SLAYER("Slayer"), + FARMING("Farming"), + RUNECRAFT("Runecraft"), + HUNTER("Hunter"), + CONSTRUCTION("Construction"), + BOUNTY_HUNTER_HUNTER("Bounty Hunter - Hunter"), + BOUNTY_HUNTER_ROGUE("Bounty Hunter - Rogue"), + LAST_MAN_STANDING("Last Man Standing"), + CLUE_SCROLL_ALL("Clue Scrolls (all)"), + CLUE_SCROLL_BEGINNER("Clue Scrolls (beginner)"), + CLUE_SCROLL_EASY("Clue Scrolls (easy)"), + CLUE_SCROLL_MEDIUM("Clue Scrolls (medium)"), + CLUE_SCROLL_HARD("Clue Scrolls (hard)"), + CLUE_SCROLL_ELITE("Clue Scrolls (elite)"), + CLUE_SCROLL_MASTER("Clue Scrolls (master)"); + + private final String name; + + HiscoreSkill(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/SingleHiscoreSkillResult.java b/http-api/src/main/java/net/runelite/http/api/hiscore/SingleHiscoreSkillResult.java new file mode 100644 index 0000000000..c2ab3407a1 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/SingleHiscoreSkillResult.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017. l2- + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +import java.util.Objects; + +public class SingleHiscoreSkillResult +{ + private String player; + private String skillName; + private Skill skill; + + public String getPlayer() + { + return player; + } + + public void setPlayer(String player) + { + this.player = player; + } + + public String getSkillName() + { + return skillName; + } + + public void setSkillName(String skillName) + { + this.skillName = skillName; + } + + public Skill getSkill() + { + return skill; + } + + public void setSkill(Skill skill) + { + this.skill = skill; + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 37 * hash + Objects.hashCode(this.player); + hash = 37 * hash + Objects.hashCode(this.skillName); + hash = 37 * hash + Objects.hashCode(this.skill); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final SingleHiscoreSkillResult other = (SingleHiscoreSkillResult) obj; + if (!Objects.equals(this.player, other.player)) + { + return false; + } + if (!Objects.equals(this.skillName, other.skillName)) + { + return false; + } + if (!Objects.equals(this.skill, other.skill)) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "SingleHiscoreSkillResult{" + "player=" + player + ", skillName=" + skillName + ", skill=" + skill + '}'; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/hiscore/Skill.java b/http-api/src/main/java/net/runelite/http/api/hiscore/Skill.java new file mode 100644 index 0000000000..fa779381bc --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/hiscore/Skill.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.hiscore; + +public class Skill +{ + private final int rank; + private final int level; + private final long experience; + + public Skill(int rank, int level, long experience) + { + this.rank = rank; + this.level = level; + this.experience = experience; + } + + public int getRank() + { + return rank; + } + + public int getLevel() + { + return level; + } + + public long getExperience() + { + return experience; + } + + @Override + public int hashCode() + { + int hash = 3; + hash = 59 * hash + this.rank; + hash = 59 * hash + this.level; + hash = 59 * hash + (int) (this.experience ^ (this.experience >>> 32)); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + final Skill other = (Skill) obj; + if (this.rank != other.rank) + { + return false; + } + if (this.level != other.level) + { + return false; + } + if (this.experience != other.experience) + { + return false; + } + return true; + } + + @Override + public String toString() + { + return "Skill{" + "rank=" + rank + ", level=" + level + ", experience=" + experience + '}'; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/item/Item.java b/http-api/src/main/java/net/runelite/http/api/item/Item.java new file mode 100644 index 0000000000..3a6f0346c4 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/Item.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import lombok.Data; + +@Data +public class Item +{ + private int id; + private String name; + private String description; + private ItemType type; +} diff --git a/http-api/src/main/java/net/runelite/http/api/item/ItemClient.java b/http-api/src/main/java/net/runelite/http/api/item/ItemClient.java new file mode 100644 index 0000000000..17784dd67b --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/ItemClient.java @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import com.google.gson.JsonParseException; +import com.google.gson.reflect.TypeToken; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Map; +import javax.imageio.ImageIO; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ItemClient +{ + private static final Logger logger = LoggerFactory.getLogger(ItemClient.class); + + public ItemPrice lookupItemPrice(int itemId) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("item") + .addPathSegment("" + itemId) + .addPathSegment("price") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error looking up item {}: {}", itemId, response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), ItemPrice.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public ItemPrice[] lookupItemPrice(Integer[] itemIds) throws IOException + { + HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("item") + .addPathSegment("price"); + + for (int itemId : itemIds) + { + urlBuilder.addQueryParameter("id", String.valueOf(itemId)); + } + + HttpUrl url = urlBuilder.build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error looking up items {}: {}", Arrays.toString(itemIds), response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), ItemPrice[].class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public BufferedImage getIcon(int itemId) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("item") + .addPathSegment("" + itemId) + .addPathSegment("icon") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error grabbing icon {}: {}", itemId, response); + return null; + } + + InputStream in = response.body().byteStream(); + synchronized (ImageIO.class) + { + return ImageIO.read(in); + } + } + } + + public SearchResult search(String itemName) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("item") + .addPathSegment("search") + .addQueryParameter("query", itemName) + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error looking up item {}: {}", itemName, response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), SearchResult.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public ItemPrice[] getPrices() throws IOException + { + HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("item") + .addPathSegment("prices.js"); + + HttpUrl url = urlBuilder.build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.warn("Error looking up prices: {}", response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), ItemPrice[].class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public Map getStats() throws IOException + { + HttpUrl.Builder urlBuilder = RuneLiteAPI.getStaticBase().newBuilder() + .addPathSegment("item") + // TODO: Change this to stats.min.json later after release is undeployed + .addPathSegment("stats.ids.min.json"); + + HttpUrl url = urlBuilder.build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.warn("Error looking up item stats: {}", response); + return null; + } + + InputStream in = response.body().byteStream(); + final Type typeToken = new TypeToken>() + { + }.getType(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), typeToken); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/item/ItemEquipmentStats.java b/http-api/src/main/java/net/runelite/http/api/item/ItemEquipmentStats.java new file mode 100644 index 0000000000..5f7fdaccbe --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/ItemEquipmentStats.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import lombok.Builder; +import lombok.Value; + +@Value +@Builder +public class ItemEquipmentStats +{ + private int slot; + + private int astab; + private int aslash; + private int acrush; + private int amagic; + private int arange; + + private int dstab; + private int dslash; + private int dcrush; + private int dmagic; + private int drange; + + private int str; + private int rstr; + private int mdmg; + private int prayer; + private int aspeed; +} + diff --git a/http-api/src/main/java/net/runelite/http/api/item/ItemPrice.java b/http-api/src/main/java/net/runelite/http/api/item/ItemPrice.java new file mode 100644 index 0000000000..001c63deb8 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/ItemPrice.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import java.time.Instant; +import lombok.Data; + +@Data +public class ItemPrice +{ + private int id; + private String name; + private int price; + private Instant time; +} diff --git a/http-api/src/main/java/net/runelite/http/api/item/ItemStats.java b/http-api/src/main/java/net/runelite/http/api/item/ItemStats.java new file mode 100644 index 0000000000..3ebc17970f --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/ItemStats.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import lombok.Value; + +@Value +public class ItemStats +{ + private boolean quest; + private boolean equipable; + private double weight; + + private ItemEquipmentStats equipment; + + public ItemStats subtract(ItemStats other) + { + if (other == null) + { + return this; + } + + final double newWeight = weight - other.weight; + final ItemEquipmentStats newEquipment; + + + if (other.equipment != null) + { + final ItemEquipmentStats equipment = this.equipment != null + ? this.equipment + : new ItemEquipmentStats.ItemEquipmentStatsBuilder().build(); + + newEquipment = new ItemEquipmentStats.ItemEquipmentStatsBuilder() + .slot(equipment.getSlot()) + .astab(equipment.getAstab() - other.equipment.getAstab()) + .aslash(equipment.getAslash() - other.equipment.getAslash()) + .acrush(equipment.getAcrush() - other.equipment.getAcrush()) + .amagic(equipment.getAmagic() - other.equipment.getAmagic()) + .arange(equipment.getArange() - other.equipment.getArange()) + .dstab(equipment.getDstab() - other.equipment.getDstab()) + .dslash(equipment.getDslash() - other.equipment.getDslash()) + .dcrush(equipment.getDcrush() - other.equipment.getDcrush()) + .dmagic(equipment.getDmagic() - other.equipment.getDmagic()) + .drange(equipment.getDrange() - other.equipment.getDrange()) + .str(equipment.getStr() - other.equipment.getStr()) + .rstr(equipment.getRstr() - other.equipment.getRstr()) + .mdmg(equipment.getMdmg() - other.equipment.getMdmg()) + .prayer(equipment.getPrayer() - other.equipment.getPrayer()) + .aspeed(equipment.getAspeed() - other.equipment.getAspeed()) + .build(); + } + else + { + newEquipment = equipment; + } + + return new ItemStats(quest, equipable, newWeight, newEquipment); + } +} + diff --git a/http-api/src/main/java/net/runelite/http/api/item/ItemType.java b/http-api/src/main/java/net/runelite/http/api/item/ItemType.java new file mode 100644 index 0000000000..9221f096b2 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/ItemType.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public enum ItemType +{ + DEFAULT; + + private static final Logger logger = LoggerFactory.getLogger(ItemType.class); + + public static ItemType of(String type) + { + try + { + return ItemType.valueOf(type.toUpperCase()); + } + catch (IllegalArgumentException ex) + { + logger.warn("unable to convert type", ex); + return DEFAULT; + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/item/SearchResult.java b/http-api/src/main/java/net/runelite/http/api/item/SearchResult.java new file mode 100644 index 0000000000..90ae1ec783 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/item/SearchResult.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.item; + +import java.util.List; + +public class SearchResult +{ + private List items; + + public List getItems() + { + return items; + } + + public void setItems(List items) + { + this.items = items; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/loottracker/GameItem.java b/http-api/src/main/java/net/runelite/http/api/loottracker/GameItem.java new file mode 100644 index 0000000000..7e9b06c21b --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/loottracker/GameItem.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, TheStonedTurtle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.loottracker; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GameItem +{ + private int id; + private int qty; +} diff --git a/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecord.java b/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecord.java new file mode 100644 index 0000000000..fc945220f1 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecord.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, TheStonedTurtle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.loottracker; + +import java.time.Instant; +import java.util.Collection; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class LootRecord +{ + private String eventId; + private LootRecordType type; + private Collection drops; + private Instant time; +} diff --git a/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecordType.java b/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecordType.java new file mode 100644 index 0000000000..c91817b410 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/loottracker/LootRecordType.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018, TheStonedTurtle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.loottracker; + +public enum LootRecordType +{ + NPC, + PLAYER, + EVENT, + UNKNOWN +} diff --git a/http-api/src/main/java/net/runelite/http/api/loottracker/LootTrackerClient.java b/http-api/src/main/java/net/runelite/http/api/loottracker/LootTrackerClient.java new file mode 100644 index 0000000000..d250620905 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/loottracker/LootTrackerClient.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.loottracker; + +import com.google.gson.Gson; +import com.google.gson.JsonParseException; +import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +@Slf4j +@AllArgsConstructor +public class LootTrackerClient +{ + private static final MediaType JSON = MediaType.parse("application/json"); + private static final Gson GSON = RuneLiteAPI.GSON; + + private final UUID uuid; + + public void submit(LootRecord lootRecord) + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("loottracker") + .build(); + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .post(RequestBody.create(JSON, GSON.toJson(lootRecord))) + .url(url) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + log.warn("unable to submit loot", e); + } + + @Override + public void onResponse(Call call, Response response) + { + log.debug("Submitted loot"); + response.close(); + } + }); + } + + public Collection get() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("loottracker") + .build(); + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + log.debug("Error looking up loot: {}", response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken>() + { + }.getType()); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public void delete(String eventId) + { + HttpUrl.Builder builder = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("loottracker"); + + if (eventId != null) + { + builder.addQueryParameter("eventId", eventId); + } + + Request request = new Request.Builder() + .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + .delete() + .url(builder.build()) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + log.warn("unable to delete loot", e); + } + + @Override + public void onResponse(Call call, Response response) + { + log.debug("Deleted loot"); + response.close(); + } + }); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeClient.java b/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeClient.java new file mode 100644 index 0000000000..c01337fdc0 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, AeonLucid + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.osbuddy; + +import com.google.gson.JsonParseException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import lombok.extern.slf4j.Slf4j; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; + +@Slf4j +public class OSBGrandExchangeClient +{ + public OSBGrandExchangeResult lookupItem(int itemId) throws IOException + { + final HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("osb") + .addPathSegment("ge") + .addQueryParameter("itemId", Integer.toString(itemId)) + .build(); + + log.debug("Built URI: {}", url); + + final Request request = new Request.Builder() + .url(url) + .build(); + + try (final Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Error looking up item id: " + response); + } + + final InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), OSBGrandExchangeResult.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeResult.java b/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeResult.java new file mode 100644 index 0000000000..13e5f5e8e4 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeResult.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, AeonLucid + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.osbuddy; + +import java.time.Instant; +import lombok.Data; + +@Data +public class OSBGrandExchangeResult +{ + private int item_id; + private int buy_average; + private int sell_average; + private int overall_average; + private Instant last_update; +} diff --git a/http-api/src/main/java/net/runelite/http/api/worlds/World.java b/http-api/src/main/java/net/runelite/http/api/worlds/World.java new file mode 100644 index 0000000000..2c1e6f6798 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/worlds/World.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.worlds; + +import java.util.EnumSet; +import lombok.Builder; +import lombok.Value; + +@Value +@Builder +public class World +{ + private int id; + private EnumSet types; + private String address; + private String activity; + private int location; + private int players; +} diff --git a/http-api/src/main/java/net/runelite/http/api/worlds/WorldClient.java b/http-api/src/main/java/net/runelite/http/api/worlds/WorldClient.java new file mode 100644 index 0000000000..668e088404 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/worlds/WorldClient.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, Adam + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.worlds; + +import com.google.gson.JsonParseException; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class WorldClient +{ + private static final Logger logger = LoggerFactory.getLogger(WorldClient.class); + + public WorldResult lookupWorlds() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("worlds.js") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + logger.debug("Error looking up worlds: {}", response); + return null; + } + + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), WorldResult.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/worlds/WorldResult.java b/http-api/src/main/java/net/runelite/http/api/worlds/WorldResult.java new file mode 100644 index 0000000000..a4afe23e85 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/worlds/WorldResult.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.worlds; + +import java.util.List; + +public class WorldResult +{ + private List worlds; + + public List getWorlds() + { + return worlds; + } + + public void setWorlds(List worlds) + { + this.worlds = worlds; + } + + public World findWorld(int worldNum) + { + for (World world : worlds) + { + if (world.getId() == worldNum) + { + return world; + } + } + return null; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/worlds/WorldType.java b/http-api/src/main/java/net/runelite/http/api/worlds/WorldType.java new file mode 100644 index 0000000000..c94a7c70e6 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/worlds/WorldType.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018, Lotto + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.worlds; + +public enum WorldType +{ + MEMBERS, + PVP, + BOUNTY, + SKILL_TOTAL, + HIGH_RISK, + LAST_MAN_STANDING, + TOURNAMENT, + DEADMAN, + SEASONAL_DEADMAN, + DEADMAN_TOURNAMENT +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/RuntimeTypeAdapterFactory.java b/http-api/src/main/java/net/runelite/http/api/ws/RuntimeTypeAdapterFactory.java new file mode 100644 index 0000000000..2819c92ceb --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/RuntimeTypeAdapterFactory.java @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.runelite.http.api.ws; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.internal.Streams; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +/** + * Adapts values whose runtime type may differ from their declaration type. This + * is necessary when a field's type is not the same type that GSON should create + * when deserializing that field. For example, consider these types: + *
   {@code
+ *   abstract class Shape {
+ *     int x;
+ *     int y;
+ *   }
+ *   class Circle extends Shape {
+ *     int radius;
+ *   }
+ *   class Rectangle extends Shape {
+ *     int width;
+ *     int height;
+ *   }
+ *   class Diamond extends Shape {
+ *     int width;
+ *     int height;
+ *   }
+ *   class Drawing {
+ *     Shape bottomShape;
+ *     Shape topShape;
+ *   }
+ * }
+ *

Without additional type information, the serialized JSON is ambiguous. Is + * the bottom shape in this drawing a rectangle or a diamond?

   {@code
+ *   {
+ *     "bottomShape": {
+ *       "width": 10,
+ *       "height": 5,
+ *       "x": 0,
+ *       "y": 0
+ *     },
+ *     "topShape": {
+ *       "radius": 2,
+ *       "x": 4,
+ *       "y": 1
+ *     }
+ *   }}
+ * This class addresses this problem by adding type information to the + * serialized JSON and honoring that type information when the JSON is + * deserialized:
   {@code
+ *   {
+ *     "bottomShape": {
+ *       "type": "Diamond",
+ *       "width": 10,
+ *       "height": 5,
+ *       "x": 0,
+ *       "y": 0
+ *     },
+ *     "topShape": {
+ *       "type": "Circle",
+ *       "radius": 2,
+ *       "x": 4,
+ *       "y": 1
+ *     }
+ *   }}
+ * Both the type field name ({@code "type"}) and the type labels ({@code + * "Rectangle"}) are configurable. + * + *

Registering Types

+ * Create a {@code RuntimeTypeAdapterFactory} by passing the base type and type field + * name to the {@link #of} factory method. If you don't supply an explicit type + * field name, {@code "type"} will be used.
   {@code
+ *   RuntimeTypeAdapterFactory shapeAdapterFactory
+ *       = RuntimeTypeAdapterFactory.of(Shape.class, "type");
+ * }
+ * Next register all of your subtypes. Every subtype must be explicitly + * registered. This protects your application from injection attacks. If you + * don't supply an explicit type label, the type's simple name will be used. + *
   {@code
+ *   shapeAdapter.registerSubtype(Rectangle.class, "Rectangle");
+ *   shapeAdapter.registerSubtype(Circle.class, "Circle");
+ *   shapeAdapter.registerSubtype(Diamond.class, "Diamond");
+ * }
+ * Finally, register the type adapter factory in your application's GSON builder: + *
   {@code
+ *   Gson gson = new GsonBuilder()
+ *       .registerTypeAdapterFactory(shapeAdapterFactory)
+ *       .create();
+ * }
+ * Like {@code GsonBuilder}, this API supports chaining:
   {@code
+ *   RuntimeTypeAdapterFactory shapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class)
+ *       .registerSubtype(Rectangle.class)
+ *       .registerSubtype(Circle.class)
+ *       .registerSubtype(Diamond.class);
+ * }
+ */ +public final class RuntimeTypeAdapterFactory implements TypeAdapterFactory { + private final Class baseType; + private final String typeFieldName; + private final Map> labelToSubtype = new LinkedHashMap>(); + private final Map, String> subtypeToLabel = new LinkedHashMap, String>(); + + private RuntimeTypeAdapterFactory(Class baseType, String typeFieldName) { + if (typeFieldName == null || baseType == null) { + throw new NullPointerException(); + } + this.baseType = baseType; + this.typeFieldName = typeFieldName; + } + + /** + * Creates a new runtime type adapter using for {@code baseType} using {@code + * typeFieldName} as the type field name. Type field names are case sensitive. + */ + public static RuntimeTypeAdapterFactory of(Class baseType, String typeFieldName) { + return new RuntimeTypeAdapterFactory(baseType, typeFieldName); + } + + /** + * Creates a new runtime type adapter for {@code baseType} using {@code "type"} as + * the type field name. + */ + public static RuntimeTypeAdapterFactory of(Class baseType) { + return new RuntimeTypeAdapterFactory(baseType, "type"); + } + + /** + * Registers {@code type} identified by {@code label}. Labels are case + * sensitive. + * + * @throws IllegalArgumentException if either {@code type} or {@code label} + * have already been registered on this type adapter. + */ + public RuntimeTypeAdapterFactory registerSubtype(Class type, String label) { + if (type == null || label == null) { + throw new NullPointerException(); + } + if (subtypeToLabel.containsKey(type) || labelToSubtype.containsKey(label)) { + throw new IllegalArgumentException("types and labels must be unique"); + } + labelToSubtype.put(label, type); + subtypeToLabel.put(type, label); + return this; + } + + /** + * Registers {@code type} identified by its {@link Class#getSimpleName simple + * name}. Labels are case sensitive. + * + * @throws IllegalArgumentException if either {@code type} or its simple name + * have already been registered on this type adapter. + */ + public RuntimeTypeAdapterFactory registerSubtype(Class type) { + return registerSubtype(type, type.getSimpleName()); + } + + public TypeAdapter create(Gson gson, TypeToken type) { + if (type.getRawType() != baseType) { + return null; + } + + final Map> labelToDelegate + = new LinkedHashMap>(); + final Map, TypeAdapter> subtypeToDelegate + = new LinkedHashMap, TypeAdapter>(); + for (Map.Entry> entry : labelToSubtype.entrySet()) { + TypeAdapter delegate = gson.getDelegateAdapter(this, TypeToken.get(entry.getValue())); + labelToDelegate.put(entry.getKey(), delegate); + subtypeToDelegate.put(entry.getValue(), delegate); + } + + return new TypeAdapter() { + @Override public R read(JsonReader in) throws IOException { + JsonElement jsonElement = Streams.parse(in); + JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName); + if (labelJsonElement == null) { + throw new JsonParseException("cannot deserialize " + baseType + + " because it does not define a field named " + typeFieldName); + } + String label = labelJsonElement.getAsString(); + @SuppressWarnings("unchecked") // registration requires that subtype extends T + TypeAdapter delegate = (TypeAdapter) labelToDelegate.get(label); + if (delegate == null) { + throw new JsonParseException("cannot deserialize " + baseType + " subtype named " + + label + "; did you forget to register a subtype?"); + } + return delegate.fromJsonTree(jsonElement); + } + + @Override public void write(JsonWriter out, R value) throws IOException { + Class srcType = value.getClass(); + String label = subtypeToLabel.get(srcType); + @SuppressWarnings("unchecked") // registration requires that subtype extends T + TypeAdapter delegate = (TypeAdapter) subtypeToDelegate.get(srcType); + if (delegate == null) { + throw new JsonParseException("cannot serialize " + srcType.getName() + + "; did you forget to register a subtype?"); + } + JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject(); + if (jsonObject.has(typeFieldName)) { + throw new JsonParseException("cannot serialize " + srcType.getName() + + " because it already defines a field named " + typeFieldName); + } + JsonObject clone = new JsonObject(); + clone.add(typeFieldName, new JsonPrimitive(label)); + for (Map.Entry e : jsonObject.entrySet()) { + clone.add(e.getKey(), e.getValue()); + } + Streams.write(clone, out); + } + }.nullSafe(); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/WebsocketGsonFactory.java b/http-api/src/main/java/net/runelite/http/api/ws/WebsocketGsonFactory.java new file mode 100644 index 0000000000..589a538de3 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/WebsocketGsonFactory.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import net.runelite.http.api.ws.messages.Handshake; +import net.runelite.http.api.ws.messages.LoginResponse; +import net.runelite.http.api.ws.messages.party.Join; +import net.runelite.http.api.ws.messages.party.Part; +import net.runelite.http.api.ws.messages.party.UserJoin; +import net.runelite.http.api.ws.messages.party.UserPart; +import net.runelite.http.api.ws.messages.party.UserSync; + +public class WebsocketGsonFactory +{ + private static final Collection> MESSAGES; + + static + { + final List> messages = new ArrayList<>(); + messages.add(Handshake.class); + messages.add(LoginResponse.class); + messages.add(Join.class); + messages.add(Part.class); + messages.add(UserJoin.class); + messages.add(UserPart.class); + messages.add(UserSync.class); + MESSAGES = messages; + } + + public static RuntimeTypeAdapterFactory factory(final Collection> messages) + { + final RuntimeTypeAdapterFactory factory = RuntimeTypeAdapterFactory.of(WebsocketMessage.class); + + for (Class message : MESSAGES) + { + factory.registerSubtype(message); + } + + for (Class message : messages) + { + factory.registerSubtype(message); + } + + return factory; + } + + public static Gson build(final RuntimeTypeAdapterFactory factory) + { + return new GsonBuilder() + .registerTypeAdapterFactory(factory) + .create(); + } + + public static Gson build() + { + return build(factory(Collections.emptyList())); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/WebsocketMessage.java b/http-api/src/main/java/net/runelite/http/api/ws/WebsocketMessage.java new file mode 100644 index 0000000000..d732c110cd --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/WebsocketMessage.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws; + +public class WebsocketMessage +{ + protected boolean _party; + + public boolean isParty() + { + return _party; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/Handshake.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/Handshake.java new file mode 100644 index 0000000000..557f8f524b --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/Handshake.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages; + +import java.util.UUID; +import net.runelite.http.api.ws.WebsocketMessage; + +public class Handshake extends WebsocketMessage +{ + private UUID session; + + public UUID getSession() + { + return session; + } + + public void setSession(UUID session) + { + this.session = session; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/LoginResponse.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/LoginResponse.java new file mode 100644 index 0000000000..b517e773a2 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/LoginResponse.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages; + +import net.runelite.http.api.ws.WebsocketMessage; + +/** + * Called after a successful login to the server + * @author Adam + */ +public class LoginResponse extends WebsocketMessage +{ + private String username; + + public String getUsername() + { + return username; + } + + public void setUsername(String username) + { + this.username = username; + } + + @Override + public String toString() + { + return "LoginResponse{" + "username=" + username + '}'; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Join.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Join.java new file mode 100644 index 0000000000..21aed0f653 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Join.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import java.util.UUID; +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.runelite.http.api.ws.WebsocketMessage; + +@Value +@EqualsAndHashCode(callSuper = true) +public class Join extends WebsocketMessage +{ + private final UUID partyId; + private final String name; +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Part.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Part.java new file mode 100644 index 0000000000..e284ff0cf8 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/Part.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import net.runelite.http.api.ws.WebsocketMessage; + +public class Part extends WebsocketMessage +{ +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMemberMessage.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMemberMessage.java new file mode 100644 index 0000000000..9d5cab8545 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMemberMessage.java @@ -0,0 +1,12 @@ +package net.runelite.http.api.ws.messages.party; + +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class PartyMemberMessage extends PartyMessage +{ + private UUID memberId; +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMessage.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMessage.java new file mode 100644 index 0000000000..709457ed8c --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/PartyMessage.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import net.runelite.http.api.ws.WebsocketMessage; + +public abstract class PartyMessage extends WebsocketMessage +{ + public PartyMessage() + { + _party = true; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserJoin.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserJoin.java new file mode 100644 index 0000000000..7f940e8060 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserJoin.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import java.util.UUID; +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.runelite.http.api.ws.WebsocketMessage; + +@Value +@EqualsAndHashCode(callSuper = true) +public class UserJoin extends WebsocketMessage +{ + private final UUID memberId; + private final UUID partyId; + private final String name; +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserPart.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserPart.java new file mode 100644 index 0000000000..e80c6002bd --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserPart.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import java.util.UUID; +import lombok.EqualsAndHashCode; +import lombok.Value; +import net.runelite.http.api.ws.WebsocketMessage; + +@Value +@EqualsAndHashCode(callSuper = true) +public class UserPart extends WebsocketMessage +{ + private final UUID memberId; +} diff --git a/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserSync.java b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserSync.java new file mode 100644 index 0000000000..c95038c9fa --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/ws/messages/party/UserSync.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.ws.messages.party; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +@Value +@EqualsAndHashCode(callSuper = true) +public class UserSync extends PartyMemberMessage +{ +} diff --git a/http-api/src/main/java/net/runelite/http/api/xp/XpClient.java b/http-api/src/main/java/net/runelite/http/api/xp/XpClient.java new file mode 100644 index 0000000000..c45fe2e209 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/xp/XpClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.xp; + +import java.io.IOException; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class XpClient +{ + private static final Logger logger = LoggerFactory.getLogger(XpClient.class); + + public void update(String username) + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("xp") + .addPathSegment("update") + .addQueryParameter("username", username) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + logger.warn("Error submitting xp track", e); + } + + @Override + public void onResponse(Call call, Response response) + { + response.close(); + logger.debug("Submitted xp track for {}", username); + } + }); + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/xp/XpData.java b/http-api/src/main/java/net/runelite/http/api/xp/XpData.java new file mode 100644 index 0000000000..348faa5c78 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/xp/XpData.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.xp; + +import java.time.Instant; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(exclude = "time") +public class XpData +{ + private Instant time; + + private int attack_xp; + private int defence_xp; + private int strength_xp; + private int hitpoints_xp; + private int ranged_xp; + private int prayer_xp; + private int magic_xp; + private int cooking_xp; + private int woodcutting_xp; + private int fletching_xp; + private int fishing_xp; + private int firemaking_xp; + private int crafting_xp; + private int smithing_xp; + private int mining_xp; + private int herblore_xp; + private int agility_xp; + private int thieving_xp; + private int slayer_xp; + private int farming_xp; + private int runecraft_xp; + private int hunter_xp; + private int construction_xp; + + private int overall_rank; + private int attack_rank; + private int defence_rank; + private int strength_rank; + private int hitpoints_rank; + private int ranged_rank; + private int prayer_rank; + private int magic_rank; + private int cooking_rank; + private int woodcutting_rank; + private int fletching_rank; + private int fishing_rank; + private int firemaking_rank; + private int crafting_rank; + private int smithing_rank; + private int mining_rank; + private int herblore_rank; + private int agility_rank; + private int thieving_rank; + private int slayer_rank; + private int farming_rank; + private int runecraft_rank; + private int hunter_rank; + private int construction_rank; +} diff --git a/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java b/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java new file mode 100644 index 0000000000..e4ee2c22b9 --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/xtea/XteaClient.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.xtea; + +import com.google.gson.JsonParseException; +import com.google.gson.reflect.TypeToken; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; +import net.runelite.http.api.RuneLiteAPI; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class XteaClient +{ + private static final MediaType JSON = MediaType.parse("application/json"); + + private static final Logger logger = LoggerFactory.getLogger(XteaClient.class); + + public void submit(XteaRequest xteaRequest) + { + String json = RuneLiteAPI.GSON.toJson(xteaRequest); + + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("xtea") + .build(); + + logger.debug("Built URI: {}", url); + + Request request = new Request.Builder() + .post(RequestBody.create(JSON, json)) + .url(url) + .build(); + + RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() + { + @Override + public void onFailure(Call call, IOException e) + { + logger.warn("unable to submit xtea keys", e); + } + + @Override + public void onResponse(Call call, Response response) + { + try + { + if (!response.isSuccessful()) + { + logger.debug("unsuccessful xtea response"); + } + } + finally + { + response.close(); + } + } + }); + } + + public List get() throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("xtea") + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + InputStream in = response.body().byteStream(); + // CHECKSTYLE:OFF + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken>() { }.getType()); + // CHECKSTYLE:ON + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } + + public XteaKey get(int region) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("xtea") + .addPathSegment(Integer.toString(region)) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + InputStream in = response.body().byteStream(); + return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), XteaKey.class); + } + catch (JsonParseException ex) + { + throw new IOException(ex); + } + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/xtea/XteaKey.java b/http-api/src/main/java/net/runelite/http/api/xtea/XteaKey.java new file mode 100644 index 0000000000..c108f223cb --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/xtea/XteaKey.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.xtea; + +public class XteaKey +{ + private int region; + private int keys[]; + + public int getRegion() + { + return region; + } + + public void setRegion(int region) + { + this.region = region; + } + + public int[] getKeys() + { + return keys; + } + + public void setKeys(int[] keys) + { + this.keys = keys; + } +} diff --git a/http-api/src/main/java/net/runelite/http/api/xtea/XteaRequest.java b/http-api/src/main/java/net/runelite/http/api/xtea/XteaRequest.java new file mode 100644 index 0000000000..f84c85b83b --- /dev/null +++ b/http-api/src/main/java/net/runelite/http/api/xtea/XteaRequest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api.xtea; + +import java.util.ArrayList; +import java.util.List; + +public class XteaRequest +{ + private int revision; + private List keys = new ArrayList<>(); + + public int getRevision() + { + return revision; + } + + public void setRevision(int revision) + { + this.revision = revision; + } + + public List getKeys() + { + return keys; + } + + public void addKey(XteaKey key) + { + keys.add(key); + } +} diff --git a/http-api/src/main/resources/runelite.properties b/http-api/src/main/resources/runelite.properties new file mode 100644 index 0000000000..4011664529 --- /dev/null +++ b/http-api/src/main/resources/runelite.properties @@ -0,0 +1,4 @@ +runelite.version=${project.version} +rs.version=${rs.version} +runelite.commit=${git.commit.id.abbrev} +runelite.dirty=${git.dirty} \ No newline at end of file diff --git a/http-api/src/test/java/net/runelite/http/api/RuneLiteAPITest.java b/http-api/src/test/java/net/runelite/http/api/RuneLiteAPITest.java new file mode 100644 index 0000000000..42fadf4363 --- /dev/null +++ b/http-api/src/test/java/net/runelite/http/api/RuneLiteAPITest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.http.api; + +import java.io.IOException; +import okhttp3.Request; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.After; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; + +public class RuneLiteAPITest +{ + private final MockWebServer server = new MockWebServer(); + + @Before + public void before() throws IOException + { + server.enqueue(new MockResponse().setBody("OK")); + + server.start(); + } + + @After + public void after() throws IOException + { + server.shutdown(); + } + + @Test + public void testUserAgent() throws IOException, InterruptedException + { + Request request = new Request.Builder() + .url(server.url("/").url()) + .build(); + RuneLiteAPI.CLIENT.newCall(request).execute().close(); + + // rest of UA depends on if git is found + assertTrue(server.takeRequest().getHeader("User-Agent").startsWith("RuneLite/" + RuneLiteAPI.getVersion())); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 23f3459193..47c4058b97 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ pom 1.0-SNAPSHOT + http-api RuneLitePlus api rs-client