All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.transloadit.sdk.response.Response Maven / Gradle / Ivy

Go to download

A Java Integration of the Transloadit's(https://transloadit.com) file uploading and encoding service.

There is a newer version: 1.0.0
Show newest version
package com.transloadit.sdk.response;

import com.transloadit.sdk.exceptions.LocalOperationException;
import org.json.JSONObject;

import java.io.IOException;

/**
 * Transloadit Api Response class.
 */
public class Response {
    private okhttp3.Response httpResponse;
    private String stringBody;

    /**
     * Initializes a new Response object for a Http Response from the Transloadit Api.
     * @param response {@link okhttp3.Response} - response from interaction with Web API
     * @throws LocalOperationException if something goes wrong while running non-http operations.
     */
    public Response(okhttp3.Response response) throws LocalOperationException {
        httpResponse = response;
        try {
            stringBody = response.body().string();
        } catch (IOException e) {
            throw new LocalOperationException(e);
        }
    }

    /**
     *
     * @return the json content of the response as an instance of ({@link JSONObject})
     */
    public JSONObject json() {
        return new JSONObject(stringBody);
    }

    /**
     *
     * @return http status code.
     */
    public int status() {
        return httpResponse.code();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy