http-api: add batch lookup to ItemClient

This commit is contained in:
Jeremy Plsek
2018-03-18 11:32:33 -04:00
committed by Adam
parent 53d8286db8
commit c12dc9b6c7

View File

@@ -29,6 +29,7 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import javax.imageio.ImageIO;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.HttpUrl;
@@ -72,6 +73,42 @@ public class ItemClient
}
}
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.message());
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()