Search in sources :

Example 86 with HttpUrl

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);
    }
}
Also used : Response(okhttp3.Response) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Request(okhttp3.Request) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) HttpUrl(okhttp3.HttpUrl)

Example 87 with HttpUrl

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);
    }
}
Also used : Response(okhttp3.Response) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Request(okhttp3.Request) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) HttpUrl(okhttp3.HttpUrl)

Example 88 with HttpUrl

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);
    }
}
Also used : Response(okhttp3.Response) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Request(okhttp3.Request) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) HttpUrl(okhttp3.HttpUrl)

Example 89 with HttpUrl

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);
        }
    }
}
Also used : Response(okhttp3.Response) InputStream(java.io.InputStream) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) ImageIO(javax.imageio.ImageIO)

Example 90 with HttpUrl

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();
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Aggregations

HttpUrl (okhttp3.HttpUrl)302 Request (okhttp3.Request)130 Test (org.junit.Test)86 Response (okhttp3.Response)69 IOException (java.io.IOException)61 MockResponse (okhttp3.mockwebserver.MockResponse)40 Cookie (okhttp3.Cookie)35 ArrayList (java.util.ArrayList)28 OkHttpClient (okhttp3.OkHttpClient)27 MockWebServer (okhttp3.mockwebserver.MockWebServer)26 InputStream (java.io.InputStream)21 InputStreamReader (java.io.InputStreamReader)20 HashMap (java.util.HashMap)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 RequestBody (okhttp3.RequestBody)18 JsonParseException (com.google.gson.JsonParseException)13 File (java.io.File)12 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)10 List (java.util.List)10 Test (org.junit.jupiter.api.Test)10