wiki price service: use v1 api

This commit is contained in:
Adam
2021-03-14 18:10:38 -04:00
parent 4b8f2120ed
commit ed978d31dd
3 changed files with 18 additions and 17 deletions

View File

@@ -25,13 +25,20 @@
*/ */
package net.runelite.http.service.wiki; package net.runelite.http.service.wiki;
import java.util.Map;
import lombok.Data; import lombok.Data;
@Data @Data
class ItemPrice class PriceResult
{ {
private int high; @Data
private int highTime; static class Item
private int low; {
private int lowTime; private int high;
private int highTime;
private int low;
private int lowTime;
}
private Map<Integer, Item> data;
} }

View File

@@ -26,9 +26,7 @@
package net.runelite.http.service.wiki; package net.runelite.http.service.wiki;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map; import java.util.Map;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
@@ -79,7 +77,7 @@ public class WikiPriceService
{ {
try try
{ {
Map<Integer, ItemPrice> summary = getPrices(); PriceResult summary = getPrices();
try (Connection con = sql2o.beginTransaction()) try (Connection con = sql2o.beginTransaction())
{ {
@@ -88,10 +86,10 @@ public class WikiPriceService
+ " ON DUPLICATE KEY UPDATE high = VALUES(high), highTime = VALUES(highTime)," + " ON DUPLICATE KEY UPDATE high = VALUES(high), highTime = VALUES(highTime),"
+ " low = VALUES(low), lowTime = VALUES(lowTime)"); + " low = VALUES(low), lowTime = VALUES(lowTime)");
for (Map.Entry<Integer, ItemPrice> entry : summary.entrySet()) for (Map.Entry<Integer, PriceResult.Item> entry : summary.getData().entrySet())
{ {
Integer itemId = entry.getKey(); Integer itemId = entry.getKey();
ItemPrice item = entry.getValue(); PriceResult.Item item = entry.getValue();
query query
.addParameter("itemId", itemId) .addParameter("itemId", itemId)
@@ -112,7 +110,7 @@ public class WikiPriceService
} }
} }
private Map<Integer, ItemPrice> getPrices() throws IOException private PriceResult getPrices() throws IOException
{ {
HttpUrl httpUrl = HttpUrl.parse(url); HttpUrl httpUrl = HttpUrl.parse(url);
Request request = new Request.Builder() Request request = new Request.Builder()
@@ -127,11 +125,7 @@ public class WikiPriceService
throw new IOException("Error retrieving prices: " + responseOk.message()); throw new IOException("Error retrieving prices: " + responseOk.message());
} }
Type type = new TypeToken<Map<Integer, ItemPrice>>() return RuneLiteAPI.GSON.fromJson(responseOk.body().string(), PriceResult.class);
{
}.getType();
return RuneLiteAPI.GSON.fromJson(responseOk.body().string(), type);
} }
catch (JsonSyntaxException ex) catch (JsonSyntaxException ex)
{ {

View File

@@ -46,6 +46,6 @@ runelite:
history: 90 # days history: 90 # days
wiki: wiki:
poll.ms: 300000 # 5 minutes poll.ms: 300000 # 5 minutes
url: https://prices.runescape.wiki/osrs/latest url: https://prices.runescape.wiki/api/v1/osrs/latest
price: price:
cache: 30 # minutes cache: 30 # minutes