From 6f76825b37013da9a3bd8aeafbc0fbae6cacce59 Mon Sep 17 00:00:00 2001 From: Tanish Azad Date: Tue, 7 Nov 2023 23:57:37 +0530 Subject: [PATCH] added raw response to InstagramResponse --- .../github/taz03/jia/requests/InstagramRequest.java | 11 +++++++---- .../taz03/jia/responses/InstagramResponse.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/io/github/taz03/jia/requests/InstagramRequest.java b/lib/src/main/java/io/github/taz03/jia/requests/InstagramRequest.java index 152776c..85cb10a 100644 --- a/lib/src/main/java/io/github/taz03/jia/requests/InstagramRequest.java +++ b/lib/src/main/java/io/github/taz03/jia/requests/InstagramRequest.java @@ -1,8 +1,8 @@ package io.github.taz03.jia.requests; import java.net.http.HttpRequest; -import java.util.List; import java.util.Map; +import java.util.stream.Stream; import io.github.taz03.jia.InstagramClient; import io.github.taz03.jia.responses.InstagramResponse; @@ -41,7 +41,7 @@ protected InstagramRequest(Class responseType, String path, Map 0) + if (queries != null && !queries.isEmpty()) url += "?" + UrlUtils.makeBody(queries); } @@ -73,7 +73,10 @@ public Class getResponseType() { * @return Parsed response class */ public T parseResponse(String json) throws JsonProcessingException { - return mapper.readValue(json, responseType); + T response = mapper.readValue(json, responseType); + response.setJson(json); + + return response; } protected Map getHeaders(InstagramClient client) { @@ -86,7 +89,7 @@ protected Map getHeaders(InstagramClient client) { protected static String[] makeHeaderArray(Map headers) { return headers.keySet().stream() - .flatMap(key -> List.of(key, headers.get(key).toString()).stream()) + .flatMap(key -> Stream.of(key, headers.get(key).toString())) .toList() .toArray(new String[0]); } diff --git a/lib/src/main/java/io/github/taz03/jia/responses/InstagramResponse.java b/lib/src/main/java/io/github/taz03/jia/responses/InstagramResponse.java index 6e76f90..272f8f8 100644 --- a/lib/src/main/java/io/github/taz03/jia/responses/InstagramResponse.java +++ b/lib/src/main/java/io/github/taz03/jia/responses/InstagramResponse.java @@ -5,6 +5,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class InstagramResponse { + private String json; + @JsonProperty("status") private String status; @JsonProperty("message") @@ -20,6 +22,17 @@ public class InstagramResponse { @JsonProperty("checkpoint_url") private String checkpointUrl; + public void setJson(String json) { + this.json = json; + } + + /** + * @return The raw json response + */ + public String getJson() { + return json; + } + public String getStatus() { return status; }