com.cloudinary.http43.ApiUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudinary-http43 Show documentation
Show all versions of cloudinary-http43 Show documentation
Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. Upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your websiteâs graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more. This Java library allows to easily integrate with Cloudinary in Java applications.
package com.cloudinary.http43;
import com.cloudinary.utils.ObjectUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.message.BasicNameValuePair;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ApiUtils {
public static void setTimeouts(HttpRequestBase request, Map options) {
RequestConfig config= request.getConfig();
final RequestConfig.Builder builder;
if (config != null) {
builder = RequestConfig.copy(config);
} else {
builder = RequestConfig.custom();
}
Integer timeout = (Integer) options.get("timeout");
if(timeout != null) {
builder.setSocketTimeout(timeout);
}
Integer connectionRequestTimeout = (Integer) options.get("connection_request_timeout");
if(connectionRequestTimeout != null) {
builder.setConnectionRequestTimeout(connectionRequestTimeout);
}
Integer connectTimeout = (Integer) options.get("connect_timeout");
if(connectTimeout != null) {
builder.setConnectTimeout(connectTimeout);
}
request.setConfig(builder.build());
}
static List prepareParams(Map params) {
List requestParams = new ArrayList(params.size());
for (Map.Entry param : params.entrySet()) {
if (param.getValue() instanceof Iterable) {
for (Object single : (Iterable>) param.getValue()) {
requestParams.add(new BasicNameValuePair(param.getKey() + "[]", ObjectUtils.asString(single)));
}
} else {
requestParams.add(new BasicNameValuePair(param.getKey(), ObjectUtils.asString(param.getValue())));
}
}
return requestParams;
}
}