Skip to content

Commit 4f21719

Browse files
authored
Merge pull request #146 from GetStream/PBE-1366
[PBE-1366] Ranking Variables in the Enriched Activities Endpoint
2 parents 8e921a9 + 2cb2d46 commit 4f21719

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/main/java/io/getstream/core/options/EnrichmentFlags.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
import static com.google.common.base.Preconditions.checkArgument;
44
import static com.google.common.base.Preconditions.checkNotNull;
55

6+
import com.fasterxml.jackson.databind.ObjectMapper;
67
import com.google.common.collect.Lists;
78
import io.getstream.core.http.Request;
9+
import java8.util.concurrent.CompletionException;
10+
11+
import java.io.IOException;
812
import java.util.List;
13+
import java.util.Map;
914

1015
public final class EnrichmentFlags implements RequestOption {
1116
enum OpType {
1217
OWN_CHILDREN("with_own_children"),
1318
OWN_REACTIONS("with_own_reactions"),
1419
REACTION_COUNTS("with_reaction_counts"),
15-
// XXX: move it to a separate option???
1620
REACTION_KINDS("reaction_kinds_filter"),
1721
RECENT_REACTIONS("with_recent_reactions"),
18-
RECENT_REACTIONS_LIMIT("recent_reactions_limit");
22+
RECENT_REACTIONS_LIMIT("recent_reactions_limit"),
23+
RANKING_VARS("ranking_vars");
1924

2025
private String operator;
2126

@@ -91,6 +96,23 @@ public EnrichmentFlags withUserChildren(String userID) {
9196
return this;
9297
}
9398

99+
public EnrichmentFlags rankingVars(Map<String, Object> externalVars) {
100+
checkNotNull(externalVars, "No external variables to filter by");
101+
checkArgument(externalVars.size() > 0, "No external variables to filter by");
102+
103+
String rankingVarsJSON;
104+
try {
105+
ObjectMapper objectMapper = new ObjectMapper();
106+
rankingVarsJSON = objectMapper.writeValueAsString(externalVars);
107+
}
108+
catch (IOException e){
109+
throw new CompletionException(e);
110+
}
111+
112+
ops.add(new OpEntry(OpType.RANKING_VARS, rankingVarsJSON));
113+
return this;
114+
}
115+
94116
@Override
95117
public void apply(Request.Builder builder) {
96118
for (OpEntry op : ops) {

src/test/java/io/getstream/client/AggregatedFeedTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
import io.getstream.core.models.EnrichedActivity;
99
import io.getstream.core.models.Group;
1010
import io.getstream.core.options.EnrichmentFlags;
11+
import io.getstream.core.options.Limit;
12+
import io.getstream.core.options.Offset;
13+
14+
import static org.junit.Assert.assertNotNull;
15+
16+
import java.util.LinkedHashMap;
1117
import java.util.List;
18+
import java.util.Map;
19+
1220
import java8.util.concurrent.CompletionException;
1321
import okhttp3.OkHttpClient;
1422
import org.junit.Test;
@@ -45,6 +53,33 @@ public void getEnrichedActivityGroups() throws Exception {
4553
.join();
4654
}
4755

56+
/*
57+
@Test
58+
public void getEnrichedRankingVars() throws Exception {
59+
MockHTTPClient httpClient = new MockHTTPClient();
60+
Client client =
61+
Client.builder(apiKey, secret)
62+
.httpClient(new OKHTTPClientAdapter(new OkHttpClient()))//.httpClient(httpClient)
63+
.build();
64+
65+
Map<String, Object> mp = new LinkedHashMap();
66+
67+
mp.put("boolVal", true);
68+
mp.put("music", 1);
69+
mp.put("sports", 2.1);
70+
mp.put("string", "str");
71+
72+
FlatFeed feed = client.flatFeed("flat", "123");
73+
74+
List<EnrichedActivity> result = feed.getEnrichedActivities(
75+
new Limit(69),
76+
new Offset(13),
77+
new EnrichmentFlags().rankingVars(mp), "popularity").join();
78+
79+
assertNotNull(result);
80+
}
81+
*/
82+
4883
@Test
4984
public void getCustomActivityGroups() throws Exception {
5085
Client client = Client.builder(apiKey, secret).build();

src/test/java/io/getstream/client/ClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void feedURLExternalRanking() throws Exception {
163163
Client client = Client.builder(apiKey, secret).httpClient(httpClient).build();
164164
FlatFeed feed = client.flatFeed("flat", "1");
165165

166-
Map<String, Object> mp=new LinkedHashMap();
166+
Map<String, Object> mp = new LinkedHashMap();
167167

168168
mp.put("boolVal",true);
169169
mp.put("music",1);

0 commit comments

Comments
 (0)