Refine search
public void completed(HttpResponse<JsonNode> response) { JSONObject responseBody = response.getBody().getObject(); if ("ERROR".equals(responseBody.getString("result"))) { onFail((JSONObject) responseBody.get("data")); return; } onSuccess(responseBody.getJSONObject("data")); }
HttpRequest request = Unirest.get(branchesUrl); addSecurityTo(request); HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson(); JSONObject responseObj = response.getBody().getObject(); if (response.getStatus() != 200) { throw new UnirestException("Unexpected response from Bitbucket: " + response.getStatus() + "::" + response.getStatusText()); responseObj.getJSONArray("values").forEach(obj -> { JSONObject b = (JSONObject) obj; SourceCodeBranch branch = new SourceCodeBranch(); branch.setName(b.getString("name")); branch.setCommitId(b.getJSONObject("target").getString("hash")); rVal.add(branch); });
HttpResponse<JsonNode> response = Unirest.get("https://api.github.com/repos/apicurio/apicurio-studio/releases/tags/v" + oldReleaseTag) .header("Accept", "application/json").header("Authorization", "token " + githubPAT).asJson(); if (response.getStatus() != 200) { throw new Exception("Failed to get old release info: " + response.getStatusText()); JsonNode body = response.getBody(); String publishedDate = body.getObject().getString("published_at"); if (publishedDate == null) { throw new Exception("Could not find Published Date for previous release " + oldReleaseTag); HttpResponse<JsonNode> response = Unirest.post("https://api.github.com/repos/apicurio/apicurio-studio/releases") .header("Accept", "application/json") .header("Content-Type", "application/json") .header("Authorization", "token " + githubPAT) .body(body).asJson(); if (response.getStatus() != 201) { throw new Exception("Failed to create release in GitHub: " + response.getStatusText()); assetUploadUrl = response.getBody().getObject().getString("upload_url"); if (assetUploadUrl == null || assetUploadUrl.trim().isEmpty()) { throw new Exception("Failed to get Asset Upload URL for newly created release!"); if (response.getStatus() != 201) { throw new Exception("Failed to upload asset: " + releaseArtifact, new Exception(response.getStatus() + "::" + response.getStatusText())); if (response.getStatus() != 201) { throw new Exception("Failed to upload asset: " + releaseArtifactSig, new Exception(response.getStatus() + "::" + response.getStatusText())); if (response.getStatus() != 200) {
public String ask(String query) throws UnirestException { JSONObject jsonOut = new JSONObject(); jsonOut.put("user", user) .put("key", key) .put("nick", session) .put("text", query); RequestBodyEntity post = Unirest.post("https://cleverbot.io/1.0/ask").header("Content-Type", "application/json") .body(jsonOut.toString()); JSONObject json = post.asJson().getBody().getObject(); return json.getString("response"); } }
protected JSONArray getJSonArray(BaseRequest request) throws UnirestException { HttpResponse<String> response = request.asString(); if (response.getStatus() == 423) { String error = new JSONObject(response.getBody()).getString("detail"); throw new SeleniumRobotServerException(error); } if (response.getStatus() >= 400) { try { String error = new JSONObject(response.getBody()).getString("detail"); throw new SeleniumRobotServerException(String.format("request to %s failed: %s", request.getHttpRequest().getUrl(), error)); } catch (Exception e) { throw new UnirestException(String.format("request to %s failed: %s", request.getHttpRequest().getUrl(), response.getStatusText())); } } if (response.getStatus() == 204) { return new JSONArray(); } return new JSONArray(response.getBody()); }
/** * Check for updates against the GitHub repo releases page. * * @param pluginVersion the locally installed plugin version */ public static void checkForUpdates(String pluginVersion) { try { HttpResponse<JsonNode> res = Unirest.get("https://api.github.com/repos/" + GITHUB_ORG + "/Lukkit/releases/latest").asJson(); String tagName = res.getBody().getObject().getString("tag_name").replace("v", ""); if (isOutOfDate(pluginVersion.split("-")[0], tagName)) { Main.logger.info("A new version of Lukkit has been released: " + tagName); Main.logger.info("You can download it from https://www.spigotmc.org/resources/lukkit.32599/ or https://github.com/jammehcow/Lukkit/releases"); } else { Main.logger.info("You're up to date with the latest version of Lukkit."); } } catch (Exception e ) { e.printStackTrace(); } }
public Image uploadImage(File file) throws Exception { // {"data":{"bandwidth":0,"nsfw":null,"is_ad":false,"link":"http://i.imgur.com/4a2U4HI.png","description":null,"section":null,"title":null,"type":"image/png","tags":[],"deletehash":"g5KtSKSSXT2l54Q","datetime":1490023631,"account_id":0,"size":258,"width":35,"account_url":null,"name":"","animated":false,"id":"4a2U4HI","in_gallery":false,"vote":null,"favorite":false,"views":0,"height":35},"success":true,"status":200} HttpResponse<JsonNode> response = Unirest .post("https://api.imgur.com/3/image") .header("accept", "application/json") .header("Authorization", "Client-ID " + clientId) .field("image", file) .field("name", file.getName()) .field("title", file.getName()) .asJson(); if (!response.getBody().getObject().getBoolean("success")) { Logger.debug(response.getBody().toString()); throw new Exception(response.getBody().getObject().getJSONObject("data").getString("error")); } Image image = new Image(); image.id = response.getBody().getObject().getJSONObject("data").getString("id"); image.deleteHash = response.getBody().getObject().getJSONObject("data").getString("deletehash"); return image; }
org.json.JSONObject jsonObject = new org.json.JSONObject(value); generatedJSON= jsonObject.toString(); }catch (org.json.JSONException e){ track.fail( "Error al compilar el BODY:"+value+":" + e.getMessage()); case "PRINT": if (lastResponse!=null) { track.debug("Last Response,Status:" + lastResponse.getStatus() + "-" + lastResponse.getStatusText()); track.debug("Last Response,Headers:" + lastResponse.getHeaders().toString()); track.debug("Last Response,Body:"); if (lastResponse.getBody()!= null) { track.debug((new org.json.JSONObject(lastResponse.getBody())).toString(4)); Unirest.setDefaultHeader(objectName.trim(),value.trim()); break; case "CLEAN_DEFAULT_HEADER": Unirest.clearDefaultHeaders(); break; case "ADD_HEADER":
public boolean login(String username, String password) throws UnirestException { JSONObject creds = new JSONObject(); creds.put("username", username); creds.put("password", password); String body = Unirest.post(url + "api/login") .body(creds) .asString() .getBody(); UnifiResponse login = gson.fromJson(body, UnifiResponse.class); if (login.getMeta().containsKey("rc") && login.getMeta().get("rc").equalsIgnoreCase("ok")) { return true; } else { return false; } }
/** * Send the payload to Discord. * * @throws WebhookException the webhook exception */ public void send() throws WebhookException { if (this.embed.toString().length() > 6000) throw new WebhookException("Embed object larger than the limit (" + this.embed.toString().length() + ">6000)."); this.obj.put("embeds", new JSONArray().put(this.embed)); try { HttpResponse<JsonNode> response = Unirest.post(this.webhookUrl).header("Content-Type", "application/json").body(this.obj).asJson(); try { if (response.getBody() == null || response.getBody().getObject().get("embeds") == null) throw new JSONException("Expected."); throw new WebhookException(response.getBody().getObject().toString(2)); } catch (JSONException ignored) {} } catch (UnirestException e) { e.printStackTrace(); } } }
public List<GankIssue> loadGankIOIssues() throws UnirestException { List<GankIssue> issues = new ArrayList<GankIssue>(); HttpResponse<JsonNode> jsonResponse = Unirest.get(API_DATES).asJson(); JSONObject jsonObject = jsonResponse.getBody().getObject(); JSONArray results = jsonObject.getJSONArray("results"); int len = results.length(); for (int i = 0; i < len; i++) { issues.add(parseIssue(results.getString(i), len - i)); } return issues; }
.toString(); HttpRequestWithBody request = Unirest.put(createContentUrl).header("Content-Type", "application/json; charset=utf-8"); addSecurityTo(request); HttpResponse<JsonNode> response = request.body(requestBody).asJson(); if (response.getStatus() != 200) { throw new UnirestException("Unexpected response from GitHub: " + response.getStatus() + "::" + response.getStatusText()); JsonNode node = response.getBody(); String newSha = node.getObject().getJSONObject("content").getString("sha"); String commitSha = node.getObject().getJSONObject("commit").getString("sha"); this.addCommitComment(repositoryUrl, commitSha, commitComment);
private void login() throws IOException { HttpResponse<JsonNode> loginResult; try { loginResult = Unirest.post(serverUrl + "v1/login").field("username", user).field("password", password).asJson(); } catch (UnirestException e) { throw new IOException(e); } if (loginResult.getStatus() == 401) throw new IOException("The username and password provided are incorrect."); if (loginResult.getStatus() != 200) throw new IOException("The login failed with a result of: " + loginResult.getStatus()); JSONObject data = loginResult.getBody().getObject().getJSONObject("data"); this.authToken = data.getString("authToken"); this.userId = data.getString("userId"); }
public boolean isMountebankAllowingInjection() { try { HttpResponse<JsonNode> response = Unirest.get(baseUrl + "/config").asJson(); return response.getBody().getObject().getJSONObject("options").getBoolean("allowInjection"); } catch (UnirestException e) { return false; } }
/** * transfer script from DCM */ public static ScriptRequestResponse getScriptFromRequest(HttpResponse<JsonNode> uploadRequest) { int status = uploadRequest.getStatus(); JsonNode body = uploadRequest.getBody(); logger.fine("Got " + status + " with body: " + body); if (status == 404) { return new ScriptRequestResponse(status); } int httpStatusCode = uploadRequest.getStatus(); String script = body.getObject().getString("script"); String datasetIdentifier = body.getObject().getString("datasetIdentifier"); long userId = body.getObject().getLong("userId"); ScriptRequestResponse scriptRequestResponse = new ScriptRequestResponse(httpStatusCode, datasetIdentifier, userId, script); return scriptRequestResponse; }
/** * dumps a string to hastebin * * @param message the text to send * @return key how to find it */ private static String handleHastebin(String message) throws UnirestException { return Unirest.post("https://hastebin.com/documents").body(message).asJson().getBody().getObject().getString("key"); } }
while (currentPageUrl != null) { System.out.println("Querying page " + pageNum + " of issues."); HttpResponse<JsonNode> response = Unirest.get(currentPageUrl) .header("Accept", "application/json").header("Authorization", "token " + githubPAT).asJson(); if (response.getStatus() != 200) { throw new Exception("Failed to list Issues: " + response.getStatusText()); JSONArray issueNodes = response.getBody().getArray(); issueNodes.forEach(issueNode -> { JSONObject issue = (JSONObject) issueNode; String closedOn = issue.getString("closed_at"); if (since.compareTo(closedOn) < 0) { rval.add(issue); String allLinks = response.getHeaders().getFirst("Link"); Map<String, Link> links = Link.parseAll(allLinks); if (links.containsKey("next")) {
Headers headers = jsonResponse.getHeaders(); XRateLimit = Integer.valueOf(headers.getFirst("X-RateLimit-Limit")); XRateRemaining = Integer.valueOf(headers.getFirst("X-RateLimit-Remaining")); XRateReset = Integer.valueOf(headers.getFirst("X-RateLimit-Reset")); switch (jsonResponse.getStatus()){ case 200: return jsonResponse.getBody().getArray(); case 401: throw new ConnectException("Bad GitHub credentials provided, please edit your config"); case 403: log.info(jsonResponse.getBody().getObject().getString("message")); log.info(String.format("Your rate limit is %s", XRateLimit)); log.info(String.format("Your remaining calls is %s", XRateRemaining)); default: log.error(constructUrl(page, since)); log.error(String.valueOf(jsonResponse.getStatus())); log.error(jsonResponse.getBody().toString()); log.error(jsonResponse.getHeaders().toString()); log.error("Unknown error: Sleeping 5 seconds " + "before re-trying");