diff --git a/src/main/java/io/getstream/core/options/EnrichmentFlags.java b/src/main/java/io/getstream/core/options/EnrichmentFlags.java index 00b647ff..a65900d7 100644 --- a/src/main/java/io/getstream/core/options/EnrichmentFlags.java +++ b/src/main/java/io/getstream/core/options/EnrichmentFlags.java @@ -3,19 +3,24 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; import io.getstream.core.http.Request; +import java8.util.concurrent.CompletionException; + +import java.io.IOException; import java.util.List; +import java.util.Map; public final class EnrichmentFlags implements RequestOption { enum OpType { OWN_CHILDREN("with_own_children"), OWN_REACTIONS("with_own_reactions"), REACTION_COUNTS("with_reaction_counts"), - // XXX: move it to a separate option??? REACTION_KINDS("reaction_kinds_filter"), RECENT_REACTIONS("with_recent_reactions"), - RECENT_REACTIONS_LIMIT("recent_reactions_limit"); + RECENT_REACTIONS_LIMIT("recent_reactions_limit"), + RANKING_VARS("ranking_vars"); private String operator; @@ -91,6 +96,23 @@ public EnrichmentFlags withUserChildren(String userID) { return this; } + public EnrichmentFlags rankingVars(Map externalVars) { + checkNotNull(externalVars, "No external variables to filter by"); + checkArgument(externalVars.size() > 0, "No external variables to filter by"); + + String rankingVarsJSON; + try { + ObjectMapper objectMapper = new ObjectMapper(); + rankingVarsJSON = objectMapper.writeValueAsString(externalVars); + } + catch (IOException e){ + throw new CompletionException(e); + } + + ops.add(new OpEntry(OpType.RANKING_VARS, rankingVarsJSON)); + return this; + } + @Override public void apply(Request.Builder builder) { for (OpEntry op : ops) { diff --git a/src/test/java/io/getstream/client/AggregatedFeedTest.java b/src/test/java/io/getstream/client/AggregatedFeedTest.java index 2a31d3a8..15ba4cfe 100644 --- a/src/test/java/io/getstream/client/AggregatedFeedTest.java +++ b/src/test/java/io/getstream/client/AggregatedFeedTest.java @@ -8,7 +8,15 @@ import io.getstream.core.models.EnrichedActivity; import io.getstream.core.models.Group; import io.getstream.core.options.EnrichmentFlags; +import io.getstream.core.options.Limit; +import io.getstream.core.options.Offset; + +import static org.junit.Assert.assertNotNull; + +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; + import java8.util.concurrent.CompletionException; import okhttp3.OkHttpClient; import org.junit.Test; @@ -45,6 +53,33 @@ public void getEnrichedActivityGroups() throws Exception { .join(); } + /* + @Test + public void getEnrichedRankingVars() throws Exception { + MockHTTPClient httpClient = new MockHTTPClient(); + Client client = + Client.builder(apiKey, secret) + .httpClient(new OKHTTPClientAdapter(new OkHttpClient()))//.httpClient(httpClient) + .build(); + + Map mp = new LinkedHashMap(); + + mp.put("boolVal", true); + mp.put("music", 1); + mp.put("sports", 2.1); + mp.put("string", "str"); + + FlatFeed feed = client.flatFeed("flat", "123"); + + List result = feed.getEnrichedActivities( + new Limit(69), + new Offset(13), + new EnrichmentFlags().rankingVars(mp), "popularity").join(); + + assertNotNull(result); + } + */ + @Test public void getCustomActivityGroups() throws Exception { Client client = Client.builder(apiKey, secret).build(); diff --git a/src/test/java/io/getstream/client/ClientTest.java b/src/test/java/io/getstream/client/ClientTest.java index 242a2340..f0d6a5fb 100644 --- a/src/test/java/io/getstream/client/ClientTest.java +++ b/src/test/java/io/getstream/client/ClientTest.java @@ -163,7 +163,7 @@ public void feedURLExternalRanking() throws Exception { Client client = Client.builder(apiKey, secret).httpClient(httpClient).build(); FlatFeed feed = client.flatFeed("flat", "1"); - Map mp=new LinkedHashMap(); + Map mp = new LinkedHashMap(); mp.put("boolVal",true); mp.put("music",1);