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 deleted file mode 100644 index 7bd1706cf4..0000000000 --- a/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeClient.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 java.nio.charset.StandardCharsets; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.api.RuneLiteAPI; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -@Slf4j -@AllArgsConstructor -public class OSBGrandExchangeClient -{ - private final OkHttpClient client; - - 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 = 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, StandardCharsets.UTF_8), 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 deleted file mode 100644 index 13e5f5e8e4..0000000000 --- a/http-api/src/main/java/net/runelite/http/api/osbuddy/OSBGrandExchangeResult.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java deleted file mode 100644 index 8ea34c10c9..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.service.osbuddy; - -import java.time.Instant; -import lombok.Data; - -@Data -class GrandExchangeEntry -{ - private int item_id; - private int buy_average; - private int sell_average; - private int overall_average; - private Instant last_update; -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java deleted file mode 100644 index eaade27c12..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.service.osbuddy; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.CacheControl; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/osb/ge") -public class OSBGrandExchangeController -{ - private final OSBGrandExchangeService grandExchangeService; - - @Autowired - public OSBGrandExchangeController(OSBGrandExchangeService grandExchangeService) - { - this.grandExchangeService = grandExchangeService; - } - - @GetMapping - public ResponseEntity get(@RequestParam("itemId") int itemId) throws ExecutionException - { - GrandExchangeEntry grandExchangeEntry = grandExchangeService.get(itemId); - - return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic()) - .body(grandExchangeEntry); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java deleted file mode 100644 index 49e9e4a636..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.service.osbuddy; - -import java.io.IOException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.Map; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.service.osbuddy.beans.OsbuddySummaryItem; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.Sql2o; - -@Service -@Slf4j -public class OSBGrandExchangeService -{ - private static final String CREATE_GRAND_EXCHANGE_PRICES = "CREATE TABLE IF NOT EXISTS `osb_ge` (\n" - + " `item_id` int(11) NOT NULL,\n" - + " `buy_average` int(11) NOT NULL,\n" - + " `sell_average` int(11) NOT NULL,\n" - + " `overall_average` int(11) NOT NULL,\n" - + " `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " PRIMARY KEY (`item_id`)\n" - + ") ENGINE=InnoDB"; - - private static final OsbuddyClient CLIENT = new OsbuddyClient(); - - private final Sql2o sql2o; - - @Autowired - public OSBGrandExchangeService(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_GRAND_EXCHANGE_PRICES).executeUpdate(); - } - } - - public GrandExchangeEntry get(int itemId) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("SELECT item_id, buy_average, sell_average, overall_average, last_update" - + " FROM osb_ge WHERE item_id = :itemId") - .addParameter("itemId", itemId) - .executeAndFetchFirst(GrandExchangeEntry.class); - } - } - - @Scheduled(initialDelay = 1000 * 5, fixedDelay = 1000 * 60 * 30) - private void updateDatabase() - { - try - { - Map summary = CLIENT.getSummary(); - - try (Connection con = sql2o.beginTransaction()) - { - Instant updateTime = Instant.now(); - - Query query = con.createQuery("INSERT INTO osb_ge (item_id, buy_average, sell_average, overall_average," - + " last_update) VALUES (:itemId, :buyAverage, :sellAverage, :overallAverage, :lastUpdate)" - + " ON DUPLICATE KEY UPDATE buy_average = VALUES(buy_average), sell_average = VALUES(sell_average)," - + " overall_average = VALUES(overall_average), last_update = VALUES(last_update)"); - - for (Map.Entry entry : summary.entrySet()) - { - Integer itemId = entry.getKey(); - OsbuddySummaryItem item = entry.getValue(); - - if (item.getBuy_average() <= 0 || item.getSell_average() <= 0 || item.getOverall_average() <= 0) - { - continue; - } - - query - .addParameter("itemId", itemId) - .addParameter("buyAverage", item.getBuy_average()) - .addParameter("sellAverage", item.getSell_average()) - .addParameter("overallAverage", item.getOverall_average()) - .addParameter("lastUpdate", Timestamp.from(updateTime)) - .addToBatch(); - } - - query.executeBatch(); - con.commit(false); - } - } - catch (IOException e) - { - log.warn("Error while updating the osb grand exchange table", e); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java deleted file mode 100644 index 585577511a..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.service.osbuddy; - -import com.google.gson.JsonSyntaxException; -import com.google.gson.reflect.TypeToken; -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Map; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.service.osbuddy.beans.OsbuddySummaryItem; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; - -public class OsbuddyClient -{ - public Map getSummary() throws IOException - { - HttpUrl httpUrl = new HttpUrl.Builder() - .scheme("https") - .host("storage.googleapis.com") - .addPathSegment("osb-exchange") - .addPathSegment("summary.json") - .build(); - - Request request = new Request.Builder() - .url(httpUrl) - .header("User-Agent", "RuneLite") - .build(); - - try (Response responseOk = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!responseOk.isSuccessful()) - { - throw new IOException("Error retrieving summary from OSBuddy: " + responseOk.message()); - } - - Type type = new TypeToken>() - { - }.getType(); - - return RuneLiteAPI.GSON.fromJson(responseOk.body().string(), type); - } - catch (JsonSyntaxException ex) - { - throw new IOException(ex); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java deleted file mode 100644 index 2f969d9636..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.service.osbuddy.beans; - -import lombok.Data; - -@Data -public class OsbuddySummaryItem -{ - private int id; - private String name; - private boolean members; - private int sp; - private int buy_average; - private int sell_average; - private int overall_average; -}