|
7 | 7 | import io.getstream.core.http.HTTPClient; |
8 | 8 | import io.getstream.core.http.Response; |
9 | 9 | import io.getstream.core.http.Token; |
10 | | -import io.getstream.core.models.Activity; |
11 | | -import io.getstream.core.models.Data; |
12 | | -import io.getstream.core.models.FeedID; |
13 | | -import io.getstream.core.models.OGData; |
| 10 | +import io.getstream.core.models.*; |
14 | 11 | import io.getstream.core.options.CustomQueryParameter; |
15 | 12 | import io.getstream.core.options.RequestOption; |
16 | 13 |
|
|
20 | 17 | import java.net.URL; |
21 | 18 | import java.util.Arrays; |
22 | 19 | import java.util.Date; |
| 20 | +import java.util.List; |
23 | 21 | import java.util.Map; |
24 | 22 | import java.util.concurrent.CompletableFuture; |
25 | 23 | import java.util.concurrent.CompletionException; |
|
28 | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
29 | 27 | import static io.getstream.core.utils.Request.*; |
30 | 28 | import static io.getstream.core.utils.Routes.*; |
31 | | -import static io.getstream.core.utils.Serialization.deserialize; |
32 | | -import static io.getstream.core.utils.Serialization.toJSON; |
| 29 | +import static io.getstream.core.utils.Serialization.*; |
33 | 30 |
|
34 | 31 | public final class Stream { |
35 | 32 | private final String key; |
@@ -70,6 +67,33 @@ public StreamImages images() { |
70 | 67 | return new StreamImages(key, baseURL, httpClient); |
71 | 68 | } |
72 | 69 |
|
| 70 | + public CompletableFuture<List<Activity>> updateActivitiesByID(Token token, ActivityUpdate[] updates) throws StreamException { |
| 71 | + checkNotNull(updates, "No updates"); |
| 72 | + checkArgument(updates.length > 0, "No updates"); |
| 73 | + for (ActivityUpdate update : updates) { |
| 74 | + checkNotNull(update.getID(), "No activity to update"); |
| 75 | + checkNotNull(update.getSet(), "No activity properties to set"); |
| 76 | + checkNotNull(update.getUnset(), "No activity properties to unset"); |
| 77 | + } |
| 78 | + |
| 79 | + try { |
| 80 | + final byte[] payload = toJSON(new Object() { |
| 81 | + public final ActivityUpdate[] changes = updates; |
| 82 | + }); |
| 83 | + final URL url = buildActivityUpdateURL(baseURL); |
| 84 | + return httpClient.execute(buildPost(url, key, token, payload)) |
| 85 | + .thenApply(response -> { |
| 86 | + try { |
| 87 | + return deserializeContainer(response, "activities", Activity.class); |
| 88 | + } catch (StreamException | IOException e) { |
| 89 | + throw new CompletionException(e); |
| 90 | + } |
| 91 | + }); |
| 92 | + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { |
| 93 | + throw new StreamException(e); |
| 94 | + } |
| 95 | + } |
| 96 | + |
73 | 97 | public CompletableFuture<Activity> updateActivityByID(Token token, String id, Map<String, Object> set, String[] unset) throws StreamException { |
74 | 98 | checkNotNull(id, "No activity to update"); |
75 | 99 | checkNotNull(set, "No activity properties to set"); |
@@ -99,6 +123,34 @@ public CompletableFuture<Activity> updateActivityByID(Token token, String id, Ma |
99 | 123 | } |
100 | 124 | } |
101 | 125 |
|
| 126 | + public CompletableFuture<List<Activity>> updateActivitiesByForeignID(Token token, ActivityUpdate[] updates) throws StreamException { |
| 127 | + checkNotNull(updates, "No updates"); |
| 128 | + checkArgument(updates.length > 0, "No updates"); |
| 129 | + for (ActivityUpdate update : updates) { |
| 130 | + checkNotNull(update.getForeignID(), "No activity to update"); |
| 131 | + checkNotNull(update.getTime(), "Missing timestamp"); |
| 132 | + checkNotNull(update.getSet(), "No activity properties to set"); |
| 133 | + checkNotNull(update.getUnset(), "No activity properties to unset"); |
| 134 | + } |
| 135 | + |
| 136 | + try { |
| 137 | + final byte[] payload = toJSON(new Object() { |
| 138 | + public final ActivityUpdate[] changes = updates; |
| 139 | + }); |
| 140 | + final URL url = buildActivityUpdateURL(baseURL); |
| 141 | + return httpClient.execute(buildPost(url, key, token, payload)) |
| 142 | + .thenApply(response -> { |
| 143 | + try { |
| 144 | + return deserializeContainer(response, "activities", Activity.class); |
| 145 | + } catch (StreamException | IOException e) { |
| 146 | + throw new CompletionException(e); |
| 147 | + } |
| 148 | + }); |
| 149 | + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { |
| 150 | + throw new StreamException(e); |
| 151 | + } |
| 152 | + } |
| 153 | + |
102 | 154 | public CompletableFuture<Activity> updateActivityByForeignID(Token token, String foreignID, Date timestamp, Map<String, Object> set, String[] unset) throws StreamException { |
103 | 155 | checkNotNull(foreignID, "No activity to update"); |
104 | 156 | checkNotNull(timestamp, "Missing timestamp"); |
|
0 commit comments