Search in sources :

Example 81 with HttpUrl

use of okhttp3.HttpUrl in project vimeo-networking-java by vimeo.

the class BaseUrlInterceptorTest method test_excludePathsForBaseUrl_UnsanitizedPaths_SuccessfullyIntercepts.

@Test
public void test_excludePathsForBaseUrl_UnsanitizedPaths_SuccessfullyIntercepts() throws Exception {
    HttpUrl httpUrl = HttpUrl.parse("http://localhost");
    mBaseUrlInterceptor.excludePathsForBaseUrl(httpUrl, "me", "you");
    mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/me"), createTestUrlForPath(null)));
    mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/you"), createTestUrlForPath(null)));
    mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/them"), httpUrl));
}
Also used : HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 82 with HttpUrl

use of okhttp3.HttpUrl in project runelite by runelite.

the class XteaClient method submit.

public Response submit(int revision, int region, int[] keys) throws IOException {
    XteaRequest xteaRequest = new XteaRequest();
    xteaRequest.setRevision(revision);
    XteaKey xteaKey = new XteaKey();
    xteaKey.setRegion(region);
    xteaKey.setKeys(keys);
    xteaRequest.addKey(xteaKey);
    String json = RuneLiteAPI.GSON.toJson(xteaRequest);
    HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("xtea").build();
    logger.debug("Built URI: {}", url);
    Request request = new Request.Builder().post(RequestBody.create(JSON, json)).url(url).build();
    return RuneLiteAPI.CLIENT.newCall(request).execute();
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 83 with HttpUrl

use of okhttp3.HttpUrl in project runelite by runelite.

the class XteaClient method get.

public List<XteaKey> get() throws IOException {
    HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("xtea").build();
    Request request = new Request.Builder().url(url).build();
    try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
        InputStream in = response.body().byteStream();
        // CHECKSTYLE:OFF
        return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken<List<XteaKey>>() {
        }.getType());
    // CHECKSTYLE:ON
    } catch (JsonParseException ex) {
        throw new IOException(ex);
    }
}
Also used : Response(okhttp3.Response) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) TypeToken(com.google.gson.reflect.TypeToken) Request(okhttp3.Request) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) HttpUrl(okhttp3.HttpUrl)

Example 84 with HttpUrl

use of okhttp3.HttpUrl in project runelite by runelite.

the class ConfigClient method unset.

public void unset(String key) throws IOException {
    HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("config").addPathSegment(key).build();
    logger.debug("Built URI: {}", url);
    Request request = new Request.Builder().delete().header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()).url(url).build();
    try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
        logger.debug("Unset configuration value '{}'", key);
    }
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 85 with HttpUrl

use of okhttp3.HttpUrl in project runelite by runelite.

the class ConfigClient method set.

public void set(String key, String value) throws IOException {
    HttpUrl url = RuneLiteAPI.getApiBase().newBuilder().addPathSegment("config").addPathSegment(key).build();
    logger.debug("Built URI: {}", url);
    Request request = new Request.Builder().put(RequestBody.create(TEXT_PLAIN, value)).header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()).url(url).build();
    try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
        logger.debug("Set configuration value '{}' to '{}'", key, value);
    }
}
Also used : Response(okhttp3.Response) 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