From 2fcfeee6663ac10f437a1d854192d904a6fa1128 Mon Sep 17 00:00:00 2001 From: ivarnm <36505347+ivarnm@users.noreply.github.com> Date: Tue, 17 Mar 2020 20:30:58 +0100 Subject: [PATCH] #10 Add putRoundScore --- .../com/gameware/game/QueryIntermediate.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/core/src/com/gameware/game/QueryIntermediate.java b/frontend/core/src/com/gameware/game/QueryIntermediate.java index 79d2c07..154fdc3 100644 --- a/frontend/core/src/com/gameware/game/QueryIntermediate.java +++ b/frontend/core/src/com/gameware/game/QueryIntermediate.java @@ -43,6 +43,14 @@ public class QueryIntermediate { return sendRequest(httpPost); } + private static String[] sendPutRequest(String route, Map<String, String> params) { + HttpRequest httpPut = new HttpRequest(HttpMethods.PUT); + httpPut.setUrl(baseUrl + route); + httpPut.setHeader("Content-Type", "application/x-www-form-urlencoded"); + httpPut.setContent(HttpParametersUtils.convertHttpParameters(params)); + return sendRequest(httpPut); + } + // Send a request to server and return response code and text private static String[] sendRequest(HttpRequest request) { final String[] response = new String[2]; @@ -224,5 +232,16 @@ public class QueryIntermediate { return round; } + public static Round putRoundScore(String roundId, int score) throws IOException, NoSuchElementException { + String route = "rounds/" + roundId; + Map<String, String> params = new HashMap<>(); + params.put("scoreValue", Integer.toString(score)); + String[] response = sendPutRequest(route, params); + checkStatusCode(response); + Round round = json.fromJson(Round.class, response[1]); + checkObjectNotNull(round); + return round; + } + } -- GitLab