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

com.cloudinary.Search Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.0.1-dummy
Show newest version
package com.cloudinary;

import com.cloudinary.api.ApiResponse;
import com.cloudinary.utils.ObjectUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Search {

    private final Api api;
    private ArrayList> sortByParam;
    private ArrayList aggregateParam;
    private ArrayList withFieldParam;
    private HashMap params;

    Search(Cloudinary cloudinary) {
        this.api = cloudinary.api();
        this.params = new HashMap();
        this.sortByParam = new ArrayList>();
        this.aggregateParam = new ArrayList();
        this.withFieldParam = new ArrayList();
    }

    public Search expression(String value) {
        this.params.put("expression", value);
        return this;
    }

    public Search maxResults(Integer value) {
        this.params.put("max_results", value);
        return this;
    }

    public Search nextCursor(String value) {
        this.params.put("next_cursor", value);
        return this;
    }

    public Search aggregate(String field) {
        if (!aggregateParam.contains(field)) {
            aggregateParam.add(field);
        }
        return this;
    }

    public Search withField(String field) {
        if (!withFieldParam.contains(field)) {
            withFieldParam.add(field);
        }
        return this;
    }

    public Search sortBy(String field, String dir) {
        HashMap sortBucket = new HashMap();
        sortBucket.put(field, dir);
        for (int i = 0; i < sortByParam.size(); i++) {
            if (sortByParam.get(i).containsKey(field)){
                sortByParam.add(i, sortBucket);
                return this;
            }
        }
        sortByParam.add(sortBucket);
        return this;
    }

    public HashMap toQuery() {
        HashMap queryParams = new HashMap(this.params);
        queryParams.put("with_field", withFieldParam);
        queryParams.put("sort_by", sortByParam);
        queryParams.put("aggregate", aggregateParam);
        return queryParams;
    }

    public ApiResponse execute() throws Exception {
        Map options = ObjectUtils.asMap("content_type", "json");
        return this.api.callApi(Api.HttpMethod.POST, Arrays.asList("resources", "search"), this.toQuery(), options);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy