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); } }
UUID open() throws IOException { HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder() .addPathSegment("session") .build(); Request request = new Request.Builder() .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { ResponseBody body = response.body(); InputStream in = body.byteStream(); return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), UUID.class); } catch (JsonParseException | IllegalArgumentException ex) // UUID.fromString can throw IllegalArgumentException { throw new IOException(ex); } }
public void logout() throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("account") .addPathSegment("logout") .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()) { logger.debug("Sent logout request"); } }
public boolean submitTask(String username, String task, int amount, int initialAmount, String location) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") .addPathSegment("task") .addQueryParameter("name", username) .addQueryParameter("task", task) .addQueryParameter("amount", Integer.toString(amount)) .addQueryParameter("initialAmount", Integer.toString(initialAmount)) .addQueryParameter("location", location) .build(); Request request = new Request.Builder() .post(RequestBody.create(null, new byte[0])) .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { return response.isSuccessful(); } }
public XteaKey get(int region) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("xtea") .addPathSegment(Integer.toString(region)) .build(); 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), XteaKey.class); } catch (JsonParseException ex) { throw new IOException(ex); } } }
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); } }
public int getQp(String username) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") .addPathSegment("qp") .addQueryParameter("name", username) .build(); Request request = new Request.Builder() .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { if (!response.isSuccessful()) { throw new IOException("Unable to look up quest points!"); } return Integer.parseInt(response.body().string()); } }
private Request postLogin(String username, String password, boolean createAccount) { FormBody.Builder formBuilder = new FormBody.Builder() .add(LOGIN_PARAM_ACCT, username) .add(LOGIN_PARAM_PW, password) .add(LOGIN_PARAM_GOTO, DEFAULT_REDIRECT); if (createAccount) { formBuilder.add(LOGIN_PARAM_CREATING, CREATING_TRUE); } return new Request.Builder() .url(HttpUrl.parse(BASE_WEB_URL) .newBuilder() .addPathSegment(LOGIN_PATH) .build()) .post(formBuilder.build()) .build(); }
void ping(UUID uuid) throws IOException { HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder() .addPathSegment("session") .addPathSegment("ping") .addQueryParameter("session", uuid.toString()) .build(); Request request = new Request.Builder() .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { if (!response.isSuccessful()) { throw new IOException("Unsuccessful ping"); } } }
public boolean submitKc(String username, String boss, int kc) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") .addPathSegment("kc") .addQueryParameter("name", username) .addQueryParameter("boss", boss) .addQueryParameter("kc", Integer.toString(kc)) .build(); Request request = new Request.Builder() .post(RequestBody.create(null, new byte[0])) .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { return response.isSuccessful(); } }
@Test public void respectsHttpClientUri_endpointGroup() throws Exception { EndpointGroupRegistry.register("foo", new StaticEndpointGroup(Endpoint.of("127.0.0.1", server.httpPort())), ROUND_ROBIN); final Service service = new ArmeriaRetrofitBuilder() .baseUrl("http://group:foo/") .addConverterFactory(JacksonConverterFactory.create(OBJECT_MAPPER)) .build() .create(Service.class); final Response<Pojo> response = service.postForm("Cony", 26).get(); // TODO(ide) Use the actual `host:port`. See https://github.com/line/armeria/issues/379 assertThat(response.raw().request().url()).isEqualTo( new HttpUrl.Builder().scheme("http") .host("group_foo") .addPathSegment("postForm") .build()); }
public boolean submitPb(String username, String boss, int pb) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") .addPathSegment("pb") .addQueryParameter("name", username) .addQueryParameter("boss", boss) .addQueryParameter("pb", Integer.toString(pb)) .build(); Request request = new Request.Builder() .post(RequestBody.create(null, new byte[0])) .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { return response.isSuccessful(); } }
public boolean submitQp(String username, int qp) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") .addPathSegment("qp") .addQueryParameter("name", username) .addQueryParameter("qp", Integer.toString(qp)) .build(); Request request = new Request.Builder() .post(RequestBody.create(null, new byte[0])) .url(url) .build(); try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) { return response.isSuccessful(); } }
static String buildXpTrackerUrl(final Actor player, final Skill skill) { if (player == null) { return ""; } return new HttpUrl.Builder() .scheme("https") .host("runelite.net") .addPathSegment("xp") .addPathSegment("show") .addPathSegment(skill.getName().toLowerCase()) .addPathSegment(player.getName()) .addPathSegment("1week") .addPathSegment("now") .build() .toString(); }
private Request postVote(String username, String password, String itemId) { return new Request.Builder() .url(HttpUrl.parse(BASE_WEB_URL) .newBuilder() .addPathSegment(VOTE_PATH) .build()) .post(new FormBody.Builder() .add(LOGIN_PARAM_ACCT, username) .add(LOGIN_PARAM_PW, password) .add(VOTE_PARAM_ID, itemId) .add(VOTE_PARAM_HOW, VOTE_DIR_UP) .build()) .build(); }
private Request postReply(String parentId, String text, String username, String password) { return new Request.Builder() .url(HttpUrl.parse(BASE_WEB_URL) .newBuilder() .addPathSegment(COMMENT_PATH) .build()) .post(new FormBody.Builder() .add(LOGIN_PARAM_ACCT, username) .add(LOGIN_PARAM_PW, password) .add(COMMENT_PARAM_PARENT, parentId) .add(COMMENT_PARAM_TEXT, text) .build()) .build(); }
private Request postSubmitForm(String username, String password) { return new Request.Builder() .url(HttpUrl.parse(BASE_WEB_URL) .newBuilder() .addPathSegment(SUBMIT_PATH) .build()) .post(new FormBody.Builder() .add(LOGIN_PARAM_ACCT, username) .add(LOGIN_PARAM_PW, password) .build()) .build(); }
void delete(UUID uuid) throws IOException { HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder() .addPathSegment("session") .addQueryParameter("session", uuid.toString()) .build(); Request request = new Request.Builder() .delete() .url(url) .build(); RuneLiteAPI.CLIENT.newCall(request).execute().close(); } }
@Test public void respectsHttpClientUri() throws Exception { final Response<Pojo> response = service.postForm("Cony", 26).get(); assertThat(response.raw().request().url()).isEqualTo( new HttpUrl.Builder().scheme("http") .host("127.0.0.1") .port(server.httpPort()) .addPathSegment("postForm") .build()); }
private void openLoginInBrowser() { String initialScope = "user,public_repo,repo,delete_repo,notifications,gist"; HttpUrl.Builder url = new HttpUrl.Builder() .scheme("https") .host(OAUTH_HOST) .addPathSegment("login") .addPathSegment("oauth") .addPathSegment("authorize") .addQueryParameter("client_id", getString(R.string.github_client)) .addQueryParameter("scope", initialScope); Intent intent = new Intent(this, LoginWebViewActivity.class); intent.putExtra(INTENT_EXTRA_URL, url.toString()); startActivityForResult(intent, WEBVIEW_REQUEST_CODE); }