Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
added raw response to InstagramResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Taz03 committed Nov 7, 2023
1 parent b246d08 commit 6f76825
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +41,7 @@ protected InstagramRequest(Class<T> responseType, String path, Map<String, Objec
this.responseType = responseType;
this.url += path;

if (queries != null && queries.size() > 0)
if (queries != null && !queries.isEmpty())
url += "?" + UrlUtils.makeBody(queries);
}

Expand Down Expand Up @@ -73,7 +73,10 @@ public Class<T> 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<String, Object> getHeaders(InstagramClient client) {
Expand All @@ -86,7 +89,7 @@ protected Map<String, Object> getHeaders(InstagramClient client) {

protected static String[] makeHeaderArray(Map<String, Object> 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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class InstagramResponse {
private String json;

@JsonProperty("status")
private String status;
@JsonProperty("message")
Expand All @@ -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;
}
Expand Down

0 comments on commit 6f76825

Please sign in to comment.