com.dynamicpdf.api.ImageInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamicpdf-api Show documentation
Show all versions of dynamicpdf-api Show documentation
A Java Client API that uses the DynamicPDF API to create, merge, split, form fill, stamp, secure/encrypt PDF documents.
package com.dynamicpdf.api;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
/**
* Represents an image information endpoint.
*/
public class ImageInfo extends Endpoint
{
private ImageResource resource;
/**
* Initializes a new instance of the ImageInfo
class.
* @param resource The image resource of type ImageResource
.
*/
public ImageInfo(ImageResource resource)
{
this.resource = resource;
}
String getEndpointName() { return "image-info";}
/**
* Process the image resource to get image's information.
* @return The image resource to get image's information.
*/
public ImageResponse process()
{
CompletableFuture cf = processAsync();
try {
return cf.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return null;
}
/**
* Process the pdf resource to get image's information.
*
* @return collection of ImageResponse
as multithreading tasks CompletableFuture
.
*/
public CompletableFuture processAsync()
{
return CompletableFuture.supplyAsync(() -> {
ImageResponse imageResponse = null;
RequestSpecification requestSpec = super.createRequestSpecification();
Response response = RestAssured
.given()
.header("Accept", "*/*")
.header("content-type", resource.mimeType)
.spec(requestSpec)
.body(resource.getData())
.post(getDefaultBaseUrl() + "/"+ getEndpointVersion() + "/" + getEndpointName());
if (response.getStatusCode() == 200)
{
imageResponse = new ImageResponse(response.asString());
imageResponse.setIsSuccessful(true);
imageResponse.setStatusCode(response.getStatusCode());
}
else
{
imageResponse = new ImageResponse();
imageResponse.setErrorJson(response.asString());
imageResponse.setIsSuccessful(false);
imageResponse.setStatusCode(response.getStatusCode());
}
return imageResponse;
});
}
}