Search in sources :

Example 6 with StatusResult

use of org.brunocvcunha.instagram4j.requests.payload.StatusResult in project instagram4j by brunocvcunha.

the class InstagramRequest method parseJson.

/**
 * Parses Json into type, considering the status code
 * @param statusCode HTTP Status Code
 * @param str Entity content
 * @param clazz Class
 * @return Result
 */
@SneakyThrows
public <U> U parseJson(int statusCode, String str, Class<U> clazz) {
    if (clazz.isAssignableFrom(StatusResult.class)) {
        // TODO: implement a better way to handle exceptions
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            StatusResult result = (StatusResult) clazz.newInstance();
            result.setStatus("error");
            result.setMessage("SC_NOT_FOUND");
            return (U) result;
        } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
            StatusResult result = (StatusResult) clazz.newInstance();
            result.setStatus("error");
            result.setMessage("SC_FORBIDDEN");
            return (U) result;
        }
    }
    return parseJson(str, clazz);
}
Also used : StatusResult(org.brunocvcunha.instagram4j.requests.payload.StatusResult) SneakyThrows(lombok.SneakyThrows)

Aggregations

StatusResult (org.brunocvcunha.instagram4j.requests.payload.StatusResult)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 HttpPost (org.apache.http.client.methods.HttpPost)4 InstagramExposeRequest (org.brunocvcunha.instagram4j.requests.internal.InstagramExposeRequest)2 BufferedImage (java.awt.image.BufferedImage)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SneakyThrows (lombok.SneakyThrows)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1 InstagramConfigurePhotoRequest (org.brunocvcunha.instagram4j.requests.internal.InstagramConfigurePhotoRequest)1 InstagramUploadVideoJobRequest (org.brunocvcunha.instagram4j.requests.internal.InstagramUploadVideoJobRequest)1 InstagramConfigurePhotoResult (org.brunocvcunha.instagram4j.requests.payload.InstagramConfigurePhotoResult)1 InstagramUploadVideoResult (org.brunocvcunha.instagram4j.requests.payload.InstagramUploadVideoResult)1 FFmpegFrameGrabber (org.bytedeco.javacv.FFmpegFrameGrabber)1 Java2DFrameConverter (org.bytedeco.javacv.Java2DFrameConverter)1