Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/main/java/io/getstream/core/options/EnrichmentFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -91,6 +96,23 @@ public EnrichmentFlags withUserChildren(String userID) {
return this;
}

public EnrichmentFlags rankingVars(Map<String, Object> 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) {
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/io/getstream/client/AggregatedFeedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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<EnrichedActivity> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/getstream/client/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> mp=new LinkedHashMap();
Map<String, Object> mp = new LinkedHashMap();

mp.put("boolVal",true);
mp.put("music",1);
Expand Down