Skip to content

Commit

Permalink
Merge branch 'feature/search-by-context'
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Tocker committed Jan 8, 2017
2 parents cca7bc9 + 090dc23 commit 3e33935
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cloudinary-core/src/main/java/com/cloudinary/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cloudinary.strategies.AbstractApiStrategy;
import com.cloudinary.utils.ObjectUtils;
import org.cloudinary.json.JSONArray;
import com.cloudinary.utils.StringUtils;

@SuppressWarnings({"rawtypes", "unchecked"})
public class Api {
Expand Down Expand Up @@ -78,6 +79,21 @@ public ApiResponse resourcesByTag(String tag, Map options) throws Exception {
return callApi(HttpMethod.GET, Arrays.asList("resources", resourceType, "tags", tag), ObjectUtils.only(options, "next_cursor", "direction", "max_results", "tags", "context", "moderations"), options);
}

public ApiResponse resourcesByContext(String key, Map options) throws Exception {
return resourcesByContext(key,null,options);
}

public ApiResponse resourcesByContext(String key,String value, Map options) throws Exception {
if (options == null) options = ObjectUtils.emptyMap();
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
Map params = ObjectUtils.only(options, "next_cursor", "direction", "max_results", "tags", "context", "moderations");
params.put("key",key);
if (StringUtils.isNotBlank(value)) {
params.put("value",value);
}
return callApi(HttpMethod.GET, Arrays.asList("resources", resourceType,"context"), params , options);
}

public ApiResponse resourcesByIds(Iterable<String> publicIds, Map options) throws Exception {
if (options == null) options = ObjectUtils.emptyMap();
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public static void setUpClass() throws IOException {
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
options.put("public_id", API_TEST_1);
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);

options = ObjectUtils.asMap("public_id", "context_1", "tags", new String[]{SDK_TEST_TAG, uniqueTag}, "context", "test-key=alt");
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
options = ObjectUtils.asMap("public_id", "context_2", "tags", new String[]{SDK_TEST_TAG, uniqueTag}, "context", "test-key=alternate");
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
}

@AfterClass
Expand Down Expand Up @@ -387,6 +392,18 @@ public void test17aTransformationDeleteImplicit() throws Exception {
api.deleteTransformation("c_scale,w_100", ObjectUtils.emptyMap());
}

@Test
public void test20ResourcesContext() throws Exception {
Map result = api.resourcesByContext("test-key", ObjectUtils.emptyMap());

List<Map> resources = (List<Map>) result.get("resources");
assertEquals(2,resources.size());
result = api.resourcesByContext("test-key","alt", ObjectUtils.emptyMap());

resources = (List<Map>) result.get("resources");
assertEquals(1,resources.size());
}

/**
* @throws Exception
* @expectedException \Cloudinary\Api\NotFound
Expand Down

0 comments on commit 3e33935

Please sign in to comment.