loot tracker client: add get and delete methods
This commit is contained in:
@@ -25,7 +25,13 @@
|
|||||||
package net.runelite.http.api.loottracker;
|
package net.runelite.http.api.loottracker;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import java.io.IOException;
|
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 java.util.UUID;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -75,4 +81,68 @@ public class LootTrackerClient
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<LootRecord> get() throws IOException
|
||||||
|
{
|
||||||
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
|
.addPathSegment("loottracker")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
|
||||||
|
.get()
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
|
{
|
||||||
|
if (!response.isSuccessful())
|
||||||
|
{
|
||||||
|
log.debug("Error looking up loot: {}", response.message());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream in = response.body().byteStream();
|
||||||
|
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken<List<LootRecord>>()
|
||||||
|
{
|
||||||
|
}.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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user