Class ItemPriceService
- java.lang.Object
-
- com.kraken.api.service.util.price.ItemPriceService
-
@Singleton public class ItemPriceService extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ItemPriceService(okhttp3.OkHttpClient okHttpClient, com.google.gson.Gson gson)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidgetItemPrice(int itemId, java.lang.String userAgent, java.util.function.Consumer<ItemPrice> callback)Retrieves the price for a specific item.ItemPricegetItemPriceSync(int itemId, java.lang.String userAgent)voidrefreshAllPrices(java.lang.String userAgent)Asynchronously fetches prices for ALL items to populate the cache.
-
-
-
Method Detail
-
getItemPrice
public void getItemPrice(int itemId, java.lang.String userAgent, java.util.function.Consumer<ItemPrice> callback)Retrieves the price for a specific item.1. Checks the local cache. 2. If missing, performs a non blocking network request for that specific item. This is safe to use on or off the RuneLite client thread.
- Parameters:
itemId- The OSRS Item IDuserAgent- A user agent sent to the OSRS Wiki to identify the application fetching data. This should NOT be the basic java user agent or contain information about your plugins or client as it is sent to the Wiki and likely inspected.callback- A functional interface for consuming the result of the asynchronous API call- Throws:
java.lang.RuntimeException- if called on the main client thread (optional safety check you could add)
-
getItemPriceSync
public ItemPrice getItemPriceSync(int itemId, java.lang.String userAgent)
-
refreshAllPrices
public void refreshAllPrices(java.lang.String userAgent)
Asynchronously fetches prices for ALL items to populate the cache. Useful for plugin startup.- Parameters:
userAgent- A user agent sent to the OSRS Wiki to identify the application fetching data. This should NOT be the basic java user agent or contain information about your plugins or client as it is sent to the Wiki and likely inspected.
-
-