public int deleteAllImposters() { try { HttpResponse<JsonNode> response = Unirest.delete(baseUrl + "/imposters").asJson(); return response.getStatus(); } catch (UnirestException e) { return 500; } }
public String deleteImposter(int port) { try { HttpResponse<JsonNode> response = Unirest.delete(baseUrl + "/imposters/" + port).asJson(); return response.getBody().toString(); } catch (UnirestException e) { return null; } }
/** * Kill all apps that are currently running. */ @Override public void killAllApps() { String marathonEndpoint = getServiceUrl().toString(); JSONObject appsResponse; try { appsResponse = Unirest.get(marathonEndpoint + APPS_ENDPOINT).header(HEADER_ACCEPT, APPLICATION_JSON).asJson().getBody().getObject(); if (appsResponse.length() == 0) { return; } } catch (UnirestException e) { throw new MinimesosException("Could not retrieve apps from Marathon at " + marathonEndpoint, e); } JSONArray apps = appsResponse.getJSONArray("apps"); for (int i = 0; i < apps.length(); i++) { JSONObject app = apps.getJSONObject(i); String appId = app.getString("id"); try { Unirest.delete(marathonEndpoint + APPS_ENDPOINT + appId).asJson(); } catch (UnirestException e) { //NOSONAR // failed to delete one app; continue with others LOGGER.error("Could not delete app " + appId + " at " + marathonEndpoint, e); } } }
public static UserProfilePhotos createUserProfilePhotos(long user_id, TelegramBot telegramBot) { try { JSONObject json = Unirest.post(telegramBot.getBotAPIUrl() + "getUserProfilePhotos") .queryString("user_id", user_id).asJson().getBody().getObject(); if(json.getBoolean("ok")) { return new UserProfilePhotosImpl(json.getJSONObject("result")); } } catch (UnirestException e) { e.printStackTrace(); } return null; }
@Test public void shouldDeleteAllImposters() throws UnirestException { when(Unirest.delete(Client.DEFAULT_BASE_URL + "/imposters")).thenReturn(requestWithBody); when(requestWithBody.asJson()).thenReturn(httpResponse); when(httpResponse.getStatus()).thenReturn(Integer.valueOf(200)); assertThat(client.deleteAllImposters()).isEqualTo(200); }
@Test public void shouldDeleteAnImposter() throws UnirestException { String deleteResponse = "{ url: http://localhost:5757 }"; when(Unirest.delete(Client.DEFAULT_BASE_URL + "/imposters/5757")).thenReturn(requestWithBody); when(requestWithBody.asJson()).thenReturn(httpResponse); when(httpResponse.getBody()).thenReturn(value); when(value.toString()).thenReturn(deleteResponse); String response = client.deleteImposter(5757); assertThat(response).contains("5757").contains("http"); }
default HttpResponse<JsonNode> deleteTdef(String namespace, String name, long version) throws UnirestException, KevoreeRegistryException { // be sure user is logged-in / refresh token if necessary / throws otherwise this.ensureLogin(); // DELETE tdef return Unirest.delete(this.baseUrl() + "/api/namespaces/{namespace}/tdefs/{name}/{version}") .header("Authorization", "Bearer " + config().getString("user.access_token")) .routeParam("namespace", namespace) .routeParam("name", name) .routeParam("version", String.valueOf(version)) .asJson(); } }
default HttpResponse<JsonNode> deleteDu(String namespace, String tdefName, long tdefVersion, String name, String version, String platform) throws UnirestException, KevoreeRegistryException { // be sure user is logged-in / refresh token if necessary / throws otherwise this.ensureLogin(); // DELETE du return Unirest.delete(this.baseUrl() + "/api/namespaces/{namespace}/tdefs/{tdefName}/{tdefVersion}/dus/{name}/{version}/{platform}") .header("Authorization", "Bearer " + config().getString("user.access_token")) .routeParam("namespace", namespace) .routeParam("tdefName", tdefName) .routeParam("tdefVersion", String.valueOf(tdefVersion)) .routeParam("name", name) .routeParam("version", version) .routeParam("platform", platform) .asJson(); } }