|
1 | 1 | package io.getstream.client; |
2 | 2 |
|
| 3 | +import static io.getstream.core.utils.Auth.*; |
| 4 | + |
3 | 5 | import com.google.common.collect.Iterables; |
| 6 | +import io.getstream.core.KeepHistory; |
4 | 7 | import io.getstream.core.StreamBatch; |
5 | 8 | import io.getstream.core.exceptions.StreamException; |
6 | 9 | import io.getstream.core.http.Token; |
7 | 10 | import io.getstream.core.models.*; |
8 | | -import io.getstream.core.KeepHistory; |
9 | 11 | import io.getstream.core.utils.DefaultOptions; |
| 12 | +import java.util.List; |
10 | 13 | import java8.util.J8Arrays; |
11 | 14 | import java8.util.concurrent.CompletableFuture; |
12 | 15 |
|
13 | | -import java.util.List; |
14 | | - |
15 | | -import static io.getstream.core.utils.Auth.*; |
16 | | - |
17 | 16 | public final class BatchClient { |
18 | | - private final String secret; |
19 | | - private final StreamBatch batch; |
20 | | - |
21 | | - BatchClient(String secret, StreamBatch batch) { |
22 | | - this.secret = secret; |
23 | | - this.batch = batch; |
24 | | - } |
25 | | - |
26 | | - public CompletableFuture<Void> addToMany(Activity activity, FeedID... feeds) throws StreamException { |
27 | | - final Token token = buildFeedToken(secret, TokenAction.WRITE); |
28 | | - return batch.addToMany(token, activity, feeds); |
29 | | - } |
30 | | - |
31 | | - public CompletableFuture<Void> followMany(int activityCopyLimit, FollowRelation... follows) throws StreamException { |
32 | | - final Token token = buildFollowToken(secret, TokenAction.WRITE); |
33 | | - return batch.followMany(token, activityCopyLimit, follows); |
34 | | - } |
35 | | - |
36 | | - public CompletableFuture<Void> followMany(int activityCopyLimit, Iterable<FollowRelation> follows) throws StreamException { |
37 | | - return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class)); |
38 | | - } |
39 | | - |
40 | | - public CompletableFuture<Void> followMany(FollowRelation... follows) throws StreamException { |
41 | | - return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows); |
42 | | - } |
43 | | - |
44 | | - public CompletableFuture<Void> followMany(Iterable<FollowRelation> follows) throws StreamException { |
45 | | - return followMany(Iterables.toArray(follows, FollowRelation.class)); |
46 | | - } |
47 | | - |
48 | | - public CompletableFuture<Void> unfollowMany(FollowRelation... follows) throws StreamException { |
49 | | - final Token token = buildFollowToken(secret, TokenAction.WRITE); |
50 | | - final UnfollowOperation[] ops = J8Arrays.stream(follows) |
51 | | - .map(follow -> new UnfollowOperation(follow, io.getstream.core.KeepHistory.YES)) |
52 | | - .toArray(UnfollowOperation[]::new); |
53 | | - return batch.unfollowMany(token, ops); |
54 | | - } |
55 | | - |
56 | | - public CompletableFuture<Void> unfollowMany(KeepHistory keepHistory, FollowRelation... follows) throws StreamException { |
57 | | - final Token token = buildFollowToken(secret, TokenAction.WRITE); |
58 | | - final UnfollowOperation[] ops = J8Arrays.stream(follows) |
59 | | - .map(follow -> new UnfollowOperation(follow, keepHistory)) |
60 | | - .toArray(UnfollowOperation[]::new); |
61 | | - return batch.unfollowMany(token, ops); |
62 | | - } |
63 | | - |
64 | | - public CompletableFuture<Void> unfollowMany(UnfollowOperation... unfollows) throws StreamException { |
65 | | - final Token token = buildFollowToken(secret, TokenAction.WRITE); |
66 | | - return batch.unfollowMany(token, unfollows); |
67 | | - } |
68 | | - |
69 | | - public CompletableFuture<List<Activity>> getActivitiesByID(Iterable<String> activityIDs) throws StreamException { |
70 | | - return getActivitiesByID(Iterables.toArray(activityIDs, String.class)); |
71 | | - } |
72 | | - |
73 | | - public CompletableFuture<List<Activity>> getActivitiesByID(String... activityIDs) throws StreamException { |
74 | | - final Token token = buildActivityToken(secret, TokenAction.READ); |
75 | | - return batch.getActivitiesByID(token, activityIDs); |
76 | | - } |
77 | | - |
78 | | - public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(Iterable<String> activityIDs) throws StreamException { |
79 | | - return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class)); |
80 | | - } |
81 | | - |
82 | | - public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(String... activityIDs) throws StreamException { |
83 | | - final Token token = buildActivityToken(secret, TokenAction.READ); |
84 | | - return batch.getEnrichedActivitiesByID(token, activityIDs); |
85 | | - } |
86 | | - |
87 | | - public CompletableFuture<List<Activity>> getActivitiesByForeignID(Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException { |
88 | | - return getActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); |
89 | | - } |
90 | | - |
91 | | - public CompletableFuture<List<Activity>> getActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException { |
92 | | - final Token token = buildActivityToken(secret, TokenAction.READ); |
93 | | - return batch.getActivitiesByForeignID(token, activityIDTimePairs); |
94 | | - } |
95 | | - |
96 | | - public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException { |
97 | | - return getEnrichedActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); |
98 | | - } |
99 | | - |
100 | | - public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException { |
101 | | - final Token token = buildActivityToken(secret, TokenAction.READ); |
102 | | - return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs); |
103 | | - } |
104 | | - |
105 | | - public CompletableFuture<Void> updateActivities(Iterable<Activity> activities) throws StreamException { |
106 | | - return updateActivities(Iterables.toArray(activities, Activity.class)); |
107 | | - } |
108 | | - |
109 | | - public CompletableFuture<Void> updateActivities(Activity... activities) throws StreamException { |
110 | | - final Token token = buildActivityToken(secret, TokenAction.WRITE); |
111 | | - return batch.updateActivities(token, activities); |
112 | | - } |
| 17 | + private final String secret; |
| 18 | + private final StreamBatch batch; |
| 19 | + |
| 20 | + BatchClient(String secret, StreamBatch batch) { |
| 21 | + this.secret = secret; |
| 22 | + this.batch = batch; |
| 23 | + } |
| 24 | + |
| 25 | + public CompletableFuture<Void> addToMany(Activity activity, FeedID... feeds) |
| 26 | + throws StreamException { |
| 27 | + final Token token = buildFeedToken(secret, TokenAction.WRITE); |
| 28 | + return batch.addToMany(token, activity, feeds); |
| 29 | + } |
| 30 | + |
| 31 | + public CompletableFuture<Void> followMany(int activityCopyLimit, FollowRelation... follows) |
| 32 | + throws StreamException { |
| 33 | + final Token token = buildFollowToken(secret, TokenAction.WRITE); |
| 34 | + return batch.followMany(token, activityCopyLimit, follows); |
| 35 | + } |
| 36 | + |
| 37 | + public CompletableFuture<Void> followMany(int activityCopyLimit, Iterable<FollowRelation> follows) |
| 38 | + throws StreamException { |
| 39 | + return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class)); |
| 40 | + } |
| 41 | + |
| 42 | + public CompletableFuture<Void> followMany(FollowRelation... follows) throws StreamException { |
| 43 | + return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows); |
| 44 | + } |
| 45 | + |
| 46 | + public CompletableFuture<Void> followMany(Iterable<FollowRelation> follows) |
| 47 | + throws StreamException { |
| 48 | + return followMany(Iterables.toArray(follows, FollowRelation.class)); |
| 49 | + } |
| 50 | + |
| 51 | + public CompletableFuture<Void> unfollowMany(FollowRelation... follows) throws StreamException { |
| 52 | + final Token token = buildFollowToken(secret, TokenAction.WRITE); |
| 53 | + final UnfollowOperation[] ops = |
| 54 | + J8Arrays.stream(follows) |
| 55 | + .map(follow -> new UnfollowOperation(follow, io.getstream.core.KeepHistory.YES)) |
| 56 | + .toArray(UnfollowOperation[]::new); |
| 57 | + return batch.unfollowMany(token, ops); |
| 58 | + } |
| 59 | + |
| 60 | + public CompletableFuture<Void> unfollowMany(KeepHistory keepHistory, FollowRelation... follows) |
| 61 | + throws StreamException { |
| 62 | + final Token token = buildFollowToken(secret, TokenAction.WRITE); |
| 63 | + final UnfollowOperation[] ops = |
| 64 | + J8Arrays.stream(follows) |
| 65 | + .map(follow -> new UnfollowOperation(follow, keepHistory)) |
| 66 | + .toArray(UnfollowOperation[]::new); |
| 67 | + return batch.unfollowMany(token, ops); |
| 68 | + } |
| 69 | + |
| 70 | + public CompletableFuture<Void> unfollowMany(UnfollowOperation... unfollows) |
| 71 | + throws StreamException { |
| 72 | + final Token token = buildFollowToken(secret, TokenAction.WRITE); |
| 73 | + return batch.unfollowMany(token, unfollows); |
| 74 | + } |
| 75 | + |
| 76 | + public CompletableFuture<List<Activity>> getActivitiesByID(Iterable<String> activityIDs) |
| 77 | + throws StreamException { |
| 78 | + return getActivitiesByID(Iterables.toArray(activityIDs, String.class)); |
| 79 | + } |
| 80 | + |
| 81 | + public CompletableFuture<List<Activity>> getActivitiesByID(String... activityIDs) |
| 82 | + throws StreamException { |
| 83 | + final Token token = buildActivityToken(secret, TokenAction.READ); |
| 84 | + return batch.getActivitiesByID(token, activityIDs); |
| 85 | + } |
| 86 | + |
| 87 | + public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID( |
| 88 | + Iterable<String> activityIDs) throws StreamException { |
| 89 | + return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class)); |
| 90 | + } |
| 91 | + |
| 92 | + public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(String... activityIDs) |
| 93 | + throws StreamException { |
| 94 | + final Token token = buildActivityToken(secret, TokenAction.READ); |
| 95 | + return batch.getEnrichedActivitiesByID(token, activityIDs); |
| 96 | + } |
| 97 | + |
| 98 | + public CompletableFuture<List<Activity>> getActivitiesByForeignID( |
| 99 | + Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException { |
| 100 | + return getActivitiesByForeignID( |
| 101 | + Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); |
| 102 | + } |
| 103 | + |
| 104 | + public CompletableFuture<List<Activity>> getActivitiesByForeignID( |
| 105 | + ForeignIDTimePair... activityIDTimePairs) throws StreamException { |
| 106 | + final Token token = buildActivityToken(secret, TokenAction.READ); |
| 107 | + return batch.getActivitiesByForeignID(token, activityIDTimePairs); |
| 108 | + } |
| 109 | + |
| 110 | + public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID( |
| 111 | + Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException { |
| 112 | + return getEnrichedActivitiesByForeignID( |
| 113 | + Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); |
| 114 | + } |
| 115 | + |
| 116 | + public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID( |
| 117 | + ForeignIDTimePair... activityIDTimePairs) throws StreamException { |
| 118 | + final Token token = buildActivityToken(secret, TokenAction.READ); |
| 119 | + return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs); |
| 120 | + } |
| 121 | + |
| 122 | + public CompletableFuture<Void> updateActivities(Iterable<Activity> activities) |
| 123 | + throws StreamException { |
| 124 | + return updateActivities(Iterables.toArray(activities, Activity.class)); |
| 125 | + } |
| 126 | + |
| 127 | + public CompletableFuture<Void> updateActivities(Activity... activities) throws StreamException { |
| 128 | + final Token token = buildActivityToken(secret, TokenAction.WRITE); |
| 129 | + return batch.updateActivities(token, activities); |
| 130 | + } |
113 | 131 | } |
0 commit comments