use of okhttp3.HttpUrl in project runelite by runelite.
the class ConfigClient method get.
public Configuration get() throws IOException {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("config").build();
logger.debug("Built URI: {}", url);
Request request = new Request.Builder().header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()).url(url).build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), Configuration.class);
} catch (JsonParseException ex) {
throw new IOException(ex);
}
}
use of okhttp3.HttpUrl in project runelite by runelite.
the class HiscoreClient method lookup.
public SingleHiscoreSkillResult lookup(String username, HiscoreSkill skill, HiscoreEndpoint endpoint) throws IOException {
HttpUrl.Builder builder = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("hiscore").addPathSegment(endpoint.name()).addPathSegment(skill.toString().toLowerCase()).addQueryParameter("username", username);
HttpUrl url = builder.build();
logger.debug("Built URI: {}", url);
Request request = new Request.Builder().url(url).build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), SingleHiscoreSkillResult.class);
} catch (JsonParseException ex) {
throw new IOException(ex);
}
}
use of okhttp3.HttpUrl in project runelite by runelite.
the class ItemClient method search.
public SearchResult search(String itemName) throws IOException {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("item").addPathSegment("search").addQueryParameter("query", itemName).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 item {}: {}", itemName, response.message());
return null;
}
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), SearchResult.class);
} catch (JsonParseException ex) {
throw new IOException(ex);
}
}
use of okhttp3.HttpUrl in project runelite by runelite.
the class ItemClient method getIcon.
public BufferedImage getIcon(int itemId) throws IOException {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("item").addPathSegment("" + itemId).addPathSegment("icon").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 grabbing icon {}: {}", itemId, response.message());
return null;
}
InputStream in = response.body().byteStream();
synchronized (ImageIO.class) {
return ImageIO.read(in);
}
}
}
use of okhttp3.HttpUrl in project runelite by runelite.
the class SessionClient method delete.
public void delete(UUID uuid) throws IOException {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("session").addQueryParameter("session", uuid.toString()).build();
Request request = new Request.Builder().delete().url(url).build();
RuneLiteAPI.CLIENT.newCall(request).execute().close();
}
Aggregations