From 5098fd09a4be414644c7aecb94fb52b2284f3b9c Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Mon, 2 Mar 2020 15:57:00 +0100 Subject: [PATCH 1/3] Ensure formatting with google style guide --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1c71250c..d4ec5a9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,9 @@ env: - secure: TmI+K6gSOfDy5oa5EgLCGijimKdR5cHAwM6RASDegTjlRQ/sWVf8BNF4IPJHnAYFWNCgyX6vLdfPS3IJNrYS9iI1Er2a1Ctcq1TbCZfZpn4eIj8mcUXxr2Fo6hLJh2KeuXj3OQwfUy/Jul1Own/9R5YoVDJYD0ntnt1HJgFqq+0= - secure: DethMgIykOufLLQn9Jykmg7rdvZp4ONXD4A1XVQNaEVQytv20Fb2QidEPmVEocuDmpmU6SjWNMhAeBdlWnyGB4lECMG9594HJpSnNkyFQzzsfSWdOwHixiUCuD+rMJlEPRJDM4ayxhilPnK1gkycKBAZ1gtutriC4O/BdEOCN6A= - secure: F6jGxeoyhD1tmC0ovRW2RqeEQDN5t5Kfqktmtcj0Lz3S4ddgzMwC6RYKyYiiu9T3FSfh/hEMrx2SrMK+Neu2ctfYflNibUjgZJVPZHR7DA3S+g30teyj10XWspb6+OLC7U0DnGbdLee/w0KkuugQHYNv1aM9oEPtLWi+3VpvIIU= +before_script: + - wget -O google-java-format https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar + - find . -name "*.java" | xargs java -jar google-java-format -set-exit-if-changed -replace script: - gradle test #after_success: From d115f91db58c7312a6b4e9e2f0902b2f731b2ada Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Mon, 2 Mar 2020 15:57:32 +0100 Subject: [PATCH 2/3] Format all files --- example/Example.java | 1107 ++++++++------- .../io/getstream/client/AggregatedFeed.java | 1036 +++++++++----- .../io/getstream/client/AnalyticsClient.java | 92 +- .../java/io/getstream/client/BatchClient.java | 218 +-- src/main/java/io/getstream/client/Client.java | 603 +++++---- .../getstream/client/CollectionsClient.java | 249 ++-- src/main/java/io/getstream/client/Feed.java | 644 +++++---- .../getstream/client/FileStorageClient.java | 51 +- .../java/io/getstream/client/FlatFeed.java | 1003 +++++++++----- .../getstream/client/ImageStorageClient.java | 71 +- .../io/getstream/client/NotificationFeed.java | 1189 +++++++++++------ .../client/PersonalizationClient.java | 134 +- .../io/getstream/client/ReactionsClient.java | 329 +++-- src/main/java/io/getstream/client/User.java | 181 +-- .../getstream/cloud/CloudAggregatedFeed.java | 1036 +++++++++----- .../getstream/cloud/CloudAnalyticsClient.java | 31 +- .../java/io/getstream/cloud/CloudClient.java | 442 +++--- .../cloud/CloudCollectionsClient.java | 98 +- .../java/io/getstream/cloud/CloudFeed.java | 573 ++++---- .../cloud/CloudFileStorageClient.java | 33 +- .../io/getstream/cloud/CloudFlatFeed.java | 1003 +++++++++----- .../cloud/CloudImageStorageClient.java | 45 +- .../cloud/CloudNotificationFeed.java | 1189 +++++++++++------ .../getstream/cloud/CloudReactionsClient.java | 278 ++-- .../java/io/getstream/cloud/CloudUser.java | 181 +-- .../java/io/getstream/core/KeepHistory.java | 18 +- .../java/io/getstream/core/LookupKind.java | 22 +- src/main/java/io/getstream/core/Region.java | 26 +- src/main/java/io/getstream/core/Stream.java | 755 ++++++----- .../io/getstream/core/StreamAnalytics.java | 142 +- .../java/io/getstream/core/StreamBatch.java | 428 +++--- .../io/getstream/core/StreamCollections.java | 392 +++--- .../java/io/getstream/core/StreamFiles.java | 140 +- .../java/io/getstream/core/StreamImages.java | 177 +-- .../getstream/core/StreamPersonalization.java | 182 +-- .../io/getstream/core/StreamReactions.java | 420 +++--- .../core/exceptions/StreamAPIException.java | 95 +- .../core/exceptions/StreamException.java | 31 +- .../io/getstream/core/http/HTTPClient.java | 10 +- .../core/http/OKHTTPClientAdapter.java | 195 +-- .../java/io/getstream/core/http/Request.java | 253 ++-- .../io/getstream/core/http/RequestBody.java | 151 +-- .../java/io/getstream/core/http/Response.java | 80 +- .../java/io/getstream/core/http/Token.java | 56 +- .../io/getstream/core/models/Activity.java | 431 +++--- .../getstream/core/models/ActivityUpdate.java | 171 +-- .../getstream/core/models/CollectionData.java | 176 ++- .../io/getstream/core/models/Content.java | 139 +- .../java/io/getstream/core/models/Data.java | 123 +- .../io/getstream/core/models/Engagement.java | 332 ++--- .../core/models/EnrichedActivity.java | 567 ++++---- .../io/getstream/core/models/Feature.java | 76 +- .../java/io/getstream/core/models/FeedID.java | 104 +- .../getstream/core/models/FollowRelation.java | 87 +- .../core/models/ForeignIDTimePair.java | 74 +- .../java/io/getstream/core/models/Group.java | 177 ++- .../io/getstream/core/models/Impression.java | 299 +++-- .../core/models/NotificationGroup.java | 102 +- .../java/io/getstream/core/models/OGData.java | 420 +++--- .../io/getstream/core/models/Paginated.java | 15 +- .../io/getstream/core/models/ProfileData.java | 134 +- .../io/getstream/core/models/Reaction.java | 439 +++--- .../core/models/UnfollowOperation.java | 106 +- .../io/getstream/core/models/UserData.java | 71 +- .../serialization/DataDeserializer.java | 46 +- .../serialization/DateDeserializer.java | 45 +- .../core/options/ActivityMarker.java | 97 +- .../java/io/getstream/core/options/Crop.java | 101 +- .../core/options/CustomQueryParameter.java | 52 +- .../core/options/EnrichmentFlags.java | 176 ++- .../io/getstream/core/options/Filter.java | 85 +- .../getstream/core/options/KeepHistory.java | 22 +- .../java/io/getstream/core/options/Limit.java | 22 +- .../io/getstream/core/options/Offset.java | 24 +- .../io/getstream/core/options/Ranking.java | 30 +- .../getstream/core/options/RequestOption.java | 2 +- .../io/getstream/core/options/Resize.java | 99 +- .../java/io/getstream/core/utils/Auth.java | 264 ++-- .../getstream/core/utils/DefaultOptions.java | 18 +- .../io/getstream/core/utils/Enrichment.java | 22 +- .../java/io/getstream/core/utils/Info.java | 26 +- .../java/io/getstream/core/utils/Request.java | 77 +- .../java/io/getstream/core/utils/Routes.java | 282 ++-- .../getstream/core/utils/Serialization.java | 184 +-- .../java/io/getstream/core/utils/Streams.java | 13 +- .../getstream/client/AggregatedFeedTest.java | 96 +- .../getstream/client/AnalyticsClientTest.java | 120 +- .../io/getstream/client/BatchClientTest.java | 319 ++--- .../java/io/getstream/client/ClientTest.java | 306 +++-- .../client/CollectionsClientTest.java | 368 +++-- .../java/io/getstream/client/FeedTest.java | 327 ++--- .../client/FileStorageClientTest.java | 63 +- .../io/getstream/client/FlatFeedTest.java | 164 +-- .../client/ImageStorageClientTest.java | 113 +- .../client/NotificationFeedTest.java | 42 +- src/test/java/io/getstream/client/OGTest.java | 24 +- .../client/PersonalizationClientTest.java | 92 +- .../getstream/client/ReactionsClientTest.java | 198 +-- .../java/io/getstream/client/UserTest.java | 125 +- .../client/entities/FootballMatch.java | 66 +- .../io/getstream/client/entities/Match.java | 37 +- .../client/entities/VolleyballMatch.java | 66 +- .../getstream/cloud/AnalyticsClientTest.java | 120 +- src/test/java/io/getstream/cloud/Cloud.java | 24 +- .../cloud/CloudAggregatedFeedTest.java | 211 +-- .../io/getstream/cloud/CloudFeedTest.java | 272 ++-- .../cloud/CloudFileStorageClientTest.java | 63 +- .../io/getstream/cloud/CloudFlatFeedTest.java | 185 +-- .../cloud/CloudImageStorageClientTest.java | 113 +- .../cloud/CloudNotificationFeedTest.java | 101 +- .../cloud/CloudPersonalizationClientTest.java | 92 +- .../cloud/CloudReactionsClientTest.java | 159 ++- .../io/getstream/cloud/CloudUserTest.java | 144 +- .../core/http/OKHTTPClientAdapterTest.java | 87 +- .../core/utils/ActivityGenerator.java | 141 +- .../io/getstream/core/utils/InfoTest.java | 14 +- .../utils/SerializationPropertiesTest.java | 31 +- .../core/utils/SerializationTest.java | 361 ++--- 118 files changed, 14205 insertions(+), 11558 deletions(-) diff --git a/example/Example.java b/example/Example.java index c5795aca..9c34fd99 100644 --- a/example/Example.java +++ b/example/Example.java @@ -1,5 +1,8 @@ package example; +import static io.getstream.core.utils.Enrichment.createCollectionReference; +import static io.getstream.core.utils.Enrichment.createUserReference; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import io.getstream.client.Client; @@ -10,7 +13,6 @@ import io.getstream.core.Region; import io.getstream.core.models.*; import io.getstream.core.options.*; - import java.io.File; import java.net.URL; import java.time.LocalDateTime; @@ -18,539 +20,626 @@ import java.util.List; import java.util.Map; -import static io.getstream.core.utils.Enrichment.createCollectionReference; -import static io.getstream.core.utils.Enrichment.createUserReference; - class Example { - private static final String apiKey = "gp6e8sxxzud6"; - private static final String secret = "7j7exnksc4nxy399fdxvjqyqsqdahax3nfgtp27pumpc7sfm9um688pzpxjpjbf2"; - - public static void main(String[] args) throws Exception { - Client client = Client.builder(apiKey, secret) - .build(); - - FlatFeed chris = client.flatFeed("user", "chris"); - // Add an Activity; message is a custom field - tip: you can add unlimited custom fields! - chris.addActivity(Activity.builder() - .actor("chris") - .verb("add") - .object("picture:10") - .foreignID("picture:10") - .extraField("message", "Beautiful bird!") - .build()); + private static final String apiKey = "gp6e8sxxzud6"; + private static final String secret = + "7j7exnksc4nxy399fdxvjqyqsqdahax3nfgtp27pumpc7sfm9um688pzpxjpjbf2"; + + public static void main(String[] args) throws Exception { + Client client = Client.builder(apiKey, secret).build(); + + FlatFeed chris = client.flatFeed("user", "chris"); + // Add an Activity; message is a custom field - tip: you can add unlimited custom fields! + chris.addActivity( + Activity.builder() + .actor("chris") + .verb("add") + .object("picture:10") + .foreignID("picture:10") + .extraField("message", "Beautiful bird!") + .build()); + + // Create a following relationship between Jack's "timeline" feed and Chris' "user" feed: + FlatFeed jack = client.flatFeed("timeline", "jack"); + jack.follow(chris); + + // Read Jack's timeline and Chris' post appears in the feed: + List response = jack.getActivities(new Pagination().limit(10)).join(); + for (Activity activity : response) { + // ... + } - // Create a following relationship between Jack's "timeline" feed and Chris' "user" feed: - FlatFeed jack = client.flatFeed("timeline", "jack"); - jack.follow(chris); - - // Read Jack's timeline and Chris' post appears in the feed: - List response = jack.getActivities(new Pagination().limit(10)).join(); - for (Activity activity : response) { - // ... - } - - // Remove an Activity by referencing it's foreign_id - chris.removeActivityByForeignID("picture:10"); - - /* -------------------------------------------------------- */ - - // Instantiate a feed object - FlatFeed userFeed = client.flatFeed("user", "1"); - - // Add an activity to the feed, where actor, object and target are references to objects (`Eric`, `Hawaii`, `Places to Visit`) - Activity activity = Activity.builder() - .actor("User:1") - .verb("pin") - .object("Place:42") - .target("Board:1") - .build(); - userFeed.addActivity(activity); - - // Create a bit more complex activity - activity = Activity.builder() - .actor("User:1") - .verb("run") - .object("Exercise:42") - .foreignID("run:1") - .extra(new ImmutableMap.Builder() - .put("course", new ImmutableMap.Builder() - .put("name", "Golden Gate park") - .put("distance", 10) - .build()) - .put("participants", new String[]{ - "Thierry", - "Tommaso", + // Remove an Activity by referencing it's foreign_id + chris.removeActivityByForeignID("picture:10"); + + /* -------------------------------------------------------- */ + + // Instantiate a feed object + FlatFeed userFeed = client.flatFeed("user", "1"); + + // Add an activity to the feed, where actor, object and target are references to objects + // (`Eric`, `Hawaii`, `Places to Visit`) + Activity activity = + Activity.builder().actor("User:1").verb("pin").object("Place:42").target("Board:1").build(); + userFeed.addActivity(activity); + + // Create a bit more complex activity + activity = + Activity.builder() + .actor("User:1") + .verb("run") + .object("Exercise:42") + .foreignID("run:1") + .extra( + new ImmutableMap.Builder() + .put( + "course", + new ImmutableMap.Builder() + .put("name", "Golden Gate park") + .put("distance", 10) + .build()) + .put( + "participants", + new String[] { + "Thierry", "Tommaso", }) - .put("started_at", LocalDateTime.now()) - .put("location", new ImmutableMap.Builder() - .put("type", "point") - .put("coordinates", new double[]{37.769722, -122.476944}) - .build()) - .build()) - .build(); - userFeed.addActivity(activity); - - // Remove an activity by its id - userFeed.removeActivityByID("e561de8f-00f1-11e4-b400-0cc47a024be0"); - - // Remove activities with foreign_id 'run:1' - userFeed.removeActivityByForeignID("run:1"); - - activity = Activity.builder() - .actor("1") - .verb("like") - .object("3") - .time(new Date()) - .foreignID("like:3") - .extraField("popularity", 100) - .build(); - - // first time the activity is added - userFeed.addActivity(activity); - - // update the popularity value for the activity - activity = Activity.builder() - .fromActivity(activity) - .extraField("popularity", 10) - .build(); - - client.batch().updateActivities(activity); - - /* -------------------------------------------------------- */ - - // partial update by activity ID - - // prepare the set operations - Map set = new ImmutableMap.Builder() - .put("product.price", 19.99) - .put("shares", new ImmutableMap.Builder() - .put("facebook", "...") - .put("twitter", "...") - .build()) - .build(); - // prepare the unset operations - String[] unset = new String[] { "daily_likes", "popularity" }; - - String id = "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4"; - client.updateActivityByID(id, set, unset); - - String foreignID = "product:123"; - Date timestamp = new Date(); - client.updateActivityByForeignID(foreignID, timestamp, set, unset); - - FeedID[] add = new FeedID[0]; - FeedID[] remove = new FeedID[0]; - userFeed.updateActivityToTargets(activity, add, remove); - - FeedID[] newTargets = new FeedID[0]; - userFeed.replaceActivityToTargets(activity, newTargets); - - /* -------------------------------------------------------- */ - - Date now = new Date(); - Activity firstActivity = userFeed.addActivity(Activity.builder() - .actor("1") - .verb("like") - .object("3") - .time(now) - .foreignID("like:3") - .build()).join(); - Activity secondActivity = userFeed.addActivity(Activity.builder() - .actor("1") - .verb("like") - .object("3") - .time(now) - .extraField("extra", "extra_value") - .foreignID("like:3") - .build()).join(); - // foreign ID and time are the same for both activities - // hence only one activity is created and first and second IDs are equal - // firstActivity.ID == secondActivity.ID - - /* -------------------------------------------------------- */ - - // Get 5 activities with id less than the given UUID (Faster - Recommended!) - response = userFeed.getActivities(new Filter().idLessThan("e561de8f-00f1-11e4-b400-0cc47a024be0").limit(5)).join(); - // Get activities from 5 to 10 (Pagination-based - Slower) - response = userFeed.getActivities(new Pagination().offset(0).limit(5)).join(); - // Get activities sorted by rank (Ranked Feeds Enabled): - response = userFeed.getActivities(new Pagination().limit(5), "popularity").join(); - - /* -------------------------------------------------------- */ - - // timeline:timeline_feed_1 follows user:user_42 - FlatFeed user = client.flatFeed("user", "user_42"); - FlatFeed timeline = client.flatFeed("timeline", "timeline_feed_1"); - timeline.follow(user); - - // follow feed without copying the activities: - timeline.follow(user, 0); - - /* -------------------------------------------------------- */ - - // user := client.FlatFeed("user", "42") - - // Stop following feed user:user_42 - timeline.unfollow(user); - - // Stop following feed user:user_42 but keep history of activities - timeline.unfollow(user, KeepHistory.YES); - - // list followers - List followers = userFeed.getFollowers(new Pagination().offset(0).limit(10)).join(); - for (FollowRelation follow : followers) { - System.out.format("%s -> %s", follow.getSource(), follow.getTarget()); - // ... - } - - // Retrieve last 10 feeds followed by user_feed_1 - List followed = userFeed.getFollowed(new Pagination().offset(0).limit(10)).join(); - - // Retrieve 10 feeds followed by user_feed_1 starting from the 11th - followed = userFeed.getFollowed(new Pagination().offset(10).limit(10)).join(); - - // Check if user_feed_1 follows specific feeds - followed = userFeed.getFollowed(new Pagination().offset(0).limit(2), new FeedID("user:42"), new FeedID("user", "43")).join(); - - /* -------------------------------------------------------- */ - - NotificationFeed notifications = client.notificationFeed("notifications", "1"); - // Mark all activities in the feed as seen - List> activityGroups = notifications.getActivities(new ActivityMarker().allSeen()).join(); - for (NotificationGroup group : activityGroups) { - // ... - } - // Mark some activities as read via specific Activity Group Ids - activityGroups = notifications.getActivities(new ActivityMarker().read("groupID1", "groupID2" /* ... */)).join(); - - /* -------------------------------------------------------- */ - - // Add an activity to the feed, where actor, object and target are references to objects - adding your ranking method as a parameter (in this case, "popularity"): - activity = Activity.builder() - .actor("User:1") - .verb("pin") - .object("place:42") - .target("board:1") - .extraField("popularity", 5) - .build(); - userFeed.addActivity(activity); - - // Get activities sorted by the ranking method labelled 'activity_popularity' (Ranked Feeds Enabled) - response = userFeed.getActivities(new Pagination().limit(5), "activity_popularity").join(); - - /* -------------------------------------------------------- */ - - // Add the activity to Eric's feed and to Jessica's notification feed - activity = Activity.builder() - .actor("User:Eric") - .verb("tweet") - .object("tweet:id") - .to(Lists.newArrayList(new FeedID("notification:Jessica"))) - .extraField("message", "@Jessica check out getstream.io it's so dang awesome.") - .build(); - userFeed.addActivity(activity); - - // The TO field ensures the activity is send to the player, match and team feed - activity = Activity.builder() - .actor("Player:Suarez") - .verb("foul") - .object("Player:Ramos") - .to(Lists.newArrayList(new FeedID("team:barcelona"), new FeedID("match:1"))) - .extraField("match", ImmutableMap.of("El Classico", 10)) - .build(); - // playerFeed.addActivity(activity); - userFeed.addActivity(activity); - - /* -------------------------------------------------------- */ - - // Batch following many feeds - // Let timeline:1 will follow user:1, user:2 and user:3 - FollowRelation[] follows = new FollowRelation[]{ - new FollowRelation("timeline:1", "user:1"), - new FollowRelation("timeline:3", "user:2"), - new FollowRelation("timeline:1", "user:3") - }; - client.batch().followMany(follows); - // copy only the last 10 activities from every feed - client.batch().followMany(10, follows); - - /* -------------------------------------------------------- */ - - Activity[] activities = new Activity[]{ + .put("started_at", LocalDateTime.now()) + .put( + "location", + new ImmutableMap.Builder() + .put("type", "point") + .put("coordinates", new double[] {37.769722, -122.476944}) + .build()) + .build()) + .build(); + userFeed.addActivity(activity); + + // Remove an activity by its id + userFeed.removeActivityByID("e561de8f-00f1-11e4-b400-0cc47a024be0"); + + // Remove activities with foreign_id 'run:1' + userFeed.removeActivityByForeignID("run:1"); + + activity = + Activity.builder() + .actor("1") + .verb("like") + .object("3") + .time(new Date()) + .foreignID("like:3") + .extraField("popularity", 100) + .build(); + + // first time the activity is added + userFeed.addActivity(activity); + + // update the popularity value for the activity + activity = Activity.builder().fromActivity(activity).extraField("popularity", 10).build(); + + client.batch().updateActivities(activity); + + /* -------------------------------------------------------- */ + + // partial update by activity ID + + // prepare the set operations + Map set = + new ImmutableMap.Builder() + .put("product.price", 19.99) + .put( + "shares", + new ImmutableMap.Builder() + .put("facebook", "...") + .put("twitter", "...") + .build()) + .build(); + // prepare the unset operations + String[] unset = new String[] {"daily_likes", "popularity"}; + + String id = "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4"; + client.updateActivityByID(id, set, unset); + + String foreignID = "product:123"; + Date timestamp = new Date(); + client.updateActivityByForeignID(foreignID, timestamp, set, unset); + + FeedID[] add = new FeedID[0]; + FeedID[] remove = new FeedID[0]; + userFeed.updateActivityToTargets(activity, add, remove); + + FeedID[] newTargets = new FeedID[0]; + userFeed.replaceActivityToTargets(activity, newTargets); + + /* -------------------------------------------------------- */ + + Date now = new Date(); + Activity firstActivity = + userFeed + .addActivity( Activity.builder() - .actor("User:1") - .verb("tweet") - .object("Tweet:1") - .build(), + .actor("1") + .verb("like") + .object("3") + .time(now) + .foreignID("like:3") + .build()) + .join(); + Activity secondActivity = + userFeed + .addActivity( Activity.builder() - .actor("User:2") - .verb("watch") - .object("Movie:1") - .build() - }; - userFeed.addActivities(activities); - - /* -------------------------------------------------------- */ - - // adds 1 activity to many feeds in one request - activity = Activity.builder() - .actor("User:2") - .verb("pin") - .object("Place:42") - .target("Board:1") - .build(); - FeedID[] feeds = new FeedID[]{ - new FeedID("timeline", "1"), - new FeedID("timeline", "2"), - new FeedID("timeline", "3"), - new FeedID("timeline", "4") - }; - client.batch().addToMany(activity, feeds); - - /* -------------------------------------------------------- */ - - // retrieve two activities by ID - client.batch().getActivitiesByID("01b3c1dd-e7ab-4649-b5b3-b4371d8f7045", "ed2837a6-0a3b-4679-adc1-778a1704852"); - - // retrieve an activity by foreign ID and time - client.batch().getActivitiesByForeignID(new ForeignIDTimePair("foreignID1", new Date()), new ForeignIDTimePair("foreignID2", new Date())); - - /* -------------------------------------------------------- */ - - // connect to the us-east region - client = Client.builder(apiKey, secret) - .region(Region.US_EAST) - .build(); - - /* -------------------------------------------------------- */ - Reaction like = new Reaction.Builder() - .kind("like") - .activityID(activity.getID()) - .build(); - - // add a like reaction to the activity with id activityId - like = client.reactions().add("john-doe", like).join(); - - Reaction comment = new Reaction.Builder() - .kind("comment") - .activityID(activity.getID()) - .extraField("text", "awesome post!") - .build(); - - // adds a comment reaction to the activity with id activityId - comment = client.reactions().add("john-doe", comment).join(); - - /* -------------------------------------------------------- */ - - // first let's read current user's timeline feed and pick one activity - response = client.flatFeed("timeline", "mike").getActivities().join(); - activity = response.get(0); - - // then let's add a like reaction to that activity - client.reactions().add("john-doe", Reaction.builder() - .kind("like") - .activityID(activity.getID()) - .build()); - - /* -------------------------------------------------------- */ - - comment = new Reaction.Builder() - .kind("comment") - .activityID(activity.getID()) - .extraField("text", "awesome post!") - .build(); - - // adds a comment reaction to the activity and notify Thierry's notification feed - client.reactions().add("john-doe", comment, new FeedID("notification:thierry")); - - /* -------------------------------------------------------- */ - - // read bob's timeline and include most recent reactions to all activities and their total count - client.flatFeed("timeline", "bob") - .getEnrichedActivities(new EnrichmentFlags() - .withRecentReactions() - .withReactionCounts()); - - // read bob's timeline and include most recent reactions to all activities and her own reactions - client.flatFeed("timeline", "bob") - .getEnrichedActivities(new EnrichmentFlags() - .withOwnReactions() - .withRecentReactions() - .withReactionCounts()); - - /* -------------------------------------------------------- */ - - // retrieve all kind of reactions for an activity - List reactions = client.reactions().filter(LookupKind.ACTIVITY, "ed2837a6-0a3b-4679-adc1-778a1704852d").join(); - - // retrieve first 10 likes for an activity - reactions = client.reactions() - .filter(LookupKind.ACTIVITY, - "ed2837a6-0a3b-4679-adc1-778a1704852d", - new Filter().limit(10), - "like").join(); - - // retrieve the next 10 likes using the id_lt param - reactions = client.reactions() - .filter(LookupKind.ACTIVITY, - "ed2837a6-0a3b-4679-adc1-778a1704852d", - new Filter().idLessThan("e561de8f-00f1-11e4-b400-0cc47a024be0"), - "like").join(); - - /* -------------------------------------------------------- */ - - // adds a like to the previously created comment - Reaction reaction = client.reactions().addChild("john-doe", comment.getId(), Reaction.builder().kind("like").build()).join(); - - /* -------------------------------------------------------- */ - - client.reactions().update(Reaction.builder() - .id(reaction.getId()) - .extraField("text", "love it!") - .build()); - - /* -------------------------------------------------------- */ + .actor("1") + .verb("like") + .object("3") + .time(now) + .extraField("extra", "extra_value") + .foreignID("like:3") + .build()) + .join(); + // foreign ID and time are the same for both activities + // hence only one activity is created and first and second IDs are equal + // firstActivity.ID == secondActivity.ID + + /* -------------------------------------------------------- */ + + // Get 5 activities with id less than the given UUID (Faster - Recommended!) + response = + userFeed + .getActivities(new Filter().idLessThan("e561de8f-00f1-11e4-b400-0cc47a024be0").limit(5)) + .join(); + // Get activities from 5 to 10 (Pagination-based - Slower) + response = userFeed.getActivities(new Pagination().offset(0).limit(5)).join(); + // Get activities sorted by rank (Ranked Feeds Enabled): + response = userFeed.getActivities(new Pagination().limit(5), "popularity").join(); + + /* -------------------------------------------------------- */ + + // timeline:timeline_feed_1 follows user:user_42 + FlatFeed user = client.flatFeed("user", "user_42"); + FlatFeed timeline = client.flatFeed("timeline", "timeline_feed_1"); + timeline.follow(user); + + // follow feed without copying the activities: + timeline.follow(user, 0); + + /* -------------------------------------------------------- */ + + // user := client.FlatFeed("user", "42") + + // Stop following feed user:user_42 + timeline.unfollow(user); + + // Stop following feed user:user_42 but keep history of activities + timeline.unfollow(user, KeepHistory.YES); + + // list followers + List followers = + userFeed.getFollowers(new Pagination().offset(0).limit(10)).join(); + for (FollowRelation follow : followers) { + System.out.format("%s -> %s", follow.getSource(), follow.getTarget()); + // ... + } - client.reactions().delete(reaction.getId()); + // Retrieve last 10 feeds followed by user_feed_1 + List followed = + userFeed.getFollowed(new Pagination().offset(0).limit(10)).join(); + + // Retrieve 10 feeds followed by user_feed_1 starting from the 11th + followed = userFeed.getFollowed(new Pagination().offset(10).limit(10)).join(); + + // Check if user_feed_1 follows specific feeds + followed = + userFeed + .getFollowed( + new Pagination().offset(0).limit(2), + new FeedID("user:42"), + new FeedID("user", "43")) + .join(); + + /* -------------------------------------------------------- */ + + NotificationFeed notifications = client.notificationFeed("notifications", "1"); + // Mark all activities in the feed as seen + List> activityGroups = + notifications.getActivities(new ActivityMarker().allSeen()).join(); + for (NotificationGroup group : activityGroups) { + // ... + } + // Mark some activities as read via specific Activity Group Ids + activityGroups = + notifications + .getActivities(new ActivityMarker().read("groupID1", "groupID2" /* ... */)) + .join(); + + /* -------------------------------------------------------- */ + + // Add an activity to the feed, where actor, object and target are references to objects - + // adding your ranking method as a parameter (in this case, "popularity"): + activity = + Activity.builder() + .actor("User:1") + .verb("pin") + .object("place:42") + .target("board:1") + .extraField("popularity", 5) + .build(); + userFeed.addActivity(activity); + + // Get activities sorted by the ranking method labelled 'activity_popularity' (Ranked Feeds + // Enabled) + response = userFeed.getActivities(new Pagination().limit(5), "activity_popularity").join(); + + /* -------------------------------------------------------- */ + + // Add the activity to Eric's feed and to Jessica's notification feed + activity = + Activity.builder() + .actor("User:Eric") + .verb("tweet") + .object("tweet:id") + .to(Lists.newArrayList(new FeedID("notification:Jessica"))) + .extraField("message", "@Jessica check out getstream.io it's so dang awesome.") + .build(); + userFeed.addActivity(activity); + + // The TO field ensures the activity is send to the player, match and team feed + activity = + Activity.builder() + .actor("Player:Suarez") + .verb("foul") + .object("Player:Ramos") + .to(Lists.newArrayList(new FeedID("team:barcelona"), new FeedID("match:1"))) + .extraField("match", ImmutableMap.of("El Classico", 10)) + .build(); + // playerFeed.addActivity(activity); + userFeed.addActivity(activity); + + /* -------------------------------------------------------- */ + + // Batch following many feeds + // Let timeline:1 will follow user:1, user:2 and user:3 + FollowRelation[] follows = + new FollowRelation[] { + new FollowRelation("timeline:1", "user:1"), + new FollowRelation("timeline:3", "user:2"), + new FollowRelation("timeline:1", "user:3") + }; + client.batch().followMany(follows); + // copy only the last 10 activities from every feed + client.batch().followMany(10, follows); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.collections().add("food", new CollectionData("cheese-burger") + Activity[] activities = + new Activity[] { + Activity.builder().actor("User:1").verb("tweet").object("Tweet:1").build(), + Activity.builder().actor("User:2").verb("watch").object("Movie:1").build() + }; + userFeed.addActivities(activities); + + /* -------------------------------------------------------- */ + + // adds 1 activity to many feeds in one request + activity = + Activity.builder().actor("User:2").verb("pin").object("Place:42").target("Board:1").build(); + FeedID[] feeds = + new FeedID[] { + new FeedID("timeline", "1"), + new FeedID("timeline", "2"), + new FeedID("timeline", "3"), + new FeedID("timeline", "4") + }; + client.batch().addToMany(activity, feeds); + + /* -------------------------------------------------------- */ + + // retrieve two activities by ID + client + .batch() + .getActivitiesByID( + "01b3c1dd-e7ab-4649-b5b3-b4371d8f7045", "ed2837a6-0a3b-4679-adc1-778a1704852"); + + // retrieve an activity by foreign ID and time + client + .batch() + .getActivitiesByForeignID( + new ForeignIDTimePair("foreignID1", new Date()), + new ForeignIDTimePair("foreignID2", new Date())); + + /* -------------------------------------------------------- */ + + // connect to the us-east region + client = Client.builder(apiKey, secret).region(Region.US_EAST).build(); + + /* -------------------------------------------------------- */ + Reaction like = new Reaction.Builder().kind("like").activityID(activity.getID()).build(); + + // add a like reaction to the activity with id activityId + like = client.reactions().add("john-doe", like).join(); + + Reaction comment = + new Reaction.Builder() + .kind("comment") + .activityID(activity.getID()) + .extraField("text", "awesome post!") + .build(); + + // adds a comment reaction to the activity with id activityId + comment = client.reactions().add("john-doe", comment).join(); + + /* -------------------------------------------------------- */ + + // first let's read current user's timeline feed and pick one activity + response = client.flatFeed("timeline", "mike").getActivities().join(); + activity = response.get(0); + + // then let's add a like reaction to that activity + client + .reactions() + .add("john-doe", Reaction.builder().kind("like").activityID(activity.getID()).build()); + + /* -------------------------------------------------------- */ + + comment = + new Reaction.Builder() + .kind("comment") + .activityID(activity.getID()) + .extraField("text", "awesome post!") + .build(); + + // adds a comment reaction to the activity and notify Thierry's notification feed + client.reactions().add("john-doe", comment, new FeedID("notification:thierry")); + + /* -------------------------------------------------------- */ + + // read bob's timeline and include most recent reactions to all activities and their total count + client + .flatFeed("timeline", "bob") + .getEnrichedActivities(new EnrichmentFlags().withRecentReactions().withReactionCounts()); + + // read bob's timeline and include most recent reactions to all activities and her own reactions + client + .flatFeed("timeline", "bob") + .getEnrichedActivities( + new EnrichmentFlags().withOwnReactions().withRecentReactions().withReactionCounts()); + + /* -------------------------------------------------------- */ + + // retrieve all kind of reactions for an activity + List reactions = + client + .reactions() + .filter(LookupKind.ACTIVITY, "ed2837a6-0a3b-4679-adc1-778a1704852d") + .join(); + + // retrieve first 10 likes for an activity + reactions = + client + .reactions() + .filter( + LookupKind.ACTIVITY, + "ed2837a6-0a3b-4679-adc1-778a1704852d", + new Filter().limit(10), + "like") + .join(); + + // retrieve the next 10 likes using the id_lt param + reactions = + client + .reactions() + .filter( + LookupKind.ACTIVITY, + "ed2837a6-0a3b-4679-adc1-778a1704852d", + new Filter().idLessThan("e561de8f-00f1-11e4-b400-0cc47a024be0"), + "like") + .join(); + + /* -------------------------------------------------------- */ + + // adds a like to the previously created comment + Reaction reaction = + client + .reactions() + .addChild("john-doe", comment.getId(), Reaction.builder().kind("like").build()) + .join(); + + /* -------------------------------------------------------- */ + + client + .reactions() + .update(Reaction.builder().id(reaction.getId()).extraField("text", "love it!").build()); + + /* -------------------------------------------------------- */ + + client.reactions().delete(reaction.getId()); + + /* -------------------------------------------------------- */ + + client + .collections() + .add( + "food", + new CollectionData("cheese-burger") .set("name", "Cheese Burger") .set("rating", "4 stars")); - // if you don't have an id on your side, just use null as the ID and Stream will generate a unique ID - client.collections().add("food", new CollectionData() - .set("name", "Cheese Burger") - .set("rating", "4 stars")); + // if you don't have an id on your side, just use null as the ID and Stream will generate a + // unique ID + client + .collections() + .add("food", new CollectionData().set("name", "Cheese Burger").set("rating", "4 stars")); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - CollectionData collection = client.collections().get("food", "cheese-burger").join(); + CollectionData collection = client.collections().get("food", "cheese-burger").join(); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.collections().delete("food", "cheese-burger"); + client.collections().delete("food", "cheese-burger"); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.collections().update("food", new CollectionData("cheese-burger") + client + .collections() + .update( + "food", + new CollectionData("cheese-burger") .set("name", "Cheese Burger") .set("rating", "1 star")); - /* -------------------------------------------------------- */ - - client.collections().upsert("visitor", - new CollectionData("123") - .set("name", "John") - .set("favorite_color", "blue"), - new CollectionData("124") - .set("name", "Jane") - .set("favorite_color", "purple") - .set("interests", Lists.newArrayList("fashion", "jazz"))); - - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // select the entries with ID 123 and 124 from items collection - List objects = client.collections().select("items", "123", "124").join(); + client + .collections() + .upsert( + "visitor", + new CollectionData("123").set("name", "John").set("favorite_color", "blue"), + new CollectionData("124") + .set("name", "Jane") + .set("favorite_color", "purple") + .set("interests", Lists.newArrayList("fashion", "jazz"))); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // delete the entries with ID 123 and 124 from visitor collection - client.collections().deleteMany("visitor", "123", "124"); + // select the entries with ID 123 and 124 from items collection + List objects = client.collections().select("items", "123", "124").join(); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // first we add our object to the food collection - CollectionData cheeseBurger = client.collections().add("food", new CollectionData("123") - .set("name", "Cheese Burger") - .set("ingredients", Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))).join(); + // delete the entries with ID 123 and 124 from visitor collection + client.collections().deleteMany("visitor", "123", "124"); - // the object returned by .add can be embedded directly inside of an activity - userFeed.addActivity(Activity.builder() - .actor(createUserReference("john-doe")) - .verb("grill") - .object(createCollectionReference(cheeseBurger.getCollection(), cheeseBurger.getID())) - .build()); + /* -------------------------------------------------------- */ - // if we now read the feed, the activity we just added will include the entire full object - userFeed.getEnrichedActivities(); - - // we can then update the object and Stream will propagate the change to all activities - client.collections().update(cheeseBurger.getCollection(), cheeseBurger - .set("name", "Amazing Cheese Burger") - .set("ingredients", Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))).join(); - - /* -------------------------------------------------------- */ - - // First create a collection entry with upsert api - client.collections().upsert("food", new CollectionData().set("name", "Cheese Burger")); - - // Then create a user - client.user("john-doe").create(new Data() + // first we add our object to the food collection + CollectionData cheeseBurger = + client + .collections() + .add( + "food", + new CollectionData("123") + .set("name", "Cheese Burger") + .set( + "ingredients", + Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))) + .join(); + + // the object returned by .add can be embedded directly inside of an activity + userFeed.addActivity( + Activity.builder() + .actor(createUserReference("john-doe")) + .verb("grill") + .object(createCollectionReference(cheeseBurger.getCollection(), cheeseBurger.getID())) + .build()); + + // if we now read the feed, the activity we just added will include the entire full object + userFeed.getEnrichedActivities(); + + // we can then update the object and Stream will propagate the change to all activities + client + .collections() + .update( + cheeseBurger.getCollection(), + cheeseBurger + .set("name", "Amazing Cheese Burger") + .set( + "ingredients", + Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))) + .join(); + + /* -------------------------------------------------------- */ + + // First create a collection entry with upsert api + client.collections().upsert("food", new CollectionData().set("name", "Cheese Burger")); + + // Then create a user + client + .user("john-doe") + .create( + new Data() .set("name", "John Doe") .set("occupation", "Software Engineer") .set("gender", "male")); - // Since we know their IDs we can create references to both without reading from APIs - String cheeseBurgerRef = createCollectionReference("food", "cheese-burger"); - String johnDoeRef = createUserReference("john-doe"); + // Since we know their IDs we can create references to both without reading from APIs + String cheeseBurgerRef = createCollectionReference("food", "cheese-burger"); + String johnDoeRef = createUserReference("john-doe"); - client.flatFeed("user", "john").addActivity(Activity.builder() - .actor(johnDoeRef) - .verb("eat") - .object(cheeseBurgerRef) - .build()); + client + .flatFeed("user", "john") + .addActivity( + Activity.builder().actor(johnDoeRef).verb("eat").object(cheeseBurgerRef).build()); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // create a new user, if the user already exist an error is returned - client.user("john-doe").create(new Data() + // create a new user, if the user already exist an error is returned + client + .user("john-doe") + .create( + new Data() .set("name", "John Doe") .set("occupation", "Software Engineer") .set("gender", "male")); - // get or create a new user, if the user already exist the user is returned - client.user("john-doe").getOrCreate(new Data() + // get or create a new user, if the user already exist the user is returned + client + .user("john-doe") + .getOrCreate( + new Data() .set("name", "John Doe") .set("occupation", "Software Engineer") .set("gender", "male")); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.user("123").get(); + client.user("123").get(); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.user("123").delete(); + client.user("123").delete(); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.user("123").update(new Data() + client + .user("123") + .update( + new Data() .set("name", "Jane Doe") .set("occupation", "Software Engineer") .set("gender", "female")); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // Read the personalization feed for a given user - client.personalization().get("personalized_feed", new ImmutableMap.Builder() + // Read the personalization feed for a given user + client + .personalization() + .get( + "personalized_feed", + new ImmutableMap.Builder() .put("user_id", 123) .put("feed_slug", "timeline") .build()); - // Our data science team will typically tell you which endpoint to use - client.personalization().get("discovery_feed", new ImmutableMap.Builder() + // Our data science team will typically tell you which endpoint to use + client + .personalization() + .get( + "discovery_feed", + new ImmutableMap.Builder() .put("user_id", 123) .put("source_feed_slug", "timeline") .put("target_feed_slug", "user") .build()); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.analytics().trackEngagement(Engagement.builder() + client + .analytics() + .trackEngagement( + Engagement.builder() .feedID("user:thierry") - .content(new Content("message:34349698") + .content( + new Content("message:34349698") .set("verb", "share") .set("actor", ImmutableMap.of("1", "user1"))) .boost(2) @@ -558,33 +647,39 @@ public static void main(String[] args) throws Exception { .position(3) .build()); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - client.analytics().trackImpression(Impression.builder() - .contentList(new Content("tweet:34349698") + client + .analytics() + .trackImpression( + Impression.builder() + .contentList( + new Content("tweet:34349698") .set("verb", "share") .set("actor", ImmutableMap.of("1", "user1")), - new Content("tweet:34349699"), - new Content("tweet:34349700")) + new Content("tweet:34349699"), + new Content("tweet:34349700")) .feedID("flat:tommaso") .location("android-app") .build()); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // the URL to direct to - URL targetURL = new URL("http://mysite.com/detail"); + // the URL to direct to + URL targetURL = new URL("http://mysite.com/detail"); - // track the impressions and a click - List impressions = Lists.newArrayList(Impression.builder() - .contentList(new Content("tweet:1"), - new Content("tweet:2"), - new Content("tweet:3")) + // track the impressions and a click + List impressions = + Lists.newArrayList( + Impression.builder() + .contentList(new Content("tweet:1"), new Content("tweet:2"), new Content("tweet:3")) .userData(new UserData("tommaso", null)) .location("email") .feedID("user:global") .build()); - List engagements = Lists.newArrayList(Engagement.builder() + List engagements = + Lists.newArrayList( + Engagement.builder() .content(new Content("tweet:2")) .label("click") .position(1) @@ -593,36 +688,36 @@ public static void main(String[] args) throws Exception { .feedID("user:global") .build()); - // when the user opens the tracking URL in their browser gets redirected to the target URL - // the events are added to our analytics platform - URL trackingURL = client.analytics().createRedirectURL(targetURL, impressions, engagements); + // when the user opens the tracking URL in their browser gets redirected to the target URL + // the events are added to our analytics platform + URL trackingURL = client.analytics().createRedirectURL(targetURL, impressions, engagements); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - File image = new File("..."); - URL imageURL = client.images().upload(image).join(); + File image = new File("..."); + URL imageURL = client.images().upload(image).join(); - File file = new File("..."); - URL fileURL = client.files().upload(file).join(); + File file = new File("..."); + URL fileURL = client.files().upload(file).join(); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // deleting an image using the url returned by the APIs - client.images().delete(imageURL); + // deleting an image using the url returned by the APIs + client.images().delete(imageURL); - // deleting a file using the url returned by the APIs - client.files().delete(fileURL); + // deleting a file using the url returned by the APIs + client.files().delete(fileURL); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - // create a 50x50 thumbnail and crop from center - client.images().process(imageURL, new Resize(50, 50, Resize.Type.CROP)); + // create a 50x50 thumbnail and crop from center + client.images().process(imageURL, new Resize(50, 50, Resize.Type.CROP)); - // create a 50x50 thumbnail using clipping (keeps aspect ratio) - client.images().process(imageURL, new Resize(50, 50, Resize.Type.CLIP)); + // create a 50x50 thumbnail using clipping (keeps aspect ratio) + client.images().process(imageURL, new Resize(50, 50, Resize.Type.CLIP)); - /* -------------------------------------------------------- */ + /* -------------------------------------------------------- */ - OGData urlPreview = client.openGraph(new URL("http://www.imdb.com/title/tt0117500/")).join(); - } + OGData urlPreview = client.openGraph(new URL("http://www.imdb.com/title/tt0117500/")).join(); + } } diff --git a/src/main/java/io/getstream/client/AggregatedFeed.java b/src/main/java/io/getstream/client/AggregatedFeed.java index 47ecc7e0..fb857ed9 100644 --- a/src/main/java/io/getstream/client/AggregatedFeed.java +++ b/src/main/java/io/getstream/client/AggregatedFeed.java @@ -1,5 +1,7 @@ package io.getstream.client; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; @@ -7,352 +9,698 @@ import io.getstream.core.models.Group; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class AggregatedFeed extends Feed { - AggregatedFeed(Client client, FeedID id) { - super(client, id); - } - - public CompletableFuture>> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + AggregatedFeed(Client client, FeedID id) { + super(client, id); + } + + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getCustomActivities( + Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> + getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/client/AnalyticsClient.java b/src/main/java/io/getstream/client/AnalyticsClient.java index 5d74b60f..7c03cbd3 100644 --- a/src/main/java/io/getstream/client/AnalyticsClient.java +++ b/src/main/java/io/getstream/client/AnalyticsClient.java @@ -1,5 +1,8 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildAnalyticsRedirectToken; +import static io.getstream.core.utils.Auth.buildAnalyticsToken; + import com.google.common.collect.Iterables; import io.getstream.core.StreamAnalytics; import io.getstream.core.exceptions.StreamException; @@ -7,50 +10,53 @@ import io.getstream.core.models.Engagement; import io.getstream.core.models.Impression; import io.getstream.core.utils.Auth.TokenAction; -import java8.util.concurrent.CompletableFuture; - import java.net.URL; - -import static io.getstream.core.utils.Auth.buildAnalyticsRedirectToken; -import static io.getstream.core.utils.Auth.buildAnalyticsToken; +import java8.util.concurrent.CompletableFuture; public final class AnalyticsClient { - private final String secret; - private final StreamAnalytics analytics; - - AnalyticsClient(String secret, StreamAnalytics analytics) { - this.secret = secret; - this.analytics = analytics; - } - - public CompletableFuture trackEngagement(Iterable events) throws StreamException { - return trackEngagement(Iterables.toArray(events, Engagement.class)); - } - - public CompletableFuture trackEngagement(Engagement... events) throws StreamException { - final Token token = buildAnalyticsToken(secret, TokenAction.WRITE); - return analytics.trackEngagement(token, events); - } - - public CompletableFuture trackImpression(Impression event) throws StreamException { - final Token token = buildAnalyticsToken(secret, TokenAction.WRITE); - return analytics.trackImpression(token, event); - } - - public URL createRedirectURL(URL url, Engagement... engagements) throws StreamException { - return createRedirectURL(url, new Impression[0], engagements); - } - - public URL createRedirectURL(URL url, Impression... impressions) throws StreamException { - return createRedirectURL(url, impressions, new Engagement[0]); - } - - public URL createRedirectURL(URL url, Iterable impressions, Iterable engagements) throws StreamException { - return createRedirectURL(url, Iterables.toArray(impressions, Impression.class), Iterables.toArray(engagements, Engagement.class)); - } - - public URL createRedirectURL(URL url, Impression[] impressions, Engagement[] engagements) throws StreamException { - final Token token = buildAnalyticsRedirectToken(secret); - return analytics.createRedirectURL(token, url, impressions, engagements); - } + private final String secret; + private final StreamAnalytics analytics; + + AnalyticsClient(String secret, StreamAnalytics analytics) { + this.secret = secret; + this.analytics = analytics; + } + + public CompletableFuture trackEngagement(Iterable events) + throws StreamException { + return trackEngagement(Iterables.toArray(events, Engagement.class)); + } + + public CompletableFuture trackEngagement(Engagement... events) throws StreamException { + final Token token = buildAnalyticsToken(secret, TokenAction.WRITE); + return analytics.trackEngagement(token, events); + } + + public CompletableFuture trackImpression(Impression event) throws StreamException { + final Token token = buildAnalyticsToken(secret, TokenAction.WRITE); + return analytics.trackImpression(token, event); + } + + public URL createRedirectURL(URL url, Engagement... engagements) throws StreamException { + return createRedirectURL(url, new Impression[0], engagements); + } + + public URL createRedirectURL(URL url, Impression... impressions) throws StreamException { + return createRedirectURL(url, impressions, new Engagement[0]); + } + + public URL createRedirectURL( + URL url, Iterable impressions, Iterable engagements) + throws StreamException { + return createRedirectURL( + url, + Iterables.toArray(impressions, Impression.class), + Iterables.toArray(engagements, Engagement.class)); + } + + public URL createRedirectURL(URL url, Impression[] impressions, Engagement[] engagements) + throws StreamException { + final Token token = buildAnalyticsRedirectToken(secret); + return analytics.createRedirectURL(token, url, impressions, engagements); + } } diff --git a/src/main/java/io/getstream/client/BatchClient.java b/src/main/java/io/getstream/client/BatchClient.java index d202f354..62a6def0 100644 --- a/src/main/java/io/getstream/client/BatchClient.java +++ b/src/main/java/io/getstream/client/BatchClient.java @@ -1,113 +1,131 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.*; + import com.google.common.collect.Iterables; +import io.getstream.core.KeepHistory; import io.getstream.core.StreamBatch; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; import io.getstream.core.models.*; -import io.getstream.core.KeepHistory; import io.getstream.core.utils.DefaultOptions; +import java.util.List; import java8.util.J8Arrays; import java8.util.concurrent.CompletableFuture; -import java.util.List; - -import static io.getstream.core.utils.Auth.*; - public final class BatchClient { - private final String secret; - private final StreamBatch batch; - - BatchClient(String secret, StreamBatch batch) { - this.secret = secret; - this.batch = batch; - } - - public CompletableFuture addToMany(Activity activity, FeedID... feeds) throws StreamException { - final Token token = buildFeedToken(secret, TokenAction.WRITE); - return batch.addToMany(token, activity, feeds); - } - - public CompletableFuture followMany(int activityCopyLimit, FollowRelation... follows) throws StreamException { - final Token token = buildFollowToken(secret, TokenAction.WRITE); - return batch.followMany(token, activityCopyLimit, follows); - } - - public CompletableFuture followMany(int activityCopyLimit, Iterable follows) throws StreamException { - return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class)); - } - - public CompletableFuture followMany(FollowRelation... follows) throws StreamException { - return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows); - } - - public CompletableFuture followMany(Iterable follows) throws StreamException { - return followMany(Iterables.toArray(follows, FollowRelation.class)); - } - - public CompletableFuture unfollowMany(FollowRelation... follows) throws StreamException { - final Token token = buildFollowToken(secret, TokenAction.WRITE); - final UnfollowOperation[] ops = J8Arrays.stream(follows) - .map(follow -> new UnfollowOperation(follow, io.getstream.core.KeepHistory.YES)) - .toArray(UnfollowOperation[]::new); - return batch.unfollowMany(token, ops); - } - - public CompletableFuture unfollowMany(KeepHistory keepHistory, FollowRelation... follows) throws StreamException { - final Token token = buildFollowToken(secret, TokenAction.WRITE); - final UnfollowOperation[] ops = J8Arrays.stream(follows) - .map(follow -> new UnfollowOperation(follow, keepHistory)) - .toArray(UnfollowOperation[]::new); - return batch.unfollowMany(token, ops); - } - - public CompletableFuture unfollowMany(UnfollowOperation... unfollows) throws StreamException { - final Token token = buildFollowToken(secret, TokenAction.WRITE); - return batch.unfollowMany(token, unfollows); - } - - public CompletableFuture> getActivitiesByID(Iterable activityIDs) throws StreamException { - return getActivitiesByID(Iterables.toArray(activityIDs, String.class)); - } - - public CompletableFuture> getActivitiesByID(String... activityIDs) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.READ); - return batch.getActivitiesByID(token, activityIDs); - } - - public CompletableFuture> getEnrichedActivitiesByID(Iterable activityIDs) throws StreamException { - return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class)); - } - - public CompletableFuture> getEnrichedActivitiesByID(String... activityIDs) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.READ); - return batch.getEnrichedActivitiesByID(token, activityIDs); - } - - public CompletableFuture> getActivitiesByForeignID(Iterable activityIDTimePairs) throws StreamException { - return getActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); - } - - public CompletableFuture> getActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.READ); - return batch.getActivitiesByForeignID(token, activityIDTimePairs); - } - - public CompletableFuture> getEnrichedActivitiesByForeignID(Iterable activityIDTimePairs) throws StreamException { - return getEnrichedActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); - } - - public CompletableFuture> getEnrichedActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.READ); - return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs); - } - - public CompletableFuture updateActivities(Iterable activities) throws StreamException { - return updateActivities(Iterables.toArray(activities, Activity.class)); - } - - public CompletableFuture updateActivities(Activity... activities) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.WRITE); - return batch.updateActivities(token, activities); - } + private final String secret; + private final StreamBatch batch; + + BatchClient(String secret, StreamBatch batch) { + this.secret = secret; + this.batch = batch; + } + + public CompletableFuture addToMany(Activity activity, FeedID... feeds) + throws StreamException { + final Token token = buildFeedToken(secret, TokenAction.WRITE); + return batch.addToMany(token, activity, feeds); + } + + public CompletableFuture followMany(int activityCopyLimit, FollowRelation... follows) + throws StreamException { + final Token token = buildFollowToken(secret, TokenAction.WRITE); + return batch.followMany(token, activityCopyLimit, follows); + } + + public CompletableFuture followMany(int activityCopyLimit, Iterable follows) + throws StreamException { + return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class)); + } + + public CompletableFuture followMany(FollowRelation... follows) throws StreamException { + return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows); + } + + public CompletableFuture followMany(Iterable follows) + throws StreamException { + return followMany(Iterables.toArray(follows, FollowRelation.class)); + } + + public CompletableFuture unfollowMany(FollowRelation... follows) throws StreamException { + final Token token = buildFollowToken(secret, TokenAction.WRITE); + final UnfollowOperation[] ops = + J8Arrays.stream(follows) + .map(follow -> new UnfollowOperation(follow, io.getstream.core.KeepHistory.YES)) + .toArray(UnfollowOperation[]::new); + return batch.unfollowMany(token, ops); + } + + public CompletableFuture unfollowMany(KeepHistory keepHistory, FollowRelation... follows) + throws StreamException { + final Token token = buildFollowToken(secret, TokenAction.WRITE); + final UnfollowOperation[] ops = + J8Arrays.stream(follows) + .map(follow -> new UnfollowOperation(follow, keepHistory)) + .toArray(UnfollowOperation[]::new); + return batch.unfollowMany(token, ops); + } + + public CompletableFuture unfollowMany(UnfollowOperation... unfollows) + throws StreamException { + final Token token = buildFollowToken(secret, TokenAction.WRITE); + return batch.unfollowMany(token, unfollows); + } + + public CompletableFuture> getActivitiesByID(Iterable activityIDs) + throws StreamException { + return getActivitiesByID(Iterables.toArray(activityIDs, String.class)); + } + + public CompletableFuture> getActivitiesByID(String... activityIDs) + throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.READ); + return batch.getActivitiesByID(token, activityIDs); + } + + public CompletableFuture> getEnrichedActivitiesByID( + Iterable activityIDs) throws StreamException { + return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class)); + } + + public CompletableFuture> getEnrichedActivitiesByID(String... activityIDs) + throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.READ); + return batch.getEnrichedActivitiesByID(token, activityIDs); + } + + public CompletableFuture> getActivitiesByForeignID( + Iterable activityIDTimePairs) throws StreamException { + return getActivitiesByForeignID( + Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); + } + + public CompletableFuture> getActivitiesByForeignID( + ForeignIDTimePair... activityIDTimePairs) throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.READ); + return batch.getActivitiesByForeignID(token, activityIDTimePairs); + } + + public CompletableFuture> getEnrichedActivitiesByForeignID( + Iterable activityIDTimePairs) throws StreamException { + return getEnrichedActivitiesByForeignID( + Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class)); + } + + public CompletableFuture> getEnrichedActivitiesByForeignID( + ForeignIDTimePair... activityIDTimePairs) throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.READ); + return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs); + } + + public CompletableFuture updateActivities(Iterable activities) + throws StreamException { + return updateActivities(Iterables.toArray(activities, Activity.class)); + } + + public CompletableFuture updateActivities(Activity... activities) throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.WRITE); + return batch.updateActivities(token, activities); + } } diff --git a/src/main/java/io/getstream/client/Client.java b/src/main/java/io/getstream/client/Client.java index 8eec5bd7..00783e97 100644 --- a/src/main/java/io/getstream/client/Client.java +++ b/src/main/java/io/getstream/client/Client.java @@ -1,5 +1,9 @@ package io.getstream.client; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Auth.*; + import com.google.common.collect.Iterables; import io.getstream.core.Region; import io.getstream.core.Stream; @@ -10,318 +14,343 @@ import io.getstream.core.http.Token; import io.getstream.core.models.*; import io.getstream.core.options.RequestOption; -import java8.util.concurrent.CompletableFuture; - import java.net.MalformedURLException; import java.net.URL; import java.util.Date; import java.util.List; import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Auth.*; +import java8.util.concurrent.CompletableFuture; public final class Client { + private final String secret; + private final Stream stream; + + private Client(String key, String secret, URL baseURL, HTTPClient httpClient) { + this.secret = secret; + this.stream = new Stream(key, baseURL, httpClient); + } + + public static Builder builder(String apiKey, String secret) { + return new Builder(apiKey, secret); + } + + public CompletableFuture updateActivityByID( + String id, Map set, Iterable unset) throws StreamException { + return updateActivityByID(id, set, Iterables.toArray(unset, String.class)); + } + + public CompletableFuture updateActivityByID(ActivityUpdate update) + throws StreamException { + return updateActivityByID(update.getID(), update.getSet(), update.getUnset()); + } + + public CompletableFuture updateActivityByID( + String id, Map set, String[] unset) throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.WRITE); + return stream.updateActivityByID(token, id, set, unset); + } + + public CompletableFuture updateActivityByForeignID( + ForeignIDTimePair foreignIDTimePair, Map set, Iterable unset) + throws StreamException { + checkNotNull(foreignIDTimePair, "No activity to update"); + return updateActivityByForeignID( + foreignIDTimePair.getForeignID(), foreignIDTimePair.getTime(), set, unset); + } + + public CompletableFuture updateActivityByForeignID( + ForeignIDTimePair foreignIDTimePair, Map set, String[] unset) + throws StreamException { + checkNotNull(foreignIDTimePair, "No activity to update"); + return updateActivityByForeignID( + foreignIDTimePair.getForeignID(), foreignIDTimePair.getTime(), set, unset); + } + + public CompletableFuture updateActivityByForeignID( + String foreignID, Date timestamp, Map set, Iterable unset) + throws StreamException { + return updateActivityByForeignID( + foreignID, timestamp, set, Iterables.toArray(unset, String.class)); + } + + public CompletableFuture updateActivityByForeignID(ActivityUpdate update) + throws StreamException { + return updateActivityByForeignID( + update.getForeignID(), update.getTime(), update.getSet(), update.getUnset()); + } + + public CompletableFuture updateActivityByForeignID( + String foreignID, Date timestamp, Map set, String[] unset) + throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.WRITE); + return stream.updateActivityByForeignID(token, foreignID, timestamp, set, unset); + } + + public CompletableFuture openGraph(URL url) throws StreamException { + final Token token = buildOpenGraphToken(secret); + return stream.openGraph(token, url); + } + + public CompletableFuture> updateActivitiesByID(Iterable updates) + throws StreamException { + return updateActivitiesByID(Iterables.toArray(updates, ActivityUpdate.class)); + } + + public CompletableFuture> updateActivitiesByID(ActivityUpdate... updates) + throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.WRITE); + return stream.updateActivitiesByID(token, updates); + } + + public CompletableFuture> updateActivitiesByForeignID( + Iterable updates) throws StreamException { + return updateActivitiesByForeignID(Iterables.toArray(updates, ActivityUpdate.class)); + } + + public CompletableFuture> updateActivitiesByForeignID(ActivityUpdate... updates) + throws StreamException { + final Token token = buildActivityToken(secret, TokenAction.WRITE); + return stream.updateActivitiesByForeignID(token, updates); + } + + public static final class Builder { + private static final String DEFAULT_HOST = "stream-io-api.com"; + + private final String apiKey; private final String secret; - private final Stream stream; - - private Client(String key, String secret, URL baseURL, HTTPClient httpClient) { - this.secret = secret; - this.stream = new Stream(key, baseURL, httpClient); - } - - public static Builder builder(String apiKey, String secret) { - return new Builder(apiKey, secret); - } - - public CompletableFuture updateActivityByID(String id, Map set, Iterable unset) throws StreamException { - return updateActivityByID(id, set, Iterables.toArray(unset, String.class)); - } - - public CompletableFuture updateActivityByID(ActivityUpdate update) throws StreamException { - return updateActivityByID(update.getID(), update.getSet(), update.getUnset()); - } - - public CompletableFuture updateActivityByID(String id, Map set, String[] unset) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.WRITE); - return stream.updateActivityByID(token, id, set, unset); - } - - public CompletableFuture updateActivityByForeignID(ForeignIDTimePair foreignIDTimePair, Map set, Iterable unset) throws StreamException { - checkNotNull(foreignIDTimePair, "No activity to update"); - return updateActivityByForeignID(foreignIDTimePair.getForeignID(), foreignIDTimePair.getTime(), set, unset); - } - - public CompletableFuture updateActivityByForeignID(ForeignIDTimePair foreignIDTimePair, Map set, String[] unset) throws StreamException { - checkNotNull(foreignIDTimePair, "No activity to update"); - return updateActivityByForeignID(foreignIDTimePair.getForeignID(), foreignIDTimePair.getTime(), set, unset); - } - - public CompletableFuture updateActivityByForeignID(String foreignID, Date timestamp, Map set, Iterable unset) throws StreamException { - return updateActivityByForeignID(foreignID, timestamp, set, Iterables.toArray(unset, String.class)); - } - - public CompletableFuture updateActivityByForeignID(ActivityUpdate update) throws StreamException { - return updateActivityByForeignID(update.getForeignID(), update.getTime(), update.getSet(), update.getUnset()); - } - - public CompletableFuture updateActivityByForeignID(String foreignID, Date timestamp, Map set, String[] unset) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.WRITE); - return stream.updateActivityByForeignID(token, foreignID, timestamp, set, unset); - } - - public CompletableFuture openGraph(URL url) throws StreamException { - final Token token = buildOpenGraphToken(secret); - return stream.openGraph(token, url); - } - - public CompletableFuture> updateActivitiesByID(Iterable updates) throws StreamException { - return updateActivitiesByID(Iterables.toArray(updates, ActivityUpdate.class)); - } - - public CompletableFuture> updateActivitiesByID(ActivityUpdate... updates) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.WRITE); - return stream.updateActivitiesByID(token, updates); - } - - public CompletableFuture> updateActivitiesByForeignID(Iterable updates) throws StreamException { - return updateActivitiesByForeignID(Iterables.toArray(updates, ActivityUpdate.class)); - } - - public CompletableFuture> updateActivitiesByForeignID(ActivityUpdate... updates) throws StreamException { - final Token token = buildActivityToken(secret, TokenAction.WRITE); - return stream.updateActivitiesByForeignID(token, updates); - } - - public static final class Builder { - private static final String DEFAULT_HOST = "stream-io-api.com"; - - private final String apiKey; - private final String secret; - private HTTPClient httpClient; - - private String scheme = "https"; - private String region = Region.US_EAST.toString(); - private String host = DEFAULT_HOST; - private int port = 443; - - public Builder(String apiKey, String secret) { - checkNotNull(apiKey, "API key can't be null"); - checkNotNull(secret, "Secret can't be null"); - checkArgument(!apiKey.isEmpty(), "API key can't be empty"); - checkArgument(!secret.isEmpty(), "Secret can't be empty"); - this.apiKey = apiKey; - this.secret = secret; - } - - public Builder httpClient(HTTPClient httpClient) { - checkNotNull(httpClient, "HTTP client can't be null"); - this.httpClient = httpClient; - return this; - } - - public Builder scheme(String scheme) { - checkNotNull(scheme, "Scheme can't be null"); - checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); - this.scheme = scheme; - return this; - } - - public Builder host(String host) { - checkNotNull(host, "Host can't be null"); - checkArgument(!host.isEmpty(), "Host can't be empty"); - this.host = host; - return this; - } - - public Builder port(int port) { - checkArgument(port > 0, "Port has to be a non-zero positive number"); - this.port = port; - return this; - } - - public Builder region(Region region) { - checkNotNull(region, "Region can't be null"); - this.region = region.toString(); - return this; - } - - public Builder region(String region) { - checkNotNull(region, "Region can't be null"); - checkArgument(!region.isEmpty(), "Region can't be empty"); - this.region = region; - return this; - } - - private String buildHost() { - final StringBuilder sb = new StringBuilder(); - if (host.equals(DEFAULT_HOST)) { - sb.append(region).append("."); - } - sb.append(host); - return sb.toString(); - } - - public Client build() throws MalformedURLException { - if (httpClient == null) { - httpClient = new OKHTTPClientAdapter(); - } - return new Client(apiKey, secret, new URL(scheme, buildHost(), port, ""), httpClient); - } - } - - public T getHTTPClientImplementation() { - return stream.getHTTPClientImplementation(); - } - - public Token frontendToken(String userID) { - return buildFrontendToken(secret, userID); - } - - public Token frontendToken(String userID, Date expiresAt) { - return buildFrontendToken(secret, userID, expiresAt); - } - - public FlatFeed flatFeed(FeedID id) { - return new FlatFeed(this, id); - } - - public FlatFeed flatFeed(String slug, String userID) { - return flatFeed(new FeedID(slug, userID)); - } - - public AggregatedFeed aggregatedFeed(FeedID id) { - return new AggregatedFeed(this, id); - } - - public AggregatedFeed aggregatedFeed(String slug, String userID) { - return aggregatedFeed(new FeedID(slug, userID)); - } - - public NotificationFeed notificationFeed(FeedID id) { - return new NotificationFeed(this, id); - } - - public NotificationFeed notificationFeed(String slug, String userID) { - return notificationFeed(new FeedID(slug, userID)); - } - - public User user(String userID) { - return new User(this, userID); - } - - public BatchClient batch() { - return new BatchClient(secret, stream.batch()); - } - - public CollectionsClient collections() { - return new CollectionsClient(secret, stream.collections()); - } - - public PersonalizationClient personalization() { - return new PersonalizationClient(secret, stream.personalization()); - } + private HTTPClient httpClient; - public AnalyticsClient analytics() { - return new AnalyticsClient(secret, stream.analytics()); - } - - public ReactionsClient reactions() { - return new ReactionsClient(secret, stream.reactions()); - } - - public FileStorageClient files() { - return new FileStorageClient(secret, stream.files()); - } - - public ImageStorageClient images() { - return new ImageStorageClient(secret, stream.images()); - } - - CompletableFuture getActivities(FeedID feed, RequestOption... options) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.READ); - return stream.getActivities(token, feed, options); - } - - CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.READ); - return stream.getEnrichedActivities(token, feed, options); - } - - CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.WRITE); - return stream.addActivity(token, feed, activity); - } - - CompletableFuture addActivities(FeedID feed, Activity... activities) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.WRITE); - return stream.addActivities(token, feed, activities); - } - - CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.DELETE); - return stream.removeActivityByID(token, feed, id); - } - - CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) throws StreamException { - final Token token = buildFeedToken(secret, feed, TokenAction.DELETE); - return stream.removeActivityByForeignID(token, feed, foreignID); - } - - CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) throws StreamException { - final Token token = buildFollowToken(secret, source, TokenAction.WRITE); - final Token targetToken = buildFeedToken(secret, target, TokenAction.READ); - return stream.follow(token, targetToken, source, target, activityCopyLimit); - } - - CompletableFuture getFollowers(FeedID feed, RequestOption... options) throws StreamException { - final Token token = buildFollowToken(secret, feed, TokenAction.READ); - return stream.getFollowers(token, feed, options); - } + private String scheme = "https"; + private String region = Region.US_EAST.toString(); + private String host = DEFAULT_HOST; + private int port = 443; - CompletableFuture getFollowed(FeedID feed, RequestOption... options) throws StreamException { - final Token token = buildFollowToken(secret, feed, TokenAction.READ); - return stream.getFollowed(token, feed, options); + public Builder(String apiKey, String secret) { + checkNotNull(apiKey, "API key can't be null"); + checkNotNull(secret, "Secret can't be null"); + checkArgument(!apiKey.isEmpty(), "API key can't be empty"); + checkArgument(!secret.isEmpty(), "Secret can't be empty"); + this.apiKey = apiKey; + this.secret = secret; } - CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) throws StreamException { - final Token token = buildFollowToken(secret, source, TokenAction.DELETE); - return stream.unfollow(token, source, target, options); + public Builder httpClient(HTTPClient httpClient) { + checkNotNull(httpClient, "HTTP client can't be null"); + this.httpClient = httpClient; + return this; } - CompletableFuture updateActivityToTargets(FeedID feed, Activity activity, FeedID[] add, FeedID[] remove, FeedID[] newTargets) throws StreamException { - final Token token = buildToTargetUpdateToken(secret, feed, TokenAction.WRITE); - return stream.updateActivityToTargets(token, feed, activity, add, remove, newTargets); + public Builder scheme(String scheme) { + checkNotNull(scheme, "Scheme can't be null"); + checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); + this.scheme = scheme; + return this; } - CompletableFuture getUser(String id) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.READ); - return stream.getUser(token, id, false); + public Builder host(String host) { + checkNotNull(host, "Host can't be null"); + checkArgument(!host.isEmpty(), "Host can't be empty"); + this.host = host; + return this; } - CompletableFuture deleteUser(String id) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.DELETE); - return stream.deleteUser(token, id); + public Builder port(int port) { + checkArgument(port > 0, "Port has to be a non-zero positive number"); + this.port = port; + return this; } - CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.WRITE); - return stream.createUser(token, id, data, true); + public Builder region(Region region) { + checkNotNull(region, "Region can't be null"); + this.region = region.toString(); + return this; } - CompletableFuture createUser(String id, Data data) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.WRITE); - return stream.createUser(token, id, data, false); + public Builder region(String region) { + checkNotNull(region, "Region can't be null"); + checkArgument(!region.isEmpty(), "Region can't be empty"); + this.region = region; + return this; } - CompletableFuture updateUser(String id, Data data) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.WRITE); - return stream.updateUser(token, id, data); + private String buildHost() { + final StringBuilder sb = new StringBuilder(); + if (host.equals(DEFAULT_HOST)) { + sb.append(region).append("."); + } + sb.append(host); + return sb.toString(); } - CompletableFuture userProfile(String id) throws StreamException { - final Token token = buildUsersToken(secret, TokenAction.READ); - return stream.getUser(token, id, true); + public Client build() throws MalformedURLException { + if (httpClient == null) { + httpClient = new OKHTTPClientAdapter(); + } + return new Client(apiKey, secret, new URL(scheme, buildHost(), port, ""), httpClient); } + } + + public T getHTTPClientImplementation() { + return stream.getHTTPClientImplementation(); + } + + public Token frontendToken(String userID) { + return buildFrontendToken(secret, userID); + } + + public Token frontendToken(String userID, Date expiresAt) { + return buildFrontendToken(secret, userID, expiresAt); + } + + public FlatFeed flatFeed(FeedID id) { + return new FlatFeed(this, id); + } + + public FlatFeed flatFeed(String slug, String userID) { + return flatFeed(new FeedID(slug, userID)); + } + + public AggregatedFeed aggregatedFeed(FeedID id) { + return new AggregatedFeed(this, id); + } + + public AggregatedFeed aggregatedFeed(String slug, String userID) { + return aggregatedFeed(new FeedID(slug, userID)); + } + + public NotificationFeed notificationFeed(FeedID id) { + return new NotificationFeed(this, id); + } + + public NotificationFeed notificationFeed(String slug, String userID) { + return notificationFeed(new FeedID(slug, userID)); + } + + public User user(String userID) { + return new User(this, userID); + } + + public BatchClient batch() { + return new BatchClient(secret, stream.batch()); + } + + public CollectionsClient collections() { + return new CollectionsClient(secret, stream.collections()); + } + + public PersonalizationClient personalization() { + return new PersonalizationClient(secret, stream.personalization()); + } + + public AnalyticsClient analytics() { + return new AnalyticsClient(secret, stream.analytics()); + } + + public ReactionsClient reactions() { + return new ReactionsClient(secret, stream.reactions()); + } + + public FileStorageClient files() { + return new FileStorageClient(secret, stream.files()); + } + + public ImageStorageClient images() { + return new ImageStorageClient(secret, stream.images()); + } + + CompletableFuture getActivities(FeedID feed, RequestOption... options) + throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.READ); + return stream.getActivities(token, feed, options); + } + + CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) + throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.READ); + return stream.getEnrichedActivities(token, feed, options); + } + + CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.WRITE); + return stream.addActivity(token, feed, activity); + } + + CompletableFuture addActivities(FeedID feed, Activity... activities) + throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.WRITE); + return stream.addActivities(token, feed, activities); + } + + CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.DELETE); + return stream.removeActivityByID(token, feed, id); + } + + CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) + throws StreamException { + final Token token = buildFeedToken(secret, feed, TokenAction.DELETE); + return stream.removeActivityByForeignID(token, feed, foreignID); + } + + CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) + throws StreamException { + final Token token = buildFollowToken(secret, source, TokenAction.WRITE); + final Token targetToken = buildFeedToken(secret, target, TokenAction.READ); + return stream.follow(token, targetToken, source, target, activityCopyLimit); + } + + CompletableFuture getFollowers(FeedID feed, RequestOption... options) + throws StreamException { + final Token token = buildFollowToken(secret, feed, TokenAction.READ); + return stream.getFollowers(token, feed, options); + } + + CompletableFuture getFollowed(FeedID feed, RequestOption... options) + throws StreamException { + final Token token = buildFollowToken(secret, feed, TokenAction.READ); + return stream.getFollowed(token, feed, options); + } + + CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) + throws StreamException { + final Token token = buildFollowToken(secret, source, TokenAction.DELETE); + return stream.unfollow(token, source, target, options); + } + + CompletableFuture updateActivityToTargets( + FeedID feed, Activity activity, FeedID[] add, FeedID[] remove, FeedID[] newTargets) + throws StreamException { + final Token token = buildToTargetUpdateToken(secret, feed, TokenAction.WRITE); + return stream.updateActivityToTargets(token, feed, activity, add, remove, newTargets); + } + + CompletableFuture getUser(String id) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.READ); + return stream.getUser(token, id, false); + } + + CompletableFuture deleteUser(String id) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.DELETE); + return stream.deleteUser(token, id); + } + + CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.WRITE); + return stream.createUser(token, id, data, true); + } + + CompletableFuture createUser(String id, Data data) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.WRITE); + return stream.createUser(token, id, data, false); + } + + CompletableFuture updateUser(String id, Data data) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.WRITE); + return stream.updateUser(token, id, data); + } + + CompletableFuture userProfile(String id) throws StreamException { + final Token token = buildUsersToken(secret, TokenAction.READ); + return stream.getUser(token, id, true); + } } diff --git a/src/main/java/io/getstream/client/CollectionsClient.java b/src/main/java/io/getstream/client/CollectionsClient.java index 4b3c267a..39f2bee4 100644 --- a/src/main/java/io/getstream/client/CollectionsClient.java +++ b/src/main/java/io/getstream/client/CollectionsClient.java @@ -1,5 +1,8 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildCollectionsToken; +import static io.getstream.core.utils.Serialization.convert; + import com.google.common.collect.Iterables; import io.getstream.core.StreamCollections; import io.getstream.core.exceptions.StreamException; @@ -7,124 +10,142 @@ import io.getstream.core.models.CollectionData; import io.getstream.core.utils.Auth.TokenAction; import io.getstream.core.utils.Streams; +import java.util.List; import java8.util.J8Arrays; import java8.util.concurrent.CompletableFuture; import java8.util.stream.Collectors; import java8.util.stream.StreamSupport; -import java.util.List; - -import static io.getstream.core.utils.Auth.buildCollectionsToken; -import static io.getstream.core.utils.Serialization.convert; - public final class CollectionsClient { - private final String secret; - private final StreamCollections collections; - - CollectionsClient(String secret, StreamCollections collections) { - this.secret = secret; - this.collections = collections; - } - - public CompletableFuture addCustom(String collection, T item) throws StreamException { - return addCustom(null, collection, item); - } - - public CompletableFuture addCustom(String userID, String collection, T item) throws StreamException { - return add(userID, collection, convert(item, CollectionData.class)) - .thenApply(data -> convert(data, (Class) item.getClass())); - } - - public CompletableFuture add(String collection, CollectionData item) throws StreamException { - return add(null, collection, item); - } - - public CompletableFuture add(String userID, String collection, CollectionData item) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.WRITE); - return collections.add(token, userID, collection, item); - } - - public CompletableFuture updateCustom(String collection, T item) throws StreamException { - return updateCustom(null, collection, item); - } - - public CompletableFuture updateCustom(String userID, String collection, T item) throws StreamException { - return update(userID, collection, convert(item, CollectionData.class)) - .thenApply(data -> convert(data, (Class) item.getClass())); - } - - public CompletableFuture update(String collection, CollectionData item) throws StreamException { - return update(null, collection, item); - } - - public CompletableFuture update(String userID, String collection, CollectionData item) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.WRITE); - return collections.update(token, userID, collection, item); - } - - public CompletableFuture upsertCustom(String collection, Iterable items) throws StreamException { - final CollectionData[] custom = Streams.stream(items) - .map(item -> CollectionData.buildFrom(item)) - .toArray(CollectionData[]::new); - return upsert(collection, custom); - } - - public CompletableFuture upsertCustom(String collection, T... items) throws StreamException { - final CollectionData[] custom = J8Arrays.stream(items) - .map(item -> CollectionData.buildFrom(item)) - .toArray(CollectionData[]::new); - return upsert(collection, custom); - } - - public CompletableFuture upsert(String collection, Iterable items) throws StreamException { - return upsert(collection, Iterables.toArray(items, CollectionData.class)); - } - - public CompletableFuture upsert(String collection, CollectionData... items) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.WRITE); - return collections.upsert(token, collection, items); - } - - public CompletableFuture getCustom(Class type, String collection, String id) throws StreamException { - return get(collection, id).thenApply(data -> convert(data, type)); - } - - public CompletableFuture get(String collection, String id) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.READ); - return collections.get(token, collection, id); - } - - public CompletableFuture> selectCustom(Class type, String collection, Iterable ids) throws StreamException { - return selectCustom(type, collection, Iterables.toArray(ids, String.class)); - } - - public CompletableFuture> selectCustom(Class type, String collection, String... ids) throws StreamException { - return select(collection, ids) - .thenApply(data -> StreamSupport.stream(data) - .map(item -> convert(item, type)) - .collect(Collectors.toList())); - } - - public CompletableFuture> select(String collection, Iterable ids) throws StreamException { - return select(collection, Iterables.toArray(ids, String.class)); - } - - public CompletableFuture> select(String collection, String... ids) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.READ); - return collections.select(token, collection, ids); - } - - public CompletableFuture delete(String collection, String id) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.DELETE); - return collections.delete(token, collection, id); - } - - public CompletableFuture deleteMany(String collection, Iterable ids) throws StreamException { - return deleteMany(collection, Iterables.toArray(ids, String.class)); - } - - public CompletableFuture deleteMany(String collection, String... ids) throws StreamException { - final Token token = buildCollectionsToken(secret, TokenAction.DELETE); - return collections.deleteMany(token, collection, ids); - } + private final String secret; + private final StreamCollections collections; + + CollectionsClient(String secret, StreamCollections collections) { + this.secret = secret; + this.collections = collections; + } + + public CompletableFuture addCustom(String collection, T item) throws StreamException { + return addCustom(null, collection, item); + } + + public CompletableFuture addCustom(String userID, String collection, T item) + throws StreamException { + return add(userID, collection, convert(item, CollectionData.class)) + .thenApply(data -> convert(data, (Class) item.getClass())); + } + + public CompletableFuture add(String collection, CollectionData item) + throws StreamException { + return add(null, collection, item); + } + + public CompletableFuture add( + String userID, String collection, CollectionData item) throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.WRITE); + return collections.add(token, userID, collection, item); + } + + public CompletableFuture updateCustom(String collection, T item) throws StreamException { + return updateCustom(null, collection, item); + } + + public CompletableFuture updateCustom(String userID, String collection, T item) + throws StreamException { + return update(userID, collection, convert(item, CollectionData.class)) + .thenApply(data -> convert(data, (Class) item.getClass())); + } + + public CompletableFuture update(String collection, CollectionData item) + throws StreamException { + return update(null, collection, item); + } + + public CompletableFuture update( + String userID, String collection, CollectionData item) throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.WRITE); + return collections.update(token, userID, collection, item); + } + + public CompletableFuture upsertCustom(String collection, Iterable items) + throws StreamException { + final CollectionData[] custom = + Streams.stream(items) + .map(item -> CollectionData.buildFrom(item)) + .toArray(CollectionData[]::new); + return upsert(collection, custom); + } + + public CompletableFuture upsertCustom(String collection, T... items) + throws StreamException { + final CollectionData[] custom = + J8Arrays.stream(items) + .map(item -> CollectionData.buildFrom(item)) + .toArray(CollectionData[]::new); + return upsert(collection, custom); + } + + public CompletableFuture upsert(String collection, Iterable items) + throws StreamException { + return upsert(collection, Iterables.toArray(items, CollectionData.class)); + } + + public CompletableFuture upsert(String collection, CollectionData... items) + throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.WRITE); + return collections.upsert(token, collection, items); + } + + public CompletableFuture getCustom(Class type, String collection, String id) + throws StreamException { + return get(collection, id).thenApply(data -> convert(data, type)); + } + + public CompletableFuture get(String collection, String id) + throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.READ); + return collections.get(token, collection, id); + } + + public CompletableFuture> selectCustom( + Class type, String collection, Iterable ids) throws StreamException { + return selectCustom(type, collection, Iterables.toArray(ids, String.class)); + } + + public CompletableFuture> selectCustom( + Class type, String collection, String... ids) throws StreamException { + return select(collection, ids) + .thenApply( + data -> + StreamSupport.stream(data) + .map(item -> convert(item, type)) + .collect(Collectors.toList())); + } + + public CompletableFuture> select(String collection, Iterable ids) + throws StreamException { + return select(collection, Iterables.toArray(ids, String.class)); + } + + public CompletableFuture> select(String collection, String... ids) + throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.READ); + return collections.select(token, collection, ids); + } + + public CompletableFuture delete(String collection, String id) throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.DELETE); + return collections.delete(token, collection, id); + } + + public CompletableFuture deleteMany(String collection, Iterable ids) + throws StreamException { + return deleteMany(collection, Iterables.toArray(ids, String.class)); + } + + public CompletableFuture deleteMany(String collection, String... ids) + throws StreamException { + final Token token = buildCollectionsToken(secret, TokenAction.DELETE); + return collections.deleteMany(token, collection, ids); + } } diff --git a/src/main/java/io/getstream/client/Feed.java b/src/main/java/io/getstream/client/Feed.java index 7ec622e8..8e5dd238 100644 --- a/src/main/java/io/getstream/client/Feed.java +++ b/src/main/java/io/getstream/client/Feed.java @@ -1,5 +1,9 @@ package io.getstream.client; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.*; + import com.google.common.collect.Iterables; import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; @@ -11,301 +15,357 @@ import io.getstream.core.options.RequestOption; import io.getstream.core.utils.DefaultOptions; import io.getstream.core.utils.Streams; -import java8.util.J8Arrays; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.*; +import java8.util.J8Arrays; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class Feed { - private final Client client; - private final FeedID id; - - Feed(Client client, FeedID id) { - checkNotNull(client, "Can't create feed w/o a client"); - checkNotNull(id, "Can't create feed w/o an ID"); - - this.client = client; - this.id = id; - } - - protected final Client getClient() { - return client; - } - - public final FeedID getID() { - return id; - } - - public final String getSlug() { - return id.getSlug(); - } - - public final String getUserID() { - return id.getUserID(); - } - - public final CompletableFuture addActivity(Activity activity) throws StreamException { - return getClient() - .addActivity(id, activity) - .thenApply(response -> { - try { - return deserialize(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture addCustomActivity(T activity) throws StreamException { - return getClient() - .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) - .thenApply(response -> { - try { - return deserialize(response, (Class) activity.getClass()); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Iterable activities) throws StreamException { - return addActivities(Iterables.toArray(activities, Activity.class)); - } - - public final CompletableFuture> addCustomActivities(Iterable activities) throws StreamException { - final Activity[] custom = Streams.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply(response -> { - try { - Class element = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Activity... activities) throws StreamException { - return getClient() - .addActivities(id, activities) - .thenApply(response -> { - try { - return deserializeContainer(response, "activities", Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addCustomActivities(T... activities) throws StreamException { - final Activity[] custom = J8Arrays.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply(response -> { - try { - Class element = (Class) activities.getClass().getComponentType(); - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByID(String id) throws StreamException { - return client - .removeActivityByID(this.id, id) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByForeignID(String foreignID) throws StreamException { - return client - .removeActivityByForeignID(id, foreignID) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture follow(FlatFeed feed) throws StreamException { - return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); - } - - public final CompletableFuture follow(FlatFeed feed, int activityCopyLimit) throws StreamException { - checkArgument(activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, String.format("Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); - - return client - .follow(id, feed.getID(), activityCopyLimit) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowers(Iterable feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(FeedID... feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers(Limit limit, Iterable feedIDs) throws StreamException { - return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) throws StreamException { - return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers(Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Offset offset, FeedID... feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowers(Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds) - .map(id -> id.toString()) - .toArray(String[]::new); - final RequestOption[] options = feedIDs.length == 0 - ? new RequestOption[]{limit, offset} - : new RequestOption[]{limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs))}; - return client - .getFollowers(id, options) - .thenApply(response -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowed(Iterable feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(FeedID... feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed(Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowed(Limit limit, Iterable feedIDs) throws StreamException { - return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) throws StreamException { - return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed(Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds) - .map(id -> id.toString()) - .toArray(String[]::new); - final RequestOption[] options = feedIDs.length == 0 - ? new RequestOption[]{limit, offset} - : new RequestOption[]{limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs))}; - return client - .getFollowed(id, options) - .thenApply(response -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture unfollow(FlatFeed feed) throws StreamException { - return unfollow(feed, io.getstream.core.KeepHistory.NO); - } - - public final CompletableFuture unfollow(FlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { - return client - .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture updateActivityToTargets(Activity activity, Iterable add, Iterable remove) throws StreamException { - return updateActivityToTargets(activity, Iterables.toArray(add, FeedID.class), Iterables.toArray(remove, FeedID.class)); - } - - public final CompletableFuture updateActivityToTargets(Activity activity, FeedID[] add, FeedID[] remove) throws StreamException { - return client - .updateActivityToTargets(id, activity, add, remove, new FeedID[0]) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture replaceActivityToTargets(Activity activity, Iterable newTargets) throws StreamException { - return replaceActivityToTargets(activity, Iterables.toArray(newTargets, FeedID.class)); - } - - public final CompletableFuture replaceActivityToTargets(Activity activity, FeedID... newTargets) throws StreamException { - return client - .updateActivityToTargets(id, activity, new FeedID[0], new FeedID[0], newTargets) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + private final Client client; + private final FeedID id; + + Feed(Client client, FeedID id) { + checkNotNull(client, "Can't create feed w/o a client"); + checkNotNull(id, "Can't create feed w/o an ID"); + + this.client = client; + this.id = id; + } + + protected final Client getClient() { + return client; + } + + public final FeedID getID() { + return id; + } + + public final String getSlug() { + return id.getSlug(); + } + + public final String getUserID() { + return id.getUserID(); + } + + public final CompletableFuture addActivity(Activity activity) throws StreamException { + return getClient() + .addActivity(id, activity) + .thenApply( + response -> { + try { + return deserialize(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture addCustomActivity(T activity) throws StreamException { + return getClient() + .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) + .thenApply( + response -> { + try { + return deserialize(response, (Class) activity.getClass()); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Iterable activities) + throws StreamException { + return addActivities(Iterables.toArray(activities, Activity.class)); + } + + public final CompletableFuture> addCustomActivities(Iterable activities) + throws StreamException { + final Activity[] custom = + Streams.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + response -> { + try { + Class element = + (Class) + ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Activity... activities) + throws StreamException { + return getClient() + .addActivities(id, activities) + .thenApply( + response -> { + try { + return deserializeContainer(response, "activities", Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addCustomActivities(T... activities) + throws StreamException { + final Activity[] custom = + J8Arrays.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + response -> { + try { + Class element = (Class) activities.getClass().getComponentType(); + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByID(String id) throws StreamException { + return client + .removeActivityByID(this.id, id) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByForeignID(String foreignID) + throws StreamException { + return client + .removeActivityByForeignID(id, foreignID) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture follow(FlatFeed feed) throws StreamException { + return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); + } + + public final CompletableFuture follow(FlatFeed feed, int activityCopyLimit) + throws StreamException { + checkArgument( + activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, + String.format( + "Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); + + return client + .follow(id, feed.getID(), activityCopyLimit) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowers(Iterable feedIDs) + throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(FeedID... feedIDs) + throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowers( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Offset offset, FeedID... feedIDs) throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[] {limit, offset} + : new RequestOption[] { + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowers(id, options) + .thenApply( + response -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowed(Iterable feedIDs) + throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowed( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[] {limit, offset} + : new RequestOption[] { + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowed(id, options) + .thenApply( + response -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture unfollow(FlatFeed feed) throws StreamException { + return unfollow(feed, io.getstream.core.KeepHistory.NO); + } + + public final CompletableFuture unfollow( + FlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { + return client + .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture updateActivityToTargets( + Activity activity, Iterable add, Iterable remove) throws StreamException { + return updateActivityToTargets( + activity, Iterables.toArray(add, FeedID.class), Iterables.toArray(remove, FeedID.class)); + } + + public final CompletableFuture updateActivityToTargets( + Activity activity, FeedID[] add, FeedID[] remove) throws StreamException { + return client + .updateActivityToTargets(id, activity, add, remove, new FeedID[0]) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture replaceActivityToTargets( + Activity activity, Iterable newTargets) throws StreamException { + return replaceActivityToTargets(activity, Iterables.toArray(newTargets, FeedID.class)); + } + + public final CompletableFuture replaceActivityToTargets( + Activity activity, FeedID... newTargets) throws StreamException { + return client + .updateActivityToTargets(id, activity, new FeedID[0], new FeedID[0], newTargets) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/client/FileStorageClient.java b/src/main/java/io/getstream/client/FileStorageClient.java index 1c69a9ec..d8acb38e 100644 --- a/src/main/java/io/getstream/client/FileStorageClient.java +++ b/src/main/java/io/getstream/client/FileStorageClient.java @@ -1,37 +1,36 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildFilesToken; + import io.getstream.core.StreamFiles; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; import io.getstream.core.utils.Auth.TokenAction; -import java8.util.concurrent.CompletableFuture; - import java.io.File; import java.net.URL; - -import static io.getstream.core.utils.Auth.buildFilesToken; +import java8.util.concurrent.CompletableFuture; public final class FileStorageClient { - private final String secret; - private final StreamFiles files; - - FileStorageClient(String secret, StreamFiles files) { - this.secret = secret; - this.files = files; - } - - public CompletableFuture upload(String fileName, byte[] content) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.WRITE); - return files.upload(token, fileName, content); - } - - public CompletableFuture upload(File content) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.WRITE); - return files.upload(token, content); - } - - public CompletableFuture delete(URL url) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.DELETE); - return files.delete(token, url); - } + private final String secret; + private final StreamFiles files; + + FileStorageClient(String secret, StreamFiles files) { + this.secret = secret; + this.files = files; + } + + public CompletableFuture upload(String fileName, byte[] content) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.WRITE); + return files.upload(token, fileName, content); + } + + public CompletableFuture upload(File content) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.WRITE); + return files.upload(token, content); + } + + public CompletableFuture delete(URL url) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.DELETE); + return files.delete(token, url); + } } diff --git a/src/main/java/io/getstream/client/FlatFeed.java b/src/main/java/io/getstream/client/FlatFeed.java index 9b431717..122258d7 100644 --- a/src/main/java/io/getstream/client/FlatFeed.java +++ b/src/main/java/io/getstream/client/FlatFeed.java @@ -1,369 +1,660 @@ package io.getstream.client; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; import io.getstream.core.models.FeedID; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class FlatFeed extends Feed { - FlatFeed(Client client, FeedID id) { - super(client, id); - } - - public CompletableFuture> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Limit limit, String ranking) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Filter filter, String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Offset offset, String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - CompletableFuture> getActivities(Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, String ranking) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Offset offset, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Filter filter, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getEnrichedActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + FlatFeed(Client client, FeedID id) { + super(client, id); + } + + public CompletableFuture> getActivities() throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getActivities(Limit limit) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(String ranking) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getActivities(Filter filter) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Offset offset) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Limit limit, String ranking) + throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Filter filter, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Offset offset, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + CompletableFuture> getActivities( + Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getCustomActivities(Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getCustomActivities(Class type, Limit limit) + throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities(Class type, String ranking) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getCustomActivities(Class type, Filter filter) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities(Class type, Offset offset) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities(String ranking) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities(Filter filter) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities(Offset offset) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) + throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getEnrichedActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) + throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + CompletableFuture> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + EnrichmentFlags flags, + String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/client/ImageStorageClient.java b/src/main/java/io/getstream/client/ImageStorageClient.java index f3a438d5..08849b91 100644 --- a/src/main/java/io/getstream/client/ImageStorageClient.java +++ b/src/main/java/io/getstream/client/ImageStorageClient.java @@ -1,49 +1,48 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildFilesToken; + import io.getstream.core.StreamImages; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; import io.getstream.core.options.Crop; import io.getstream.core.options.Resize; import io.getstream.core.utils.Auth.TokenAction; -import java8.util.concurrent.CompletableFuture; - import java.io.File; import java.net.URL; - -import static io.getstream.core.utils.Auth.buildFilesToken; +import java8.util.concurrent.CompletableFuture; public final class ImageStorageClient { - private final String secret; - private final StreamImages images; - - ImageStorageClient(String secret, StreamImages images) { - this.secret = secret; - this.images = images; - } - - public CompletableFuture upload(String fileName, byte[] content) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.WRITE); - return images.upload(token, fileName, content); - } - - public CompletableFuture upload(File content) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.WRITE); - return images.upload(token, content); - } - - public CompletableFuture delete(URL url) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.DELETE); - return images.delete(token, url); - } - - public CompletableFuture process(URL url, Crop crop) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.READ); - return images.process(token, url, crop); - } - - public CompletableFuture process(URL url, Resize resize) throws StreamException { - final Token token = buildFilesToken(secret, TokenAction.READ); - return images.process(token, url, resize); - } + private final String secret; + private final StreamImages images; + + ImageStorageClient(String secret, StreamImages images) { + this.secret = secret; + this.images = images; + } + + public CompletableFuture upload(String fileName, byte[] content) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.WRITE); + return images.upload(token, fileName, content); + } + + public CompletableFuture upload(File content) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.WRITE); + return images.upload(token, content); + } + + public CompletableFuture delete(URL url) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.DELETE); + return images.delete(token, url); + } + + public CompletableFuture process(URL url, Crop crop) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.READ); + return images.process(token, url, crop); + } + + public CompletableFuture process(URL url, Resize resize) throws StreamException { + final Token token = buildFilesToken(secret, TokenAction.READ); + return images.process(token, url, resize); + } } diff --git a/src/main/java/io/getstream/client/NotificationFeed.java b/src/main/java/io/getstream/client/NotificationFeed.java index 89d52866..f5c7342f 100644 --- a/src/main/java/io/getstream/client/NotificationFeed.java +++ b/src/main/java/io/getstream/client/NotificationFeed.java @@ -1,5 +1,7 @@ package io.getstream.client; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; @@ -7,428 +9,775 @@ import io.getstream.core.models.NotificationGroup; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class NotificationFeed extends AggregatedFeed { - NotificationFeed(Client client, FeedID id) { - super(client, id); - } - - @Override - public CompletableFuture>> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + NotificationFeed(Client client, FeedID id) { + super(client, id); + } + + @Override + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(ActivityMarker marker) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getCustomActivities(Class type) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedActivities() + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer( + response, NotificationGroup.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/client/PersonalizationClient.java b/src/main/java/io/getstream/client/PersonalizationClient.java index 1639edac..536a4b5b 100644 --- a/src/main/java/io/getstream/client/PersonalizationClient.java +++ b/src/main/java/io/getstream/client/PersonalizationClient.java @@ -1,73 +1,83 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildPersonalizationToken; + import com.google.common.collect.ImmutableMap; import io.getstream.core.StreamPersonalization; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; import io.getstream.core.utils.Auth.TokenAction; -import java8.util.concurrent.CompletableFuture; - import java.util.Map; - -import static io.getstream.core.utils.Auth.buildPersonalizationToken; +import java8.util.concurrent.CompletableFuture; public final class PersonalizationClient { - private final String secret; - private final StreamPersonalization personalization; - - PersonalizationClient(String secret, StreamPersonalization personalization) { - this.secret = secret; - this.personalization = personalization; - } - - public CompletableFuture> get(String resource) throws StreamException { - return get(null, resource); - } - - public CompletableFuture> get(String resource, Map params) throws StreamException { - return get(null, resource, params); - } - - public CompletableFuture> get(String userID, String resource) throws StreamException { - return get(userID, resource, ImmutableMap.of()); - } - - public CompletableFuture> get(String userID, String resource, Map params) throws StreamException { - final Token token = buildPersonalizationToken(secret, userID, TokenAction.READ); - return personalization.get(token, userID, resource, params); - } - - public CompletableFuture post(String resource, Map payload) throws StreamException { - return post(null, resource, payload); - } - - public CompletableFuture post(String resource, Map params, Map payload) throws StreamException { - return post(null, resource, params, payload); - } - - public CompletableFuture post(String userID, String resource, Map payload) throws StreamException { - return post(userID, resource, ImmutableMap.of(), payload); - } - - public CompletableFuture post(String userID, String resource, Map params, Map payload) throws StreamException { - final Token token = buildPersonalizationToken(secret, userID, TokenAction.WRITE); - return personalization.post(token, userID, resource, params, payload); - } - - public CompletableFuture delete(String resource) throws StreamException { - return delete(null, resource); - } - - public CompletableFuture delete(String resource, Map params) throws StreamException { - return delete(null, resource, params); - } - - public CompletableFuture delete(String userID, String resource) throws StreamException { - return delete(userID, resource, ImmutableMap.of()); - } - - public CompletableFuture delete(String userID, String resource, Map params) throws StreamException { - final Token token = buildPersonalizationToken(secret, userID, TokenAction.DELETE); - return personalization.delete(token, userID, resource, params); - } + private final String secret; + private final StreamPersonalization personalization; + + PersonalizationClient(String secret, StreamPersonalization personalization) { + this.secret = secret; + this.personalization = personalization; + } + + public CompletableFuture> get(String resource) throws StreamException { + return get(null, resource); + } + + public CompletableFuture> get(String resource, Map params) + throws StreamException { + return get(null, resource, params); + } + + public CompletableFuture> get(String userID, String resource) + throws StreamException { + return get(userID, resource, ImmutableMap.of()); + } + + public CompletableFuture> get( + String userID, String resource, Map params) throws StreamException { + final Token token = buildPersonalizationToken(secret, userID, TokenAction.READ); + return personalization.get(token, userID, resource, params); + } + + public CompletableFuture post(String resource, Map payload) + throws StreamException { + return post(null, resource, payload); + } + + public CompletableFuture post( + String resource, Map params, Map payload) + throws StreamException { + return post(null, resource, params, payload); + } + + public CompletableFuture post(String userID, String resource, Map payload) + throws StreamException { + return post(userID, resource, ImmutableMap.of(), payload); + } + + public CompletableFuture post( + String userID, String resource, Map params, Map payload) + throws StreamException { + final Token token = buildPersonalizationToken(secret, userID, TokenAction.WRITE); + return personalization.post(token, userID, resource, params, payload); + } + + public CompletableFuture delete(String resource) throws StreamException { + return delete(null, resource); + } + + public CompletableFuture delete(String resource, Map params) + throws StreamException { + return delete(null, resource, params); + } + + public CompletableFuture delete(String userID, String resource) throws StreamException { + return delete(userID, resource, ImmutableMap.of()); + } + + public CompletableFuture delete(String userID, String resource, Map params) + throws StreamException { + final Token token = buildPersonalizationToken(secret, userID, TokenAction.DELETE); + return personalization.delete(token, userID, resource, params); + } } diff --git a/src/main/java/io/getstream/client/ReactionsClient.java b/src/main/java/io/getstream/client/ReactionsClient.java index e89e1896..f7020030 100644 --- a/src/main/java/io/getstream/client/ReactionsClient.java +++ b/src/main/java/io/getstream/client/ReactionsClient.java @@ -1,5 +1,9 @@ package io.getstream.client; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Auth.buildReactionsToken; + import com.google.common.collect.Iterables; import io.getstream.core.LookupKind; import io.getstream.core.StreamReactions; @@ -12,155 +16,184 @@ import io.getstream.core.options.Limit; import io.getstream.core.utils.Auth.TokenAction; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; - import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Auth.buildReactionsToken; +import java8.util.concurrent.CompletableFuture; public final class ReactionsClient { - private final String secret; - private final StreamReactions reactions; - - ReactionsClient(String secret, StreamReactions reactions) { - this.secret = secret; - this.reactions = reactions; - } - - public CompletableFuture get(String id) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.READ); - return reactions.get(token, id); - } - - public CompletableFuture> filter(LookupKind lookup, String id) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Limit limit) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter) throws StreamException { - return filter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, String kind) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { - return filter(lookup, id, filter, limit, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Limit limit, String kind) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter, Limit limit, String kind) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.READ); - return reactions.filter(token, lookup, id, filter, limit, kind); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id) throws StreamException { - return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, Limit limit) throws StreamException { - return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, Filter filter) throws StreamException { - return paginatedFilter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, String kind) throws StreamException { - return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { - return paginatedFilter(lookup, id, filter, limit, ""); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, Limit limit, String kind) throws StreamException { - return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); - } - - public CompletableFuture> paginatedFilter(LookupKind lookup, String id, Filter filter, Limit limit, String kind) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.READ); - return reactions.paginatedFilter(token, lookup, id, filter, limit, kind); - } - - public CompletableFuture> paginatedFilter(String next) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.READ); - return reactions.paginatedFilter(token, next); - } - - public CompletableFuture add(String userID, String kind, String activityID, Iterable targetFeeds) throws StreamException { - return add(userID, kind, activityID, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture add(String userID, String kind, String activityID, FeedID... targetFeeds) throws StreamException { - checkNotNull(kind, "Reaction kind can't be null"); - checkArgument(!kind.isEmpty(), "Reaction kind can't be empty"); - checkNotNull(activityID, "Reaction activity id can't be null"); - checkArgument(!activityID.isEmpty(), "Reaction activity id can't be empty"); - - return add(userID, Reaction.builder().activityID(activityID).kind(kind).build(), targetFeeds); - } - - public CompletableFuture add(String userID, Reaction reaction, Iterable targetFeeds) throws StreamException { - return add(userID, reaction, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture add(String userID, Reaction reaction, FeedID... targetFeeds) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.WRITE); - return reactions.add(token, userID, reaction, targetFeeds); - } - - public CompletableFuture addChild(String userID, String kind, String parentID, Iterable targetFeeds) throws StreamException { - Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String kind, String parentID, FeedID... targetFeeds) throws StreamException { - Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String parentID, Reaction reaction, Iterable targetFeeds) throws StreamException { - Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String parentID, Reaction reaction, FeedID... targetFeeds) throws StreamException { - Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture update(String id, Iterable targetFeeds) throws StreamException { - return update(id, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture update(String id, FeedID... targetFeeds) throws StreamException { - checkNotNull(id, "Reaction id can't be null"); - checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - - return update(Reaction.builder().id(id).build(), targetFeeds); - } - - public CompletableFuture update(Reaction reaction, Iterable targetFeeds) throws StreamException { - return update(reaction, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.WRITE); - return reactions.update(token, reaction, targetFeeds); - } - - public CompletableFuture delete(String id) throws StreamException { - final Token token = buildReactionsToken(secret, TokenAction.DELETE); - return reactions.delete(token, id); - } + private final String secret; + private final StreamReactions reactions; + + ReactionsClient(String secret, StreamReactions reactions) { + this.secret = secret; + this.reactions = reactions; + } + + public CompletableFuture get(String id) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.READ); + return reactions.get(token, id); + } + + public CompletableFuture> filter(LookupKind lookup, String id) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, Limit limit) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, Filter filter) + throws StreamException { + return filter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, String kind) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { + return filter(lookup, id, filter, limit, ""); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Limit limit, String kind) throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Filter filter, Limit limit, String kind) + throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.READ); + return reactions.filter(token, lookup, id, filter, limit, kind); + } + + public CompletableFuture> paginatedFilter(LookupKind lookup, String id) + throws StreamException { + return paginatedFilter( + lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, Limit limit) throws StreamException { + return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, Filter filter) throws StreamException { + return paginatedFilter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, String kind) throws StreamException { + return paginatedFilter( + lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { + return paginatedFilter(lookup, id, filter, limit, ""); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, Limit limit, String kind) throws StreamException { + return paginatedFilter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); + } + + public CompletableFuture> paginatedFilter( + LookupKind lookup, String id, Filter filter, Limit limit, String kind) + throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.READ); + return reactions.paginatedFilter(token, lookup, id, filter, limit, kind); + } + + public CompletableFuture> paginatedFilter(String next) + throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.READ); + return reactions.paginatedFilter(token, next); + } + + public CompletableFuture add( + String userID, String kind, String activityID, Iterable targetFeeds) + throws StreamException { + return add(userID, kind, activityID, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture add( + String userID, String kind, String activityID, FeedID... targetFeeds) throws StreamException { + checkNotNull(kind, "Reaction kind can't be null"); + checkArgument(!kind.isEmpty(), "Reaction kind can't be empty"); + checkNotNull(activityID, "Reaction activity id can't be null"); + checkArgument(!activityID.isEmpty(), "Reaction activity id can't be empty"); + + return add(userID, Reaction.builder().activityID(activityID).kind(kind).build(), targetFeeds); + } + + public CompletableFuture add( + String userID, Reaction reaction, Iterable targetFeeds) throws StreamException { + return add(userID, reaction, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture add(String userID, Reaction reaction, FeedID... targetFeeds) + throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.WRITE); + return reactions.add(token, userID, reaction, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String kind, String parentID, Iterable targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String kind, String parentID, FeedID... targetFeeds) throws StreamException { + Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String parentID, Reaction reaction, Iterable targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String parentID, Reaction reaction, FeedID... targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture update(String id, Iterable targetFeeds) + throws StreamException { + return update(id, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture update(String id, FeedID... targetFeeds) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); + + return update(Reaction.builder().id(id).build(), targetFeeds); + } + + public CompletableFuture update(Reaction reaction, Iterable targetFeeds) + throws StreamException { + return update(reaction, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) + throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.WRITE); + return reactions.update(token, reaction, targetFeeds); + } + + public CompletableFuture delete(String id) throws StreamException { + final Token token = buildReactionsToken(secret, TokenAction.DELETE); + return reactions.delete(token, id); + } } diff --git a/src/main/java/io/getstream/client/User.java b/src/main/java/io/getstream/client/User.java index 855c7286..76b399dc 100644 --- a/src/main/java/io/getstream/client/User.java +++ b/src/main/java/io/getstream/client/User.java @@ -1,106 +1,117 @@ package io.getstream.client; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.deserialize; +import static io.getstream.core.utils.Serialization.deserializeError; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Data; import io.getstream.core.models.ProfileData; +import java.io.IOException; import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; -import java.io.IOException; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.deserialize; -import static io.getstream.core.utils.Serialization.deserializeError; - public final class User { - private final Client client; - private final String id; + private final Client client; + private final String id; - public User(Client client, String id) { - checkNotNull(client, "Client can't be null"); - checkNotNull(id, "User ID can't be null"); - checkArgument(!id.isEmpty(), "User ID can't be empty"); + public User(Client client, String id) { + checkNotNull(client, "Client can't be null"); + checkNotNull(id, "User ID can't be null"); + checkArgument(!id.isEmpty(), "User ID can't be empty"); - this.client = client; - this.id = id; - } + this.client = client; + this.id = id; + } - public String getID() { - return id; - } + public String getID() { + return id; + } - public CompletableFuture get() throws StreamException { - return client.getUser(id) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture get() throws StreamException { + return client + .getUser(id) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture delete() throws StreamException { - return client.deleteUser(id) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture delete() throws StreamException { + return client + .deleteUser(id) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture getOrCreate() throws StreamException { - return getOrCreate(new Data()); - } + public CompletableFuture getOrCreate() throws StreamException { + return getOrCreate(new Data()); + } - public CompletableFuture getOrCreate(Data data) throws StreamException { - return client.getOrCreateUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture getOrCreate(Data data) throws StreamException { + return client + .getOrCreateUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture create() throws StreamException { - return create(new Data()); - } + public CompletableFuture create() throws StreamException { + return create(new Data()); + } - public CompletableFuture create(Data data) throws StreamException { - return client.createUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture create(Data data) throws StreamException { + return client + .createUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture update(Data data) throws StreamException { - return client.updateUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture update(Data data) throws StreamException { + return client + .updateUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture profile() throws StreamException { - return client.userProfile(id) - .thenApply(response -> { - try { - return deserialize(response, ProfileData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture profile() throws StreamException { + return client + .userProfile(id) + .thenApply( + response -> { + try { + return deserialize(response, ProfileData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java b/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java index ac92b55b..85146ffb 100644 --- a/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java +++ b/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java @@ -1,5 +1,7 @@ package io.getstream.cloud; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; @@ -7,352 +9,698 @@ import io.getstream.core.models.Group; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class CloudAggregatedFeed extends CloudFeed { - CloudAggregatedFeed(CloudClient client, FeedID id) { - super(client, id); - } - - public CompletableFuture>> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudAggregatedFeed(CloudClient client, FeedID id) { + super(client, id); + } + + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getCustomActivities( + Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> + getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudAnalyticsClient.java b/src/main/java/io/getstream/cloud/CloudAnalyticsClient.java index c59cd88b..30392bd6 100644 --- a/src/main/java/io/getstream/cloud/CloudAnalyticsClient.java +++ b/src/main/java/io/getstream/cloud/CloudAnalyticsClient.java @@ -9,23 +9,24 @@ import java8.util.concurrent.CompletableFuture; public final class CloudAnalyticsClient { - private final Token token; - private final StreamAnalytics analytics; + private final Token token; + private final StreamAnalytics analytics; - CloudAnalyticsClient(Token token, StreamAnalytics analytics) { - this.token = token; - this.analytics = analytics; - } + CloudAnalyticsClient(Token token, StreamAnalytics analytics) { + this.token = token; + this.analytics = analytics; + } - public CompletableFuture trackEngagement(Iterable events) throws StreamException { - return trackEngagement(Iterables.toArray(events, Engagement.class)); - } + public CompletableFuture trackEngagement(Iterable events) + throws StreamException { + return trackEngagement(Iterables.toArray(events, Engagement.class)); + } - public CompletableFuture trackEngagement(Engagement... events) throws StreamException { - return analytics.trackEngagement(token, events); - } + public CompletableFuture trackEngagement(Engagement... events) throws StreamException { + return analytics.trackEngagement(token, events); + } - public CompletableFuture trackImpression(Impression event) throws StreamException { - return analytics.trackImpression(token, event); - } + public CompletableFuture trackImpression(Impression event) throws StreamException { + return analytics.trackImpression(token, event); + } } diff --git a/src/main/java/io/getstream/cloud/CloudClient.java b/src/main/java/io/getstream/cloud/CloudClient.java index 73cf61ac..a157869a 100644 --- a/src/main/java/io/getstream/cloud/CloudClient.java +++ b/src/main/java/io/getstream/cloud/CloudClient.java @@ -1,5 +1,8 @@ package io.getstream.cloud; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import io.getstream.core.Region; import io.getstream.core.Stream; import io.getstream.core.exceptions.StreamException; @@ -12,255 +15,260 @@ import io.getstream.core.models.FeedID; import io.getstream.core.models.OGData; import io.getstream.core.options.RequestOption; -import java8.util.concurrent.CompletableFuture; - import java.net.MalformedURLException; import java.net.URL; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import java8.util.concurrent.CompletableFuture; public final class CloudClient { - private final Token token; - private final String userID; - private final Stream stream; - - private CloudClient(String key, Token token, String userID, URL baseURL, HTTPClient httpClient) { - this.token = token; - this.userID = userID; - this.stream = new Stream(key, baseURL, httpClient); - } - - public static Builder builder(String apiKey, String token, String userID) { - return new Builder(apiKey, new Token(token), userID); - } - - public static Builder builder(String apiKey, Token token, String userID) { - return new Builder(apiKey, token, userID); - } - - public CompletableFuture openGraph(URL url) throws StreamException { - return stream.openGraph(token, url); - } - - public static final class Builder { - private static final String DEFAULT_HOST = "stream-io-api.com"; - - private final String apiKey; - private final Token token; - private final String userID; - private HTTPClient httpClient; - - private String scheme = "https"; - private String region = Region.US_EAST.toString(); - private String host = DEFAULT_HOST; - private int port = 443; - - public Builder(String apiKey, Token token, String userID) { - checkNotNull(apiKey, "API key can't be null"); - checkNotNull(token, "Token can't be null"); - checkNotNull(userID, "User ID can't be null"); - checkArgument(!apiKey.isEmpty(), "API key can't be empty"); - checkArgument(!userID.isEmpty(), "User ID can't be empty"); - this.apiKey = apiKey; - this.token = token; - this.userID = userID; - } - - public Builder httpClient(HTTPClient httpClient) { - checkNotNull(httpClient, "HTTP client can't be null"); - this.httpClient = httpClient; - return this; - } - - public Builder scheme(String scheme) { - checkNotNull(scheme, "Scheme can't be null"); - checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); - this.scheme = scheme; - return this; - } - - public Builder host(String host) { - checkNotNull(host, "Host can't be null"); - checkArgument(!host.isEmpty(), "Host can't be empty"); - this.host = host; - return this; - } - - public Builder port(int port) { - checkArgument(port > 0, "Port has to be a non-zero positive number"); - this.port = port; - return this; - } - - public Builder region(Region region) { - checkNotNull(region, "Region can't be null"); - this.region = region.toString(); - return this; - } - - public Builder region(String region) { - checkNotNull(region, "Region can't be null"); - checkArgument(!region.isEmpty(), "Region can't be empty"); - this.region = region; - return this; - } - - private String buildHost() { - final StringBuilder sb = new StringBuilder(); - if (host.equals(DEFAULT_HOST)) { - sb.append(region).append("."); - } - sb.append(host); - return sb.toString(); - } - - public CloudClient build() throws MalformedURLException { - if (httpClient == null) { - httpClient = new OKHTTPClientAdapter(); - } - return new CloudClient(apiKey, token, userID, new URL(scheme, buildHost(), port, ""), httpClient); - } - } - - public T getHTTPClientImplementation() { - return stream.getHTTPClientImplementation(); - } - - //TODO: add personalized feed versions - public CloudFlatFeed flatFeed(String slug) { - return flatFeed(slug, userID); - } - - public CloudFlatFeed flatFeed(String slug, CloudUser user) { - return flatFeed(slug, user.getID()); - } + private final Token token; + private final String userID; + private final Stream stream; - public CloudFlatFeed flatFeed(String slug, String userID) { - return flatFeed(new FeedID(slug, userID)); - } + private CloudClient(String key, Token token, String userID, URL baseURL, HTTPClient httpClient) { + this.token = token; + this.userID = userID; + this.stream = new Stream(key, baseURL, httpClient); + } - public CloudFlatFeed flatFeed(FeedID id) { - return new CloudFlatFeed(this, id); - } + public static Builder builder(String apiKey, String token, String userID) { + return new Builder(apiKey, new Token(token), userID); + } - public CloudAggregatedFeed aggregatedFeed(String slug) { - return aggregatedFeed(slug, userID); - } + public static Builder builder(String apiKey, Token token, String userID) { + return new Builder(apiKey, token, userID); + } - public CloudAggregatedFeed aggregatedFeed(String slug, CloudUser user) { - return aggregatedFeed(slug, user.getID()); - } + public CompletableFuture openGraph(URL url) throws StreamException { + return stream.openGraph(token, url); + } - public CloudAggregatedFeed aggregatedFeed(String slug, String userID) { - return aggregatedFeed(new FeedID(slug, userID)); - } + public static final class Builder { + private static final String DEFAULT_HOST = "stream-io-api.com"; - public CloudAggregatedFeed aggregatedFeed(FeedID id) { - return new CloudAggregatedFeed(this, id); - } - - public CloudNotificationFeed notificationFeed(String slug) { - return notificationFeed(slug, userID); - } - - public CloudNotificationFeed notificationFeed(String slug, CloudUser user) { - return notificationFeed(slug, user.getID()); - } - - public CloudNotificationFeed notificationFeed(String slug, String userID) { - return notificationFeed(new FeedID(slug, userID)); - } - - public CloudNotificationFeed notificationFeed(FeedID id) { - return new CloudNotificationFeed(this, id); - } - - public CloudUser user(String userID) { - return new CloudUser(this, userID); - } - - public CloudAnalyticsClient analytics() { - return new CloudAnalyticsClient(token, stream.analytics()); - } - - public CloudCollectionsClient collections() { - return new CloudCollectionsClient(token, userID, stream.collections()); - } - - public CloudReactionsClient reactions() { - return new CloudReactionsClient(token, userID, stream.reactions()); - } - - public CloudFileStorageClient files() { - return new CloudFileStorageClient(token, stream.files()); - } - - public CloudImageStorageClient images() { - return new CloudImageStorageClient(token, stream.images()); - } - - CompletableFuture getActivities(FeedID feed, RequestOption... options) throws StreamException { - return stream.getActivities(token, feed, options); - } + private final String apiKey; + private final Token token; + private final String userID; + private HTTPClient httpClient; - CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) throws StreamException { - return stream.getEnrichedActivities(token, feed, options); - } + private String scheme = "https"; + private String region = Region.US_EAST.toString(); + private String host = DEFAULT_HOST; + private int port = 443; - CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { - return stream.addActivity(token, feed, activity); + public Builder(String apiKey, Token token, String userID) { + checkNotNull(apiKey, "API key can't be null"); + checkNotNull(token, "Token can't be null"); + checkNotNull(userID, "User ID can't be null"); + checkArgument(!apiKey.isEmpty(), "API key can't be empty"); + checkArgument(!userID.isEmpty(), "User ID can't be empty"); + this.apiKey = apiKey; + this.token = token; + this.userID = userID; } - CompletableFuture addActivities(FeedID feed, Activity... activities) throws StreamException { - return stream.addActivities(token, feed, activities); + public Builder httpClient(HTTPClient httpClient) { + checkNotNull(httpClient, "HTTP client can't be null"); + this.httpClient = httpClient; + return this; } - CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { - return stream.removeActivityByID(token, feed, id); + public Builder scheme(String scheme) { + checkNotNull(scheme, "Scheme can't be null"); + checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); + this.scheme = scheme; + return this; } - CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) throws StreamException { - return stream.removeActivityByForeignID(token, feed, foreignID); + public Builder host(String host) { + checkNotNull(host, "Host can't be null"); + checkArgument(!host.isEmpty(), "Host can't be empty"); + this.host = host; + return this; } - CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) throws StreamException { - return stream.follow(token, token, source, target, activityCopyLimit); + public Builder port(int port) { + checkArgument(port > 0, "Port has to be a non-zero positive number"); + this.port = port; + return this; } - CompletableFuture getFollowers(FeedID feed, RequestOption... options) throws StreamException { - return stream.getFollowers(token, feed, options); + public Builder region(Region region) { + checkNotNull(region, "Region can't be null"); + this.region = region.toString(); + return this; } - CompletableFuture getFollowed(FeedID feed, RequestOption... options) throws StreamException { - return stream.getFollowed(token, feed, options); + public Builder region(String region) { + checkNotNull(region, "Region can't be null"); + checkArgument(!region.isEmpty(), "Region can't be empty"); + this.region = region; + return this; } - CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) throws StreamException { - return stream.unfollow(token, source, target, options); + private String buildHost() { + final StringBuilder sb = new StringBuilder(); + if (host.equals(DEFAULT_HOST)) { + sb.append(region).append("."); + } + sb.append(host); + return sb.toString(); } - CompletableFuture getUser(String id) throws StreamException { - return stream.getUser(token, id, false); + public CloudClient build() throws MalformedURLException { + if (httpClient == null) { + httpClient = new OKHTTPClientAdapter(); + } + return new CloudClient( + apiKey, token, userID, new URL(scheme, buildHost(), port, ""), httpClient); } + } - CompletableFuture deleteUser(String id) throws StreamException { - return stream.deleteUser(token, id); - } + public T getHTTPClientImplementation() { + return stream.getHTTPClientImplementation(); + } - CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { - return stream.createUser(token, id, data, true); - } + // TODO: add personalized feed versions + public CloudFlatFeed flatFeed(String slug) { + return flatFeed(slug, userID); + } + + public CloudFlatFeed flatFeed(String slug, CloudUser user) { + return flatFeed(slug, user.getID()); + } + + public CloudFlatFeed flatFeed(String slug, String userID) { + return flatFeed(new FeedID(slug, userID)); + } + + public CloudFlatFeed flatFeed(FeedID id) { + return new CloudFlatFeed(this, id); + } + + public CloudAggregatedFeed aggregatedFeed(String slug) { + return aggregatedFeed(slug, userID); + } + + public CloudAggregatedFeed aggregatedFeed(String slug, CloudUser user) { + return aggregatedFeed(slug, user.getID()); + } + + public CloudAggregatedFeed aggregatedFeed(String slug, String userID) { + return aggregatedFeed(new FeedID(slug, userID)); + } + + public CloudAggregatedFeed aggregatedFeed(FeedID id) { + return new CloudAggregatedFeed(this, id); + } - CompletableFuture createUser(String id, Data data) throws StreamException { - return stream.createUser(token, id, data, false); - } + public CloudNotificationFeed notificationFeed(String slug) { + return notificationFeed(slug, userID); + } - CompletableFuture updateUser(String id, Data data) throws StreamException { - return stream.updateUser(token, id, data); - } + public CloudNotificationFeed notificationFeed(String slug, CloudUser user) { + return notificationFeed(slug, user.getID()); + } - CompletableFuture userProfile(String id) throws StreamException { - return stream.getUser(token, id, true); - } + public CloudNotificationFeed notificationFeed(String slug, String userID) { + return notificationFeed(new FeedID(slug, userID)); + } + + public CloudNotificationFeed notificationFeed(FeedID id) { + return new CloudNotificationFeed(this, id); + } + + public CloudUser user(String userID) { + return new CloudUser(this, userID); + } + + public CloudAnalyticsClient analytics() { + return new CloudAnalyticsClient(token, stream.analytics()); + } + + public CloudCollectionsClient collections() { + return new CloudCollectionsClient(token, userID, stream.collections()); + } + + public CloudReactionsClient reactions() { + return new CloudReactionsClient(token, userID, stream.reactions()); + } + + public CloudFileStorageClient files() { + return new CloudFileStorageClient(token, stream.files()); + } + + public CloudImageStorageClient images() { + return new CloudImageStorageClient(token, stream.images()); + } + + CompletableFuture getActivities(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getActivities(token, feed, options); + } + + CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getEnrichedActivities(token, feed, options); + } + + CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { + return stream.addActivity(token, feed, activity); + } + + CompletableFuture addActivities(FeedID feed, Activity... activities) + throws StreamException { + return stream.addActivities(token, feed, activities); + } + + CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { + return stream.removeActivityByID(token, feed, id); + } + + CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) + throws StreamException { + return stream.removeActivityByForeignID(token, feed, foreignID); + } + + CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) + throws StreamException { + return stream.follow(token, token, source, target, activityCopyLimit); + } + + CompletableFuture getFollowers(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getFollowers(token, feed, options); + } + + CompletableFuture getFollowed(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getFollowed(token, feed, options); + } + + CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) + throws StreamException { + return stream.unfollow(token, source, target, options); + } + + CompletableFuture getUser(String id) throws StreamException { + return stream.getUser(token, id, false); + } + + CompletableFuture deleteUser(String id) throws StreamException { + return stream.deleteUser(token, id); + } + + CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { + return stream.createUser(token, id, data, true); + } + + CompletableFuture createUser(String id, Data data) throws StreamException { + return stream.createUser(token, id, data, false); + } + + CompletableFuture updateUser(String id, Data data) throws StreamException { + return stream.updateUser(token, id, data); + } + + CompletableFuture userProfile(String id) throws StreamException { + return stream.getUser(token, id, true); + } } diff --git a/src/main/java/io/getstream/cloud/CloudCollectionsClient.java b/src/main/java/io/getstream/cloud/CloudCollectionsClient.java index ce6312e2..969220d0 100644 --- a/src/main/java/io/getstream/cloud/CloudCollectionsClient.java +++ b/src/main/java/io/getstream/cloud/CloudCollectionsClient.java @@ -1,67 +1,75 @@ package io.getstream.cloud; +import static io.getstream.core.utils.Serialization.convert; + import io.getstream.core.StreamCollections; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; import io.getstream.core.models.CollectionData; import java8.util.concurrent.CompletableFuture; -import static io.getstream.core.utils.Serialization.convert; - public final class CloudCollectionsClient { - private final Token token; - private final String userID; - private final StreamCollections collections; + private final Token token; + private final String userID; + private final StreamCollections collections; - CloudCollectionsClient(Token token, String userID, StreamCollections collections) { - this.token = token; - this.userID = userID; - this.collections = collections; - } + CloudCollectionsClient(Token token, String userID, StreamCollections collections) { + this.token = token; + this.userID = userID; + this.collections = collections; + } - public CompletableFuture addCustom(String collection, T item) throws StreamException { - return addCustom(userID, collection, item); - } + public CompletableFuture addCustom(String collection, T item) throws StreamException { + return addCustom(userID, collection, item); + } - public CompletableFuture addCustom(String userID, String collection, T item) throws StreamException { - return add(userID, collection, convert(item, CollectionData.class)) - .thenApply(data -> convert(data, (Class) item.getClass())); - } + public CompletableFuture addCustom(String userID, String collection, T item) + throws StreamException { + return add(userID, collection, convert(item, CollectionData.class)) + .thenApply(data -> convert(data, (Class) item.getClass())); + } - public CompletableFuture add(String collection, CollectionData item) throws StreamException { - return add(userID, collection, item); - } + public CompletableFuture add(String collection, CollectionData item) + throws StreamException { + return add(userID, collection, item); + } - public CompletableFuture add(String userID, String collection, CollectionData item) throws StreamException { - return collections.add(token, userID, collection, item); - } + public CompletableFuture add( + String userID, String collection, CollectionData item) throws StreamException { + return collections.add(token, userID, collection, item); + } - public CompletableFuture updateCustom(String collection, T item) throws StreamException { - return updateCustom(userID, collection, item); - } + public CompletableFuture updateCustom(String collection, T item) throws StreamException { + return updateCustom(userID, collection, item); + } - public CompletableFuture updateCustom(String userID, String collection, T item) throws StreamException { - return update(userID, collection, convert(item, CollectionData.class)) - .thenApply(data -> convert(data, (Class) item.getClass())); - } + public CompletableFuture updateCustom(String userID, String collection, T item) + throws StreamException { + return update(userID, collection, convert(item, CollectionData.class)) + .thenApply(data -> convert(data, (Class) item.getClass())); + } - public CompletableFuture update(String collection, CollectionData item) throws StreamException { - return update(userID, collection, item); - } + public CompletableFuture update(String collection, CollectionData item) + throws StreamException { + return update(userID, collection, item); + } - public CompletableFuture update(String userID, String collection, CollectionData item) throws StreamException { - return collections.update(token, userID, collection, item); - } + public CompletableFuture update( + String userID, String collection, CollectionData item) throws StreamException { + return collections.update(token, userID, collection, item); + } - public CompletableFuture getCustom(Class type, String collection, String id) throws StreamException { - return get(collection, id).thenApply(data -> convert(data, type)); - } + public CompletableFuture getCustom(Class type, String collection, String id) + throws StreamException { + return get(collection, id).thenApply(data -> convert(data, type)); + } - public CompletableFuture get(String collection, String id) throws StreamException { - return collections.get(token, collection, id); - } + public CompletableFuture get(String collection, String id) + throws StreamException { + return collections.get(token, collection, id); + } - public CompletableFuture delete(String collection, String id) throws StreamException { - return collections.delete(token, collection, id); - } + public CompletableFuture delete(String collection, String id) throws StreamException { + return collections.delete(token, collection, id); + } } diff --git a/src/main/java/io/getstream/cloud/CloudFeed.java b/src/main/java/io/getstream/cloud/CloudFeed.java index d34b4ffd..c44d79ab 100644 --- a/src/main/java/io/getstream/cloud/CloudFeed.java +++ b/src/main/java/io/getstream/cloud/CloudFeed.java @@ -1,5 +1,9 @@ package io.getstream.cloud; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.*; + import com.google.common.collect.Iterables; import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; @@ -11,269 +15,318 @@ import io.getstream.core.options.RequestOption; import io.getstream.core.utils.DefaultOptions; import io.getstream.core.utils.Streams; -import java8.util.J8Arrays; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.*; +import java8.util.J8Arrays; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class CloudFeed { - private final CloudClient client; - private final FeedID id; - - CloudFeed(CloudClient client, FeedID id) { - checkNotNull(client, "Can't create feed w/o a client"); - checkNotNull(id, "Can't create feed w/o an ID"); - - this.client = client; - this.id = id; - } - - protected final CloudClient getClient() { - return client; - } - - public final FeedID getID() { - return id; - } - - public final String getSlug() { - return id.getSlug(); - } - - public final String getUserID() { - return id.getUserID(); - } - - public final CompletableFuture addActivity(Activity activity) throws StreamException { - return getClient() - .addActivity(id, activity) - .thenApply(response -> { - try { - return deserialize(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture addCustomActivity(T activity) throws StreamException { - return getClient() - .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) - .thenApply(response -> { - try { - return deserialize(response, (Class) activity.getClass()); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Iterable activities) throws StreamException { - return addActivities(Iterables.toArray(activities, Activity.class)); - } - - public final CompletableFuture> addCustomActivities(Iterable activities) throws StreamException { - final Activity[] custom = Streams.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply(response -> { - try { - Class element = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Activity... activities) throws StreamException { - return getClient() - .addActivities(id, activities) - .thenApply(response -> { - try { - return deserializeContainer(response, "activities", Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addCustomActivities(T... activities) throws StreamException { - final Activity[] custom = J8Arrays.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply(response -> { - try { - Class element = (Class) activities.getClass().getComponentType(); - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByID(String id) throws StreamException { - return client - .removeActivityByID(this.id, id) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByForeignID(String foreignID) throws StreamException { - return client - .removeActivityByForeignID(id, foreignID) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture follow(CloudFlatFeed feed) throws StreamException { - return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); - } - - public final CompletableFuture follow(CloudFlatFeed feed, int activityCopyLimit) throws StreamException { - checkArgument(activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, String.format("Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); - - return client - .follow(id, feed.getID(), activityCopyLimit) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowers(Iterable feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(FeedID... feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers(Limit limit, Iterable feedIDs) throws StreamException { - return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) throws StreamException { - return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers(Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Offset offset, FeedID... feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowers(Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds) - .map(id -> id.toString()) - .toArray(String[]::new); - final RequestOption[] options = feedIDs.length == 0 - ? new RequestOption[]{limit, offset} - : new RequestOption[]{limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs))}; - return client - .getFollowers(id, options) - .thenApply(response -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowed(Iterable feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(FeedID... feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed(Limit limit, Iterable feedIDs) throws StreamException { - return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) throws StreamException { - return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed(Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowed(Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds) - .map(id -> id.toString()) - .toArray(String[]::new); - final RequestOption[] options = feedIDs.length == 0 - ? new RequestOption[]{limit, offset} - : new RequestOption[]{limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs))}; - return client - .getFollowed(id, options) - .thenApply(response -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture unfollow(CloudFlatFeed feed) throws StreamException { - return unfollow(feed, io.getstream.core.KeepHistory.NO); - } - - public final CompletableFuture unfollow(CloudFlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { - return client - .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + private final CloudClient client; + private final FeedID id; + + CloudFeed(CloudClient client, FeedID id) { + checkNotNull(client, "Can't create feed w/o a client"); + checkNotNull(id, "Can't create feed w/o an ID"); + + this.client = client; + this.id = id; + } + + protected final CloudClient getClient() { + return client; + } + + public final FeedID getID() { + return id; + } + + public final String getSlug() { + return id.getSlug(); + } + + public final String getUserID() { + return id.getUserID(); + } + + public final CompletableFuture addActivity(Activity activity) throws StreamException { + return getClient() + .addActivity(id, activity) + .thenApply( + response -> { + try { + return deserialize(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture addCustomActivity(T activity) throws StreamException { + return getClient() + .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) + .thenApply( + response -> { + try { + return deserialize(response, (Class) activity.getClass()); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Iterable activities) + throws StreamException { + return addActivities(Iterables.toArray(activities, Activity.class)); + } + + public final CompletableFuture> addCustomActivities(Iterable activities) + throws StreamException { + final Activity[] custom = + Streams.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + response -> { + try { + Class element = + (Class) + ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Activity... activities) + throws StreamException { + return getClient() + .addActivities(id, activities) + .thenApply( + response -> { + try { + return deserializeContainer(response, "activities", Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addCustomActivities(T... activities) + throws StreamException { + final Activity[] custom = + J8Arrays.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + response -> { + try { + Class element = (Class) activities.getClass().getComponentType(); + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByID(String id) throws StreamException { + return client + .removeActivityByID(this.id, id) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByForeignID(String foreignID) + throws StreamException { + return client + .removeActivityByForeignID(id, foreignID) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture follow(CloudFlatFeed feed) throws StreamException { + return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); + } + + public final CompletableFuture follow(CloudFlatFeed feed, int activityCopyLimit) + throws StreamException { + checkArgument( + activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, + String.format( + "Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); + + return client + .follow(id, feed.getID(), activityCopyLimit) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowers(Iterable feedIDs) + throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(FeedID... feedIDs) + throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowers( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Offset offset, FeedID... feedIDs) throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[] {limit, offset} + : new RequestOption[] { + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowers(id, options) + .thenApply( + response -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowed(Iterable feedIDs) + throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowed( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[] {limit, offset} + : new RequestOption[] { + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowed(id, options) + .thenApply( + response -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture unfollow(CloudFlatFeed feed) throws StreamException { + return unfollow(feed, io.getstream.core.KeepHistory.NO); + } + + public final CompletableFuture unfollow( + CloudFlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { + return client + .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudFileStorageClient.java b/src/main/java/io/getstream/cloud/CloudFileStorageClient.java index 337e3b0f..b3a82f16 100644 --- a/src/main/java/io/getstream/cloud/CloudFileStorageClient.java +++ b/src/main/java/io/getstream/cloud/CloudFileStorageClient.java @@ -3,29 +3,28 @@ import io.getstream.core.StreamFiles; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Token; -import java8.util.concurrent.CompletableFuture; - import java.io.File; import java.net.URL; +import java8.util.concurrent.CompletableFuture; public final class CloudFileStorageClient { - private final Token token; - private final StreamFiles files; + private final Token token; + private final StreamFiles files; - CloudFileStorageClient(Token token, StreamFiles files) { - this.token = token; - this.files = files; - } + CloudFileStorageClient(Token token, StreamFiles files) { + this.token = token; + this.files = files; + } - public CompletableFuture upload(String fileName, byte[] content) throws StreamException { - return files.upload(token, fileName, content); - } + public CompletableFuture upload(String fileName, byte[] content) throws StreamException { + return files.upload(token, fileName, content); + } - public CompletableFuture upload(File content) throws StreamException { - return files.upload(token, content); - } + public CompletableFuture upload(File content) throws StreamException { + return files.upload(token, content); + } - public CompletableFuture delete(URL url) throws StreamException { - return files.delete(token, url); - } + public CompletableFuture delete(URL url) throws StreamException { + return files.delete(token, url); + } } diff --git a/src/main/java/io/getstream/cloud/CloudFlatFeed.java b/src/main/java/io/getstream/cloud/CloudFlatFeed.java index bc0e8ff2..cf90c896 100644 --- a/src/main/java/io/getstream/cloud/CloudFlatFeed.java +++ b/src/main/java/io/getstream/cloud/CloudFlatFeed.java @@ -1,369 +1,660 @@ package io.getstream.cloud; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; import io.getstream.core.models.FeedID; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class CloudFlatFeed extends CloudFeed { - CloudFlatFeed(CloudClient client, FeedID id) { - super(client, id); - } - - public CompletableFuture> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Limit limit, String ranking) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Filter filter, String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Offset offset, String ranking) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - CompletableFuture> getActivities(Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, String ranking) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, Offset offset, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Filter filter, String ranking) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - CompletableFuture> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedActivities(Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - CompletableFuture> getEnrichedActivities(Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getEnrichedActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - final RequestOption[] options = ranking == null - ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking)}; - return getClient() - .getActivities(getID(), options) - .thenApply(response -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudFlatFeed(CloudClient client, FeedID id) { + super(client, id); + } + + public CompletableFuture> getActivities() throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getActivities(Limit limit) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(String ranking) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getActivities(Filter filter) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Offset offset) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Limit limit, String ranking) + throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Filter filter, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Offset offset, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + CompletableFuture> getActivities( + Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getCustomActivities(Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getCustomActivities(Class type, Limit limit) + throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities(Class type, String ranking) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getCustomActivities(Class type, Filter filter) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities(Class type, Offset offset) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities(String ranking) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities(Filter filter) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities(Offset offset) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) + throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getEnrichedActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) + throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + CompletableFuture> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + EnrichmentFlags flags, + String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[] { + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + response -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudImageStorageClient.java b/src/main/java/io/getstream/cloud/CloudImageStorageClient.java index 6b5af7eb..c9b15aa6 100644 --- a/src/main/java/io/getstream/cloud/CloudImageStorageClient.java +++ b/src/main/java/io/getstream/cloud/CloudImageStorageClient.java @@ -5,37 +5,36 @@ import io.getstream.core.http.Token; import io.getstream.core.options.Crop; import io.getstream.core.options.Resize; -import java8.util.concurrent.CompletableFuture; - import java.io.File; import java.net.URL; +import java8.util.concurrent.CompletableFuture; public final class CloudImageStorageClient { - private final Token token; - private final StreamImages images; + private final Token token; + private final StreamImages images; - CloudImageStorageClient(Token token, StreamImages images) { - this.token = token; - this.images = images; - } + CloudImageStorageClient(Token token, StreamImages images) { + this.token = token; + this.images = images; + } - public CompletableFuture upload(String fileName, byte[] content) throws StreamException { - return images.upload(token, fileName, content); - } + public CompletableFuture upload(String fileName, byte[] content) throws StreamException { + return images.upload(token, fileName, content); + } - public CompletableFuture upload(File content) throws StreamException { - return images.upload(token, content); - } + public CompletableFuture upload(File content) throws StreamException { + return images.upload(token, content); + } - public CompletableFuture delete(URL url) throws StreamException { - return images.delete(token, url); - } + public CompletableFuture delete(URL url) throws StreamException { + return images.delete(token, url); + } - public CompletableFuture process(URL url, Crop crop) throws StreamException { - return images.process(token, url, crop); - } + public CompletableFuture process(URL url, Crop crop) throws StreamException { + return images.process(token, url, crop); + } - public CompletableFuture process(URL url, Resize resize) throws StreamException { - return images.process(token, url, resize); - } + public CompletableFuture process(URL url, Resize resize) throws StreamException { + return images.process(token, url, resize); + } } diff --git a/src/main/java/io/getstream/cloud/CloudNotificationFeed.java b/src/main/java/io/getstream/cloud/CloudNotificationFeed.java index b3036c60..f8a9e55e 100644 --- a/src/main/java/io/getstream/cloud/CloudNotificationFeed.java +++ b/src/main/java/io/getstream/cloud/CloudNotificationFeed.java @@ -1,5 +1,7 @@ package io.getstream.cloud; +import static io.getstream.core.utils.Serialization.deserializeContainer; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Activity; import io.getstream.core.models.EnrichedActivity; @@ -7,428 +9,775 @@ import io.getstream.core.models.NotificationGroup; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.util.List; - -import static io.getstream.core.utils.Serialization.deserializeContainer; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class CloudNotificationFeed extends CloudAggregatedFeed { - CloudNotificationFeed(CloudClient client, FeedID id) { - super(client, id); - } - - @Override - public CompletableFuture>> getActivities() throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Offset offset) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Filter filter) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Offset offset) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Filter filter) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedActivities() throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedActivities(Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedCustomActivities(Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply(response -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudNotificationFeed(CloudClient client, FeedID id) { + super(client, id); + } + + @Override + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(ActivityMarker marker) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getCustomActivities(Class type) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedActivities() + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer( + response, NotificationGroup.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + response -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudReactionsClient.java b/src/main/java/io/getstream/cloud/CloudReactionsClient.java index e50056e6..a331cd83 100644 --- a/src/main/java/io/getstream/cloud/CloudReactionsClient.java +++ b/src/main/java/io/getstream/cloud/CloudReactionsClient.java @@ -1,5 +1,8 @@ package io.getstream.cloud; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Iterables; import io.getstream.core.LookupKind; import io.getstream.core.StreamReactions; @@ -10,133 +13,156 @@ import io.getstream.core.options.Filter; import io.getstream.core.options.Limit; import io.getstream.core.utils.DefaultOptions; -import java8.util.concurrent.CompletableFuture; - import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import java8.util.concurrent.CompletableFuture; public final class CloudReactionsClient { - private final Token token; - private final String userID; - private final StreamReactions reactions; - - CloudReactionsClient(Token token, String userID, StreamReactions reactions) { - this.token = token; - this.userID = userID; - this.reactions = reactions; - } - - public CompletableFuture get(String id) throws StreamException { - return reactions.get(token, id); - } - - public CompletableFuture> filter(LookupKind lookup, String id) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Limit limit) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter) throws StreamException { - return filter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, String kind) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { - return filter(lookup, id, filter, limit, ""); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Limit limit, String kind) throws StreamException { - return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); - } - - public CompletableFuture> filter(LookupKind lookup, String id, Filter filter, Limit limit, String kind) throws StreamException { - return reactions.filter(token, lookup, id, filter, limit, kind); - } - - public CompletableFuture add(String kind, String activityID, Iterable targetFeeds) throws StreamException { - return add(userID, kind, activityID, targetFeeds); - } - - public CompletableFuture add(String kind, String activityID, FeedID... targetFeeds) throws StreamException { - return add(userID, activityID, targetFeeds); - } - - public CompletableFuture add(Reaction reaction, Iterable targetFeeds) throws StreamException { - return add(userID, reaction, targetFeeds); - } - - public CompletableFuture add(Reaction reaction, FeedID... targetFeeds) throws StreamException { - return add(userID, reaction, targetFeeds); - } - - public CompletableFuture add(String userID, String kind, String activityID, Iterable targetFeeds) throws StreamException { - return add(userID, kind, activityID, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture add(String userID, String kind, String activityID, FeedID... targetFeeds) throws StreamException { - checkNotNull(kind, "Reaction kind can't be null"); - checkArgument(!kind.isEmpty(), "Reaction kind can't be empty"); - checkNotNull(activityID, "Reaction activity id can't be null"); - checkArgument(!activityID.isEmpty(), "Reaction activity id can't be empty"); - - return add(userID, Reaction.builder().activityID(activityID).kind(kind).build(), targetFeeds); - } - - public CompletableFuture add(String userID, Reaction reaction, Iterable targetFeeds) throws StreamException { - return add(userID, reaction, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture add(String userID, Reaction reaction, FeedID... targetFeeds) throws StreamException { - return reactions.add(token, userID, reaction, targetFeeds); - } - - public CompletableFuture addChild(String userID, String kind, String parentID, Iterable targetFeeds) throws StreamException { - Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String kind, String parentID, FeedID... targetFeeds) throws StreamException { - Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String parentID, Reaction reaction, Iterable targetFeeds) throws StreamException { - Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture addChild(String userID, String parentID, Reaction reaction, FeedID... targetFeeds) throws StreamException { - Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); - return add(userID, child, targetFeeds); - } - - public CompletableFuture update(String id, Iterable targetFeeds) throws StreamException { - return update(id, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture update(String id, FeedID... targetFeeds) throws StreamException { - checkNotNull(id, "Reaction id can't be null"); - checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - - return update(Reaction.builder().id(id).build(), targetFeeds); - } - - public CompletableFuture update(Reaction reaction, Iterable targetFeeds) throws StreamException { - return update(reaction, Iterables.toArray(targetFeeds, FeedID.class)); - } - - public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) throws StreamException { - return reactions.update(token, reaction, targetFeeds); - } - - public CompletableFuture delete(String id) throws StreamException { - return reactions.delete(token, id); - } + private final Token token; + private final String userID; + private final StreamReactions reactions; + + CloudReactionsClient(Token token, String userID, StreamReactions reactions) { + this.token = token; + this.userID = userID; + this.reactions = reactions; + } + + public CompletableFuture get(String id) throws StreamException { + return reactions.get(token, id); + } + + public CompletableFuture> filter(LookupKind lookup, String id) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, Limit limit) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, Filter filter) + throws StreamException { + return filter(lookup, id, filter, DefaultOptions.DEFAULT_LIMIT, ""); + } + + public CompletableFuture> filter(LookupKind lookup, String id, String kind) + throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_LIMIT, kind); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Filter filter, Limit limit) throws StreamException { + return filter(lookup, id, filter, limit, ""); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Limit limit, String kind) throws StreamException { + return filter(lookup, id, DefaultOptions.DEFAULT_FILTER, limit, kind); + } + + public CompletableFuture> filter( + LookupKind lookup, String id, Filter filter, Limit limit, String kind) + throws StreamException { + return reactions.filter(token, lookup, id, filter, limit, kind); + } + + public CompletableFuture add( + String kind, String activityID, Iterable targetFeeds) throws StreamException { + return add(userID, kind, activityID, targetFeeds); + } + + public CompletableFuture add(String kind, String activityID, FeedID... targetFeeds) + throws StreamException { + return add(userID, activityID, targetFeeds); + } + + public CompletableFuture add(Reaction reaction, Iterable targetFeeds) + throws StreamException { + return add(userID, reaction, targetFeeds); + } + + public CompletableFuture add(Reaction reaction, FeedID... targetFeeds) + throws StreamException { + return add(userID, reaction, targetFeeds); + } + + public CompletableFuture add( + String userID, String kind, String activityID, Iterable targetFeeds) + throws StreamException { + return add(userID, kind, activityID, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture add( + String userID, String kind, String activityID, FeedID... targetFeeds) throws StreamException { + checkNotNull(kind, "Reaction kind can't be null"); + checkArgument(!kind.isEmpty(), "Reaction kind can't be empty"); + checkNotNull(activityID, "Reaction activity id can't be null"); + checkArgument(!activityID.isEmpty(), "Reaction activity id can't be empty"); + + return add(userID, Reaction.builder().activityID(activityID).kind(kind).build(), targetFeeds); + } + + public CompletableFuture add( + String userID, Reaction reaction, Iterable targetFeeds) throws StreamException { + return add(userID, reaction, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture add(String userID, Reaction reaction, FeedID... targetFeeds) + throws StreamException { + return reactions.add(token, userID, reaction, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String kind, String parentID, Iterable targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String kind, String parentID, FeedID... targetFeeds) throws StreamException { + Reaction child = Reaction.builder().kind(kind).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String parentID, Reaction reaction, Iterable targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture addChild( + String userID, String parentID, Reaction reaction, FeedID... targetFeeds) + throws StreamException { + Reaction child = Reaction.builder().fromReaction(reaction).parent(parentID).build(); + return add(userID, child, targetFeeds); + } + + public CompletableFuture update(String id, Iterable targetFeeds) + throws StreamException { + return update(id, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture update(String id, FeedID... targetFeeds) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); + + return update(Reaction.builder().id(id).build(), targetFeeds); + } + + public CompletableFuture update(Reaction reaction, Iterable targetFeeds) + throws StreamException { + return update(reaction, Iterables.toArray(targetFeeds, FeedID.class)); + } + + public CompletableFuture update(Reaction reaction, FeedID... targetFeeds) + throws StreamException { + return reactions.update(token, reaction, targetFeeds); + } + + public CompletableFuture delete(String id) throws StreamException { + return reactions.delete(token, id); + } } diff --git a/src/main/java/io/getstream/cloud/CloudUser.java b/src/main/java/io/getstream/cloud/CloudUser.java index 1686cf60..1f27a5b3 100644 --- a/src/main/java/io/getstream/cloud/CloudUser.java +++ b/src/main/java/io/getstream/cloud/CloudUser.java @@ -1,106 +1,117 @@ package io.getstream.cloud; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.deserialize; +import static io.getstream.core.utils.Serialization.deserializeError; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.models.Data; import io.getstream.core.models.ProfileData; +import java.io.IOException; import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; -import java.io.IOException; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.deserialize; -import static io.getstream.core.utils.Serialization.deserializeError; - public final class CloudUser { - private final CloudClient client; - private final String id; + private final CloudClient client; + private final String id; - public CloudUser(CloudClient client, String id) { - checkNotNull(client, "Client can't be null"); - checkNotNull(id, "User ID can't be null"); - checkArgument(!id.isEmpty(), "User ID can't be empty"); + public CloudUser(CloudClient client, String id) { + checkNotNull(client, "Client can't be null"); + checkNotNull(id, "User ID can't be null"); + checkArgument(!id.isEmpty(), "User ID can't be empty"); - this.client = client; - this.id = id; - } + this.client = client; + this.id = id; + } - public String getID() { - return id; - } + public String getID() { + return id; + } - public CompletableFuture get() throws StreamException { - return client.getUser(id) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture get() throws StreamException { + return client + .getUser(id) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture delete() throws StreamException { - return client.deleteUser(id) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture delete() throws StreamException { + return client + .deleteUser(id) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture getOrCreate() throws StreamException { - return getOrCreate(new Data()); - } + public CompletableFuture getOrCreate() throws StreamException { + return getOrCreate(new Data()); + } - public CompletableFuture getOrCreate(Data data) throws StreamException { - return client.getOrCreateUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture getOrCreate(Data data) throws StreamException { + return client + .getOrCreateUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture create(Data data) throws StreamException { - return client.createUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture create(Data data) throws StreamException { + return client + .createUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture create() throws StreamException { - return create(new Data()); - } + public CompletableFuture create() throws StreamException { + return create(new Data()); + } - public CompletableFuture update(Data data) throws StreamException { - return client.updateUser(id, data) - .thenApply(response -> { - try { - return deserialize(response, Data.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture update(Data data) throws StreamException { + return client + .updateUser(id, data) + .thenApply( + response -> { + try { + return deserialize(response, Data.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } - public CompletableFuture profile() throws StreamException { - return client.userProfile(id) - .thenApply(response -> { - try { - return deserialize(response, ProfileData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + public CompletableFuture profile() throws StreamException { + return client + .userProfile(id) + .thenApply( + response -> { + try { + return deserialize(response, ProfileData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/core/KeepHistory.java b/src/main/java/io/getstream/core/KeepHistory.java index 92ff2a86..5cec59b4 100644 --- a/src/main/java/io/getstream/core/KeepHistory.java +++ b/src/main/java/io/getstream/core/KeepHistory.java @@ -1,16 +1,16 @@ package io.getstream.core; public enum KeepHistory { - YES(true), - NO(false); + YES(true), + NO(false); - private final boolean flag; + private final boolean flag; - KeepHistory(boolean flag) { - this.flag = flag; - } + KeepHistory(boolean flag) { + this.flag = flag; + } - public boolean getFlag() { - return flag; - } + public boolean getFlag() { + return flag; + } } diff --git a/src/main/java/io/getstream/core/LookupKind.java b/src/main/java/io/getstream/core/LookupKind.java index a24dcc95..9f4e8bdb 100644 --- a/src/main/java/io/getstream/core/LookupKind.java +++ b/src/main/java/io/getstream/core/LookupKind.java @@ -1,18 +1,18 @@ package io.getstream.core; public enum LookupKind { - ACTIVITY("activity_id"), - ACTIVITY_WITH_DATA("activity_id"), - REACTION("reaction_id"), - USER("user_id"); + ACTIVITY("activity_id"), + ACTIVITY_WITH_DATA("activity_id"), + REACTION("reaction_id"), + USER("user_id"); - private final String kind; + private final String kind; - LookupKind(String kind) { - this.kind = kind; - } + LookupKind(String kind) { + this.kind = kind; + } - public String getKind() { - return kind; - } + public String getKind() { + return kind; + } } diff --git a/src/main/java/io/getstream/core/Region.java b/src/main/java/io/getstream/core/Region.java index ce393e6a..07b67717 100644 --- a/src/main/java/io/getstream/core/Region.java +++ b/src/main/java/io/getstream/core/Region.java @@ -1,20 +1,20 @@ package io.getstream.core; public enum Region { - US_EAST("us-east-api"), - TOKYO("tokyo-api"), - DUBLIN("dublin-api"), - SINGAPORE("singapore-api"), - CANADA("ca-central-1"); + US_EAST("us-east-api"), + TOKYO("tokyo-api"), + DUBLIN("dublin-api"), + SINGAPORE("singapore-api"), + CANADA("ca-central-1"); - private final String region; + private final String region; - Region(String region) { - this.region = region; - } + Region(String region) { + this.region = region; + } - @Override - public String toString() { - return region; - } + @Override + public String toString() { + return region; + } } diff --git a/src/main/java/io/getstream/core/Stream.java b/src/main/java/io/getstream/core/Stream.java index 808c90f6..02fc1bd2 100644 --- a/src/main/java/io/getstream/core/Stream.java +++ b/src/main/java/io/getstream/core/Stream.java @@ -1,5 +1,11 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.*; +import static io.getstream.core.utils.Routes.*; +import static io.getstream.core.utils.Serialization.*; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.OptBoolean; import com.fasterxml.jackson.core.JsonProcessingException; @@ -10,10 +16,6 @@ import io.getstream.core.models.*; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.RequestOption; -import java8.util.J8Arrays; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -21,402 +23,473 @@ import java.util.Date; import java.util.List; import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.*; -import static io.getstream.core.utils.Routes.*; -import static io.getstream.core.utils.Serialization.*; +import java8.util.J8Arrays; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class Stream { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; - - public Stream(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } - - public StreamBatch batch() { - return new StreamBatch(key, baseURL, httpClient); - } - - public StreamCollections collections() { - return new StreamCollections(key, baseURL, httpClient); - } - - public StreamPersonalization personalization() { - return new StreamPersonalization(key, baseURL, httpClient); - } - - public StreamAnalytics analytics() { - return new StreamAnalytics(key, baseURL, httpClient); - } - - public StreamReactions reactions() { - return new StreamReactions(key, baseURL, httpClient); + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; + + public Stream(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } + + public StreamBatch batch() { + return new StreamBatch(key, baseURL, httpClient); + } + + public StreamCollections collections() { + return new StreamCollections(key, baseURL, httpClient); + } + + public StreamPersonalization personalization() { + return new StreamPersonalization(key, baseURL, httpClient); + } + + public StreamAnalytics analytics() { + return new StreamAnalytics(key, baseURL, httpClient); + } + + public StreamReactions reactions() { + return new StreamReactions(key, baseURL, httpClient); + } + + public StreamFiles files() { + return new StreamFiles(key, baseURL, httpClient); + } + + public StreamImages images() { + return new StreamImages(key, baseURL, httpClient); + } + + public CompletableFuture> updateActivitiesByID( + Token token, ActivityUpdate[] updates) throws StreamException { + checkNotNull(updates, "No updates"); + checkArgument(updates.length > 0, "No updates"); + for (ActivityUpdate update : updates) { + checkNotNull(update.getID(), "No activity to update"); + checkNotNull(update.getSet(), "No activity properties to set"); + checkNotNull(update.getUnset(), "No activity properties to unset"); } - public StreamFiles files() { - return new StreamFiles(key, baseURL, httpClient); - } - - public StreamImages images() { - return new StreamImages(key, baseURL, httpClient); - } - - public CompletableFuture> updateActivitiesByID(Token token, ActivityUpdate[] updates) throws StreamException { - checkNotNull(updates, "No updates"); - checkArgument(updates.length > 0, "No updates"); - for (ActivityUpdate update : updates) { - checkNotNull(update.getID(), "No activity to update"); - checkNotNull(update.getSet(), "No activity properties to set"); - checkNotNull(update.getUnset(), "No activity properties to unset"); - } - - try { - final byte[] payload = toJSON(new Object() { + try { + final byte[] payload = + toJSON( + new Object() { public final ActivityUpdate[] changes = updates; - }); - final URL url = buildActivityUpdateURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeContainer(response, "activities", Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildActivityUpdateURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeContainer(response, "activities", Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture updateActivityByID(Token token, String id, Map set, String[] unset) throws StreamException { - checkNotNull(id, "No activity to update"); - checkNotNull(set, "No activity properties to set"); - checkNotNull(unset, "No activity properties to unset"); - - try { - //XXX: renaming variables so we can unambiguously name payload fields 'id', 'set', 'unset' - String activityID = id; - Map propertiesToSet = set; - String[] propertiesToUnset = unset; - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture updateActivityByID( + Token token, String id, Map set, String[] unset) throws StreamException { + checkNotNull(id, "No activity to update"); + checkNotNull(set, "No activity properties to set"); + checkNotNull(unset, "No activity properties to unset"); + + try { + // XXX: renaming variables so we can unambiguously name payload fields 'id', 'set', 'unset' + String activityID = id; + Map propertiesToSet = set; + String[] propertiesToUnset = unset; + final byte[] payload = + toJSON( + new Object() { public final String id = activityID; public final Map set = propertiesToSet; public final String[] unset = propertiesToUnset; - }); - final URL url = buildActivityUpdateURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserialize(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildActivityUpdateURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserialize(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); + } + } + + public CompletableFuture> updateActivitiesByForeignID( + Token token, ActivityUpdate[] updates) throws StreamException { + checkNotNull(updates, "No updates"); + checkArgument(updates.length > 0, "No updates"); + for (ActivityUpdate update : updates) { + checkNotNull(update.getForeignID(), "No activity to update"); + checkNotNull(update.getTime(), "Missing timestamp"); + checkNotNull(update.getSet(), "No activity properties to set"); + checkNotNull(update.getUnset(), "No activity properties to unset"); } - public CompletableFuture> updateActivitiesByForeignID(Token token, ActivityUpdate[] updates) throws StreamException { - checkNotNull(updates, "No updates"); - checkArgument(updates.length > 0, "No updates"); - for (ActivityUpdate update : updates) { - checkNotNull(update.getForeignID(), "No activity to update"); - checkNotNull(update.getTime(), "Missing timestamp"); - checkNotNull(update.getSet(), "No activity properties to set"); - checkNotNull(update.getUnset(), "No activity properties to unset"); - } - - try { - final byte[] payload = toJSON(new Object() { + try { + final byte[] payload = + toJSON( + new Object() { public final ActivityUpdate[] changes = updates; - }); - final URL url = buildActivityUpdateURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeContainer(response, "activities", Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildActivityUpdateURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeContainer(response, "activities", Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture updateActivityByForeignID(Token token, String foreignID, Date timestamp, Map set, String[] unset) throws StreamException { - checkNotNull(foreignID, "No activity to update"); - checkNotNull(timestamp, "Missing timestamp"); - checkNotNull(set, "No activity properties to set"); - checkNotNull(unset, "No activity properties to unset"); - - try { - //XXX: renaming variables so we can unambiguously name payload fields 'set', 'unset' - Map propertiesToSet = set; - String[] propertiesToUnset = unset; - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture updateActivityByForeignID( + Token token, String foreignID, Date timestamp, Map set, String[] unset) + throws StreamException { + checkNotNull(foreignID, "No activity to update"); + checkNotNull(timestamp, "Missing timestamp"); + checkNotNull(set, "No activity properties to set"); + checkNotNull(unset, "No activity properties to unset"); + + try { + // XXX: renaming variables so we can unambiguously name payload fields 'set', 'unset' + Map propertiesToSet = set; + String[] propertiesToUnset = unset; + final byte[] payload = + toJSON( + new Object() { public final String foreign_id = foreignID; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", lenient = OptBoolean.FALSE, timezone = "UTC") + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") public final Date time = timestamp; + public final Map set = propertiesToSet; public final String[] unset = propertiesToUnset; - }); - final URL url = buildActivityUpdateURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserialize(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildActivityUpdateURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserialize(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture openGraph(Token token, URL targetURL) throws StreamException { - checkNotNull(targetURL, "Missing url"); - - try { - final URL url = buildOpenGraphURL(baseURL); - return httpClient.execute(buildGet(url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) - .thenApply(response -> { - try { - return deserialize(response, OGData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture openGraph(Token token, URL targetURL) throws StreamException { + checkNotNull(targetURL, "Missing url"); + + try { + final URL url = buildOpenGraphURL(baseURL); + return httpClient + .execute( + buildGet( + url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) + .thenApply( + response -> { + try { + return deserialize(response, OGData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public T getHTTPClientImplementation() { - return httpClient.getImplementation(); - } + public T getHTTPClientImplementation() { + return httpClient.getImplementation(); + } - public CompletableFuture getActivities(Token token, FeedID feed, RequestOption... options) throws StreamException { - checkNotNull(options, "Missing request options"); + public CompletableFuture getActivities( + Token token, FeedID feed, RequestOption... options) throws StreamException { + checkNotNull(options, "Missing request options"); - try { - final URL url = buildFeedURL(baseURL, feed, "/"); - return httpClient.execute(buildGet(url, key, token, options)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFeedURL(baseURL, feed, "/"); + return httpClient.execute(buildGet(url, key, token, options)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture getEnrichedActivities(Token token, FeedID feed, RequestOption... options) throws StreamException { - checkNotNull(options, "Missing request options"); + public CompletableFuture getEnrichedActivities( + Token token, FeedID feed, RequestOption... options) throws StreamException { + checkNotNull(options, "Missing request options"); - try { - final URL url = buildEnrichedFeedURL(baseURL, feed, "/"); - return httpClient.execute(buildGet(url, key, token, options)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildEnrichedFeedURL(baseURL, feed, "/"); + return httpClient.execute(buildGet(url, key, token, options)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture addActivity(Token token, FeedID feed, Activity activity) throws StreamException { - checkNotNull(activity, "No activity to add"); - - try { - final byte[] payload = toJSON(activity); - final URL url = buildFeedURL(baseURL, feed, "/"); - return httpClient.execute(buildPost(url, key, token, payload)); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture addActivity(Token token, FeedID feed, Activity activity) + throws StreamException { + checkNotNull(activity, "No activity to add"); + + try { + final byte[] payload = toJSON(activity); + final URL url = buildFeedURL(baseURL, feed, "/"); + return httpClient.execute(buildPost(url, key, token, payload)); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture addActivities(Token token, FeedID feed, Activity... activityObjects) throws StreamException { - checkNotNull(activityObjects, "No activities to add"); + public CompletableFuture addActivities( + Token token, FeedID feed, Activity... activityObjects) throws StreamException { + checkNotNull(activityObjects, "No activities to add"); - try { - final byte[] payload = toJSON(new Object() { + try { + final byte[] payload = + toJSON( + new Object() { public final Activity[] activities = activityObjects; - }); - final URL url = buildFeedURL(baseURL, feed, "/"); - return httpClient.execute(buildPost(url, key, token, payload)); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildFeedURL(baseURL, feed, "/"); + return httpClient.execute(buildPost(url, key, token, payload)); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture removeActivityByID(Token token, FeedID feed, String id) throws StreamException { - checkNotNull(id, "No activity id to remove"); + public CompletableFuture removeActivityByID(Token token, FeedID feed, String id) + throws StreamException { + checkNotNull(id, "No activity id to remove"); - try { - final URL url = buildFeedURL(baseURL, feed, '/' + id + '/'); - return httpClient.execute(buildDelete(url, key, token)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFeedURL(baseURL, feed, '/' + id + '/'); + return httpClient.execute(buildDelete(url, key, token)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture removeActivityByForeignID(Token token, FeedID feed, String foreignID) throws StreamException { - checkNotNull(foreignID, "No activity id to remove"); - - try { - final URL url = buildFeedURL(baseURL, feed, '/' + foreignID + '/'); - return httpClient.execute(buildDelete(url, key, token, new CustomQueryParameter("foreign_id", "1"))); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture removeActivityByForeignID( + Token token, FeedID feed, String foreignID) throws StreamException { + checkNotNull(foreignID, "No activity id to remove"); + + try { + final URL url = buildFeedURL(baseURL, feed, '/' + foreignID + '/'); + return httpClient.execute( + buildDelete(url, key, token, new CustomQueryParameter("foreign_id", "1"))); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture follow(Token token, Token targetToken, FeedID sourceFeed, FeedID targetFeed, int activityCopyLimit) throws StreamException { - checkNotNull(targetFeed, "No feed to follow"); - checkArgument(sourceFeed != targetFeed, "Feed can't follow itself"); - checkArgument(activityCopyLimit >= 0, "Activity copy limit should be a non-negative number"); - - try { - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture follow( + Token token, Token targetToken, FeedID sourceFeed, FeedID targetFeed, int activityCopyLimit) + throws StreamException { + checkNotNull(targetFeed, "No feed to follow"); + checkArgument(sourceFeed != targetFeed, "Feed can't follow itself"); + checkArgument(activityCopyLimit >= 0, "Activity copy limit should be a non-negative number"); + + try { + final byte[] payload = + toJSON( + new Object() { public String target = targetFeed.toString(); public int activity_copy_limit = activityCopyLimit; public String target_token = targetToken.toString(); - }); - final URL url = buildFeedURL(baseURL, sourceFeed, "/following/"); - return httpClient.execute(buildPost(url, key, token, payload)); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildFeedURL(baseURL, sourceFeed, "/following/"); + return httpClient.execute(buildPost(url, key, token, payload)); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture getFollowers(Token token, FeedID feed, RequestOption... options) throws StreamException { - checkNotNull(options, "Missing request options"); + public CompletableFuture getFollowers( + Token token, FeedID feed, RequestOption... options) throws StreamException { + checkNotNull(options, "Missing request options"); - try { - final URL url = buildFeedURL(baseURL, feed, "/followers/"); - return httpClient.execute(buildGet(url, key, token, options)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFeedURL(baseURL, feed, "/followers/"); + return httpClient.execute(buildGet(url, key, token, options)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture getFollowed(Token token, FeedID feed, RequestOption... options) throws StreamException { - checkNotNull(options, "Missing request options"); + public CompletableFuture getFollowed(Token token, FeedID feed, RequestOption... options) + throws StreamException { + checkNotNull(options, "Missing request options"); - try { - final URL url = buildFeedURL(baseURL, feed, "/following/"); - return httpClient.execute(buildGet(url, key, token, options)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFeedURL(baseURL, feed, "/following/"); + return httpClient.execute(buildGet(url, key, token, options)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture unfollow(Token token, FeedID source, FeedID target, RequestOption... options) throws StreamException { - checkNotNull(options, "Missing request options"); - checkNotNull(target, "No target feed to unfollow"); - - try { - final URL url = buildFeedURL(baseURL, source, "/following/" + target + '/'); - return httpClient.execute(buildDelete(url, key, token, options)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture unfollow( + Token token, FeedID source, FeedID target, RequestOption... options) throws StreamException { + checkNotNull(options, "Missing request options"); + checkNotNull(target, "No target feed to unfollow"); + + try { + final URL url = buildFeedURL(baseURL, source, "/following/" + target + '/'); + return httpClient.execute(buildDelete(url, key, token, options)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture updateActivityToTargets(Token token, FeedID feed, Activity activity, FeedID[] add, FeedID[] remove, FeedID[] replace) throws StreamException { - checkNotNull(activity, "No activity to update"); - checkNotNull(activity.getForeignID(), "Activity is required to have foreign ID attribute"); - checkNotNull(activity.getTime(), "Activity is required to have time attribute"); - checkNotNull(add, "No targets to add"); - checkNotNull(remove, "No targets to remove"); - checkNotNull(replace, "No targets to set"); - boolean modification = replace.length == 0 && (add.length > 0 || remove.length > 0); - boolean replacement = replace.length > 0 && add.length == 0 && remove.length == 0; - checkArgument(modification || replacement, "Can't replace and modify activity to targets at the same time"); - - final String[] addedTargets = J8Arrays.stream(add) - .map(id -> id.toString()) - .toArray(String[]::new); - final String[] removedTargets = J8Arrays.stream(remove) - .map(id -> id.toString()) - .toArray(String[]::new); - final String[] newTargets = J8Arrays.stream(replace) - .map(id -> id.toString()) - .toArray(String[]::new); - - try { - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture updateActivityToTargets( + Token token, FeedID feed, Activity activity, FeedID[] add, FeedID[] remove, FeedID[] replace) + throws StreamException { + checkNotNull(activity, "No activity to update"); + checkNotNull(activity.getForeignID(), "Activity is required to have foreign ID attribute"); + checkNotNull(activity.getTime(), "Activity is required to have time attribute"); + checkNotNull(add, "No targets to add"); + checkNotNull(remove, "No targets to remove"); + checkNotNull(replace, "No targets to set"); + boolean modification = replace.length == 0 && (add.length > 0 || remove.length > 0); + boolean replacement = replace.length > 0 && add.length == 0 && remove.length == 0; + checkArgument( + modification || replacement, + "Can't replace and modify activity to targets at the same time"); + + final String[] addedTargets = + J8Arrays.stream(add).map(id -> id.toString()).toArray(String[]::new); + final String[] removedTargets = + J8Arrays.stream(remove).map(id -> id.toString()).toArray(String[]::new); + final String[] newTargets = + J8Arrays.stream(replace).map(id -> id.toString()).toArray(String[]::new); + + try { + final byte[] payload = + toJSON( + new Object() { public String foreign_id = activity.getForeignID(); - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", lenient = OptBoolean.FALSE, timezone = "UTC") + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") public Date time = activity.getTime(); + public String[] added_targets = addedTargets; public String[] removed_targets = removedTargets; public String[] new_targets = newTargets; - }); - final URL url = buildToTargetUpdateURL(baseURL, feed); - return httpClient.execute(buildPost(url, key, token, payload)); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildToTargetUpdateURL(baseURL, feed); + return httpClient.execute(buildPost(url, key, token, payload)); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture getUser(Token token, String id, boolean withFollowCounts) throws StreamException { - checkNotNull(id, "Missing user ID"); - checkArgument(!id.isEmpty(), "Missing user ID"); - - try { - final URL url = buildUsersURL(baseURL, id + '/'); - return httpClient.execute(buildGet(url, key, token, new CustomQueryParameter("with_follow_counts", Boolean.toString(withFollowCounts)))); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture getUser(Token token, String id, boolean withFollowCounts) + throws StreamException { + checkNotNull(id, "Missing user ID"); + checkArgument(!id.isEmpty(), "Missing user ID"); + + try { + final URL url = buildUsersURL(baseURL, id + '/'); + return httpClient.execute( + buildGet( + url, + key, + token, + new CustomQueryParameter("with_follow_counts", Boolean.toString(withFollowCounts)))); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture deleteUser(Token token, String id) throws StreamException { - checkNotNull(id, "Missing user ID"); - checkArgument(!id.isEmpty(), "Missing user ID"); + public CompletableFuture deleteUser(Token token, String id) throws StreamException { + checkNotNull(id, "Missing user ID"); + checkArgument(!id.isEmpty(), "Missing user ID"); - try { - final URL url = buildUsersURL(baseURL, id + '/'); - return httpClient.execute(buildDelete(url, key, token)); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildUsersURL(baseURL, id + '/'); + return httpClient.execute(buildDelete(url, key, token)); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture createUser(Token token, String userID, Data userData, boolean getOrCreate) throws StreamException { - checkNotNull(userID, "Missing user ID"); - checkNotNull(userData, "Missing user data"); - checkArgument(!userID.isEmpty(), "Missing user ID"); - - try { - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture createUser( + Token token, String userID, Data userData, boolean getOrCreate) throws StreamException { + checkNotNull(userID, "Missing user ID"); + checkNotNull(userData, "Missing user data"); + checkArgument(!userID.isEmpty(), "Missing user ID"); + + try { + final byte[] payload = + toJSON( + new Object() { public String id = userID; public Map data = userData.getData(); - }); - final URL url = buildUsersURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload, new CustomQueryParameter("get_or_create", Boolean.toString(getOrCreate)))); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildUsersURL(baseURL); + return httpClient.execute( + buildPost( + url, + key, + token, + payload, + new CustomQueryParameter("get_or_create", Boolean.toString(getOrCreate)))); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture updateUser(Token token, String userID, Data userData) throws StreamException { - checkNotNull(userID, "Missing user ID"); - checkNotNull(userData, "Missing user data"); - checkArgument(!userID.isEmpty(), "Missing user ID"); - - try { - final byte[] payload = toJSON(new Object() { + } + + public CompletableFuture updateUser(Token token, String userID, Data userData) + throws StreamException { + checkNotNull(userID, "Missing user ID"); + checkNotNull(userData, "Missing user data"); + checkArgument(!userID.isEmpty(), "Missing user ID"); + + try { + final byte[] payload = + toJSON( + new Object() { public Map data = userData.getData(); - }); - final URL url = buildUsersURL(baseURL, userID + '/'); - return httpClient.execute(buildPut(url, key, token, payload)); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildUsersURL(baseURL, userID + '/'); + return httpClient.execute(buildPut(url, key, token, payload)); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamAnalytics.java b/src/main/java/io/getstream/core/StreamAnalytics.java index 9434ec88..8e0e22dd 100644 --- a/src/main/java/io/getstream/core/StreamAnalytics.java +++ b/src/main/java/io/getstream/core/StreamAnalytics.java @@ -1,5 +1,12 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.buildPost; +import static io.getstream.core.utils.Routes.buildAnalyticsURL; +import static io.getstream.core.utils.Serialization.deserializeError; +import static io.getstream.core.utils.Serialization.toJSON; + import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.base.Charsets; import com.google.common.collect.ObjectArrays; @@ -8,86 +15,89 @@ import io.getstream.core.http.Token; import io.getstream.core.models.Engagement; import io.getstream.core.models.Impression; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.buildPost; -import static io.getstream.core.utils.Routes.buildAnalyticsURL; -import static io.getstream.core.utils.Serialization.deserializeError; -import static io.getstream.core.utils.Serialization.toJSON; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class StreamAnalytics { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; - StreamAnalytics(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } + StreamAnalytics(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } - public CompletableFuture trackEngagement(Token token, Engagement... events) throws StreamException { - checkNotNull(events, "No events to track"); - checkArgument(events.length > 0, "No events to track"); + public CompletableFuture trackEngagement(Token token, Engagement... events) + throws StreamException { + checkNotNull(events, "No events to track"); + checkArgument(events.length > 0, "No events to track"); - try { - final byte[] payload = toJSON(new Object() { + try { + final byte[] payload = + toJSON( + new Object() { public final Engagement[] content_list = events; - }); - final URL url = buildAnalyticsURL(baseURL, "engagement/"); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildAnalyticsURL(baseURL, "engagement/"); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture trackImpression(Token token, Impression event) throws StreamException { - checkNotNull(event, "No events to track"); + public CompletableFuture trackImpression(Token token, Impression event) + throws StreamException { + checkNotNull(event, "No events to track"); - try { - final byte[] payload = toJSON(event); - final URL url = buildAnalyticsURL(baseURL, "impression/"); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final byte[] payload = toJSON(event); + final URL url = buildAnalyticsURL(baseURL, "impression/"); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public URL createRedirectURL(Token token, URL url, Impression[] impressions, Engagement[] engagements) throws StreamException { - try { - final byte[] events = toJSON(ObjectArrays.concat(impressions, engagements, Object.class)); - return HTTPClient.requestBuilder() - .url(buildAnalyticsURL(baseURL, "redirect/")) - .addQueryParameter("api_key", key) - .addQueryParameter("url", url.toExternalForm()) - .addQueryParameter("events", new String(events, Charsets.UTF_8)) - .addQueryParameter("auth_type", "jwt") - .addQueryParameter("authorization", token.toString()) - .build().getURL(); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + public URL createRedirectURL( + Token token, URL url, Impression[] impressions, Engagement[] engagements) + throws StreamException { + try { + final byte[] events = toJSON(ObjectArrays.concat(impressions, engagements, Object.class)); + return HTTPClient.requestBuilder() + .url(buildAnalyticsURL(baseURL, "redirect/")) + .addQueryParameter("api_key", key) + .addQueryParameter("url", url.toExternalForm()) + .addQueryParameter("events", new String(events, Charsets.UTF_8)) + .addQueryParameter("auth_type", "jwt") + .addQueryParameter("authorization", token.toString()) + .build() + .getURL(); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamBatch.java b/src/main/java/io/getstream/core/StreamBatch.java index af8de96c..1abf5535 100644 --- a/src/main/java/io/getstream/core/StreamBatch.java +++ b/src/main/java/io/getstream/core/StreamBatch.java @@ -1,5 +1,12 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.buildGet; +import static io.getstream.core.utils.Request.buildPost; +import static io.getstream.core.utils.Routes.*; +import static io.getstream.core.utils.Serialization.*; + import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.base.Joiner; import io.getstream.core.exceptions.StreamException; @@ -8,10 +15,6 @@ import io.getstream.core.models.*; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.RequestOption; -import java8.util.J8Arrays; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -19,218 +22,265 @@ import java.text.SimpleDateFormat; import java.util.List; import java.util.TimeZone; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.buildGet; -import static io.getstream.core.utils.Request.buildPost; -import static io.getstream.core.utils.Routes.*; -import static io.getstream.core.utils.Serialization.*; +import java8.util.J8Arrays; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public final class StreamBatch { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; - - public StreamBatch(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; + + public StreamBatch(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } - public CompletableFuture addToMany(Token token, Activity activity, FeedID... feeds) throws StreamException { - checkNotNull(activity, "Missing activity"); - checkNotNull(feeds, "No feeds to add to"); - checkArgument(feeds.length > 0, "No feeds to add to"); + public CompletableFuture addToMany(Token token, Activity activity, FeedID... feeds) + throws StreamException { + checkNotNull(activity, "Missing activity"); + checkNotNull(feeds, "No feeds to add to"); + checkArgument(feeds.length > 0, "No feeds to add to"); - //XXX: renaming the variable so we can unambiguously name payload field 'activity' - Activity data = activity; - String[] feedIDs = J8Arrays.stream(feeds).map(feed -> feed.toString()).toArray(String[]::new); - try { - final byte[] payload = toJSON(new Object() { + // XXX: renaming the variable so we can unambiguously name payload field 'activity' + Activity data = activity; + String[] feedIDs = J8Arrays.stream(feeds).map(feed -> feed.toString()).toArray(String[]::new); + try { + final byte[] payload = + toJSON( + new Object() { public final Activity activity = data; public final String[] feeds = feedIDs; - }); - final URL url = buildAddToManyURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildAddToManyURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture followMany(Token token, int activityCopyLimit, FollowRelation... follows) throws StreamException { - checkArgument(activityCopyLimit >= 0, "Activity copy limit must be non negative"); - checkNotNull(follows, "No feeds to follow"); - checkArgument(follows.length > 0, "No feeds to follow"); - - try { - final byte[] payload = toJSON(follows); - final URL url = buildFollowManyURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload, new CustomQueryParameter("activity_copy_limit", Integer.toString(activityCopyLimit)))) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + public CompletableFuture followMany( + Token token, int activityCopyLimit, FollowRelation... follows) throws StreamException { + checkArgument(activityCopyLimit >= 0, "Activity copy limit must be non negative"); + checkNotNull(follows, "No feeds to follow"); + checkArgument(follows.length > 0, "No feeds to follow"); + + try { + final byte[] payload = toJSON(follows); + final URL url = buildFollowManyURL(baseURL); + return httpClient + .execute( + buildPost( + url, + key, + token, + payload, + new CustomQueryParameter( + "activity_copy_limit", Integer.toString(activityCopyLimit)))) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture unfollowMany(Token token, UnfollowOperation... unfollows) + throws StreamException { + checkNotNull(unfollows, "No feeds to unfollow"); + checkArgument(unfollows.length > 0, "No feeds to unfollow"); - public CompletableFuture unfollowMany(Token token, UnfollowOperation... unfollows) throws StreamException { - checkNotNull(unfollows, "No feeds to unfollow"); - checkArgument(unfollows.length > 0, "No feeds to unfollow"); - - try { - final byte[] payload = toJSON(unfollows); - final URL url = buildUnfollowManyURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final byte[] payload = toJSON(unfollows); + final URL url = buildUnfollowManyURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture> getActivitiesByID(Token token, String... activityIDs) throws StreamException { - checkNotNull(activityIDs, "No activities to get"); - checkArgument(activityIDs.length > 0, "No activities to get"); - - try { - final URL url = buildActivitiesURL(baseURL); - return httpClient.execute(buildGet(url, key, token, new CustomQueryParameter("ids", Joiner.on(",").join(activityIDs)))) - .thenApply(response -> { - try { - return deserializeContainer(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + public CompletableFuture> getActivitiesByID(Token token, String... activityIDs) + throws StreamException { + checkNotNull(activityIDs, "No activities to get"); + checkArgument(activityIDs.length > 0, "No activities to get"); + + try { + final URL url = buildActivitiesURL(baseURL); + return httpClient + .execute( + buildGet( + url, + key, + token, + new CustomQueryParameter("ids", Joiner.on(",").join(activityIDs)))) + .thenApply( + response -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture> getEnrichedActivitiesByID( + Token token, String... activityIDs) throws StreamException { + checkNotNull(activityIDs, "No activities to get"); + checkArgument(activityIDs.length > 0, "No activities to get"); - public CompletableFuture> getEnrichedActivitiesByID(Token token, String... activityIDs) throws StreamException { - checkNotNull(activityIDs, "No activities to get"); - checkArgument(activityIDs.length > 0, "No activities to get"); - - try { - final URL url = buildEnrichedActivitiesURL(baseURL); - return httpClient.execute(buildGet(url, key, token, new CustomQueryParameter("ids", Joiner.on(",").join(activityIDs)))) - .thenApply(response -> { - try { - return deserializeContainer(response, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildEnrichedActivitiesURL(baseURL); + return httpClient + .execute( + buildGet( + url, + key, + token, + new CustomQueryParameter("ids", Joiner.on(",").join(activityIDs)))) + .thenApply( + response -> { + try { + return deserializeContainer(response, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture> getActivitiesByForeignID( + Token token, ForeignIDTimePair... activityIDTimePairs) throws StreamException { + checkNotNull(activityIDTimePairs, "No activities to get"); + checkArgument(activityIDTimePairs.length > 0, "No activities to get"); + + SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); + timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + timestampFormat.setLenient(false); - public CompletableFuture> getActivitiesByForeignID(Token token, ForeignIDTimePair... activityIDTimePairs) throws StreamException { - checkNotNull(activityIDTimePairs, "No activities to get"); - checkArgument(activityIDTimePairs.length > 0, "No activities to get"); - - SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); - timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - timestampFormat.setLenient(false); - - String[] foreignIDs = J8Arrays.stream(activityIDTimePairs) - .map(pair -> pair.getForeignID()) - .toArray(String[]::new); - String[] timestamps = J8Arrays.stream(activityIDTimePairs) - .map(pair -> timestampFormat.format(pair.getTime())) - .toArray(String[]::new); - try { - final URL url = buildActivitiesURL(baseURL); - final RequestOption[] options = new RequestOption[]{ - new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)), - new CustomQueryParameter("timestamps", Joiner.on(",").join(timestamps)) - }; - return httpClient.execute(buildGet(url, key, token, options)) - .thenApply(response -> { - try { - return deserializeContainer(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + String[] foreignIDs = + J8Arrays.stream(activityIDTimePairs) + .map(pair -> pair.getForeignID()) + .toArray(String[]::new); + String[] timestamps = + J8Arrays.stream(activityIDTimePairs) + .map(pair -> timestampFormat.format(pair.getTime())) + .toArray(String[]::new); + try { + final URL url = buildActivitiesURL(baseURL); + final RequestOption[] options = + new RequestOption[] { + new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)), + new CustomQueryParameter("timestamps", Joiner.on(",").join(timestamps)) + }; + return httpClient + .execute(buildGet(url, key, token, options)) + .thenApply( + response -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture> getEnrichedActivitiesByForeignID(Token token, ForeignIDTimePair... activityIDTimePairs) throws StreamException { - checkNotNull(activityIDTimePairs, "No activities to get"); - checkArgument(activityIDTimePairs.length > 0, "No activities to get"); + public CompletableFuture> getEnrichedActivitiesByForeignID( + Token token, ForeignIDTimePair... activityIDTimePairs) throws StreamException { + checkNotNull(activityIDTimePairs, "No activities to get"); + checkArgument(activityIDTimePairs.length > 0, "No activities to get"); - SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); - timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - timestampFormat.setLenient(false); + SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); + timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + timestampFormat.setLenient(false); - String[] foreignIDs = J8Arrays.stream(activityIDTimePairs) + String[] foreignIDs = + J8Arrays.stream(activityIDTimePairs) .map(pair -> pair.getForeignID()) .toArray(String[]::new); - String[] timestamps = J8Arrays.stream(activityIDTimePairs) + String[] timestamps = + J8Arrays.stream(activityIDTimePairs) .map(pair -> timestampFormat.format(pair.getTime())) .toArray(String[]::new); - try { - final URL url = buildEnrichedActivitiesURL(baseURL); - final RequestOption[] options = new RequestOption[]{ - new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)), - new CustomQueryParameter("timestamps", Joiner.on(",").join(timestamps)) - }; - return httpClient.execute(buildGet(url, key, token, options)) - .thenApply(response -> { - try { - return deserializeContainer(response, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildEnrichedActivitiesURL(baseURL); + final RequestOption[] options = + new RequestOption[] { + new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)), + new CustomQueryParameter("timestamps", Joiner.on(",").join(timestamps)) + }; + return httpClient + .execute(buildGet(url, key, token, options)) + .thenApply( + response -> { + try { + return deserializeContainer(response, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture updateActivities(Token token, Activity... activities) throws StreamException { - checkNotNull(activities, "No activities to update"); - checkArgument(activities.length > 0, "No activities to update"); + public CompletableFuture updateActivities(Token token, Activity... activities) + throws StreamException { + checkNotNull(activities, "No activities to update"); + checkArgument(activities.length > 0, "No activities to update"); - try { - //XXX: renaming the variable so we can unambiguously name payload field 'activities' - Activity[] data = activities; - final byte[] payload = toJSON(new Object() { + try { + // XXX: renaming the variable so we can unambiguously name payload field 'activities' + Activity[] data = activities; + final byte[] payload = + toJSON( + new Object() { public final Activity[] activities = data; - }); - final URL url = buildActivitiesURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildActivitiesURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamCollections.java b/src/main/java/io/getstream/core/StreamCollections.java index 0a2a5fd3..c00e982f 100644 --- a/src/main/java/io/getstream/core/StreamCollections.java +++ b/src/main/java/io/getstream/core/StreamCollections.java @@ -1,5 +1,12 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.*; +import static io.getstream.core.utils.Routes.buildBatchCollectionsURL; +import static io.getstream.core.utils.Routes.buildCollectionsURL; +import static io.getstream.core.utils.Serialization.*; + import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; @@ -9,200 +16,223 @@ import io.getstream.core.models.CollectionData; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.RequestOption; -import java8.util.J8Arrays; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; -import java8.util.stream.Collectors; - import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.util.List; import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.*; -import static io.getstream.core.utils.Routes.buildBatchCollectionsURL; -import static io.getstream.core.utils.Routes.buildCollectionsURL; -import static io.getstream.core.utils.Serialization.*; +import java8.util.J8Arrays; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; +import java8.util.stream.Collectors; public final class StreamCollections { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; - - StreamCollections(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; + + StreamCollections(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } + + public CompletableFuture add( + Token token, String userID, String collection, CollectionData item) throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkNotNull(item, "Collection data can't be null"); + + try { + ImmutableMap.Builder builder = + new ImmutableMap.Builder().put("data", item.getData()); + if (userID != null) { + builder.put("user_id", userID); + } + if (item.getID() != null) { + builder.put("id", item.getID()); + } + final byte[] payload = toJSON(builder.build()); + final URL url = buildCollectionsURL(baseURL, collection + '/'); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserialize(response, CollectionData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture add(Token token, String userID, String collection, CollectionData item) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkNotNull(item, "Collection data can't be null"); - - try { - ImmutableMap.Builder builder = new ImmutableMap.Builder() - .put("data", item.getData()); - if (userID != null) { - builder.put("user_id", userID); - } - if (item.getID() != null) { - builder.put("id", item.getID()); - } - final byte[] payload = toJSON(builder.build()); - final URL url = buildCollectionsURL(baseURL, collection + '/'); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserialize(response, CollectionData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture update( + Token token, String userID, String collection, CollectionData item) throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkNotNull(item, "Collection data can't be null"); + + try { + ImmutableMap.Builder builder = + new ImmutableMap.Builder().put("data", item.getData()); + if (userID != null) { + builder.put("user_id", userID); + } + final byte[] payload = toJSON(builder.build()); + final URL url = buildCollectionsURL(baseURL, collection + '/' + item.getID() + '/'); + return httpClient + .execute(buildPut(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserialize(response, CollectionData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture update(Token token, String userID, String collection, CollectionData item) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkNotNull(item, "Collection data can't be null"); - - try { - ImmutableMap.Builder builder = new ImmutableMap.Builder() - .put("data", item.getData()); - if (userID != null) { - builder.put("user_id", userID); - } - final byte[] payload = toJSON(builder.build()); - final URL url = buildCollectionsURL(baseURL, collection + '/' + item.getID() + '/'); - return httpClient.execute(buildPut(url, key, token, payload)) - .thenApply(response -> { - try { - return deserialize(response, CollectionData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture upsert(Token token, String collection, CollectionData... items) + throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkArgument(items.length > 0, "Collection data can't be empty"); + + try { + final byte[] payload = + toJSON( + new Object() { + public final Map data = + ImmutableMap.of(collection, items); + }); + final URL url = buildBatchCollectionsURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture upsert(Token token, String collection, CollectionData... items) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkArgument(items.length > 0, "Collection data can't be empty"); - - try { - final byte[] payload = toJSON(new Object() { - public final Map data = ImmutableMap.of(collection, items); - }); - final URL url = buildBatchCollectionsURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture get(Token token, String collection, String id) + throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkNotNull(id, "Collection id can't be null"); + checkArgument(!id.isEmpty(), "Collection id can't be empty"); + + try { + final URL url = buildCollectionsURL(baseURL, collection + '/' + id + '/'); + return httpClient + .execute(buildGet(url, key, token)) + .thenApply( + response -> { + try { + return deserialize(response, CollectionData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture get(Token token, String collection, String id) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkNotNull(id, "Collection id can't be null"); - checkArgument(!id.isEmpty(), "Collection id can't be empty"); - - try { - final URL url = buildCollectionsURL(baseURL, collection + '/' + id + '/'); - return httpClient.execute(buildGet(url, key, token)) - .thenApply(response -> { - try { - return deserialize(response, CollectionData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture> select( + Token token, String collection, String... ids) throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkArgument(ids.length > 0, "Collection ids can't be empty"); + + List foreignIDs = + J8Arrays.stream(ids) + .map(id -> String.format("%s:%s", collection, id)) + .collect(Collectors.toList()); + try { + final URL url = buildBatchCollectionsURL(baseURL); + return httpClient + .execute( + buildGet( + url, + key, + token, + new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)))) + .thenApply( + response -> { + try { + return deserializeContainer(response, "response.data", CollectionData.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture> select(Token token, String collection, String... ids) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkArgument(ids.length > 0, "Collection ids can't be empty"); - - List foreignIDs = J8Arrays.stream(ids) - .map(id -> String.format("%s:%s", collection, id)) - .collect(Collectors.toList()); - try { - final URL url = buildBatchCollectionsURL(baseURL); - return httpClient.execute(buildGet(url, key, token, new CustomQueryParameter("foreign_ids", Joiner.on(",").join(foreignIDs)))) - .thenApply(response -> { - try { - return deserializeContainer(response, "response.data", CollectionData.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture delete(Token token, String collection, String id) + throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkNotNull(id, "Collection id can't be null"); + checkArgument(!id.isEmpty(), "Collection id can't be empty"); + + try { + final URL url = buildCollectionsURL(baseURL, collection + '/' + id + '/'); + return httpClient + .execute(buildDelete(url, key, token)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } - - public CompletableFuture delete(Token token, String collection, String id) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkNotNull(id, "Collection id can't be null"); - checkArgument(!id.isEmpty(), "Collection id can't be empty"); - - try { - final URL url = buildCollectionsURL(baseURL, collection + '/' + id + '/'); - return httpClient.execute(buildDelete(url, key, token)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } - } - - public CompletableFuture deleteMany(Token token, String collection, String... ids) throws StreamException { - checkNotNull(collection, "Collection name can't be null"); - checkArgument(!collection.isEmpty(), "Collection name can't be empty"); - checkArgument(ids.length > 0, "Collection ids can't be empty"); - - try { - final URL url = buildBatchCollectionsURL(baseURL); - final RequestOption[] options = new RequestOption[]{ - new CustomQueryParameter("collection_name", collection), - new CustomQueryParameter("ids", Joiner.on(",").join(ids)) - }; - return httpClient.execute(buildDelete(url, key, token, options)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + } + + public CompletableFuture deleteMany(Token token, String collection, String... ids) + throws StreamException { + checkNotNull(collection, "Collection name can't be null"); + checkArgument(!collection.isEmpty(), "Collection name can't be empty"); + checkArgument(ids.length > 0, "Collection ids can't be empty"); + + try { + final URL url = buildBatchCollectionsURL(baseURL); + final RequestOption[] options = + new RequestOption[] { + new CustomQueryParameter("collection_name", collection), + new CustomQueryParameter("ids", Joiner.on(",").join(ids)) + }; + return httpClient + .execute(buildDelete(url, key, token, options)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamFiles.java b/src/main/java/io/getstream/core/StreamFiles.java index d8d06495..0da2318c 100644 --- a/src/main/java/io/getstream/core/StreamFiles.java +++ b/src/main/java/io/getstream/core/StreamFiles.java @@ -1,90 +1,98 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.buildDelete; +import static io.getstream.core.utils.Request.buildMultiPartPost; +import static io.getstream.core.utils.Routes.buildFilesURL; +import static io.getstream.core.utils.Serialization.deserialize; +import static io.getstream.core.utils.Serialization.deserializeError; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.HTTPClient; import io.getstream.core.http.Token; import io.getstream.core.options.CustomQueryParameter; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.buildDelete; -import static io.getstream.core.utils.Request.buildMultiPartPost; -import static io.getstream.core.utils.Routes.buildFilesURL; -import static io.getstream.core.utils.Serialization.deserialize; -import static io.getstream.core.utils.Serialization.deserializeError; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class StreamFiles { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; - StreamFiles(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } + StreamFiles(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } - public CompletableFuture upload(Token token, String fileName, byte[] content) throws StreamException { - checkNotNull(content, "No data to upload"); - checkArgument(content.length > 0, "No data to upload"); + public CompletableFuture upload(Token token, String fileName, byte[] content) + throws StreamException { + checkNotNull(content, "No data to upload"); + checkArgument(content.length > 0, "No data to upload"); - try { - final URL url = buildFilesURL(baseURL); - return httpClient.execute(buildMultiPartPost(url, key, token, fileName, content)) - .thenApply(response -> { - try { - return deserialize(response, "file", URL.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFilesURL(baseURL); + return httpClient + .execute(buildMultiPartPost(url, key, token, fileName, content)) + .thenApply( + response -> { + try { + return deserialize(response, "file", URL.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture upload(Token token, File content) throws StreamException { - checkNotNull(content, "No file to upload"); - checkArgument(content.exists(), "No file to upload"); + public CompletableFuture upload(Token token, File content) throws StreamException { + checkNotNull(content, "No file to upload"); + checkArgument(content.exists(), "No file to upload"); - try { - final URL url = buildFilesURL(baseURL); - return httpClient.execute(buildMultiPartPost(url, key, token, content)) - .thenApply(response -> { - try { - return deserialize(response, "file", URL.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFilesURL(baseURL); + return httpClient + .execute(buildMultiPartPost(url, key, token, content)) + .thenApply( + response -> { + try { + return deserialize(response, "file", URL.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture delete(Token token, URL targetURL) throws StreamException { - checkNotNull(targetURL, "No file to delete"); + public CompletableFuture delete(Token token, URL targetURL) throws StreamException { + checkNotNull(targetURL, "No file to delete"); - try { - final URL url = buildFilesURL(baseURL); - return httpClient.execute(buildDelete(url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildFilesURL(baseURL); + return httpClient + .execute( + buildDelete( + url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamImages.java b/src/main/java/io/getstream/core/StreamImages.java index 121c203f..0fbb2e88 100644 --- a/src/main/java/io/getstream/core/StreamImages.java +++ b/src/main/java/io/getstream/core/StreamImages.java @@ -1,108 +1,125 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.*; +import static io.getstream.core.utils.Routes.buildImagesURL; +import static io.getstream.core.utils.Serialization.deserialize; +import static io.getstream.core.utils.Serialization.deserializeError; + import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.HTTPClient; import io.getstream.core.http.Token; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.RequestOption; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; - import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.*; -import static io.getstream.core.utils.Routes.buildImagesURL; -import static io.getstream.core.utils.Serialization.deserialize; -import static io.getstream.core.utils.Serialization.deserializeError; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; public class StreamImages { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; - StreamImages(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } + StreamImages(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } - public CompletableFuture upload(Token token, String fileName, byte[] content) throws StreamException { - checkNotNull(content, "No data to upload"); - checkArgument(content.length > 0, "No data to upload"); + public CompletableFuture upload(Token token, String fileName, byte[] content) + throws StreamException { + checkNotNull(content, "No data to upload"); + checkArgument(content.length > 0, "No data to upload"); - try { - final URL url = buildImagesURL(baseURL); - return httpClient.execute(buildMultiPartPost(url, key, token, fileName, content)) - .thenApply(response -> { - try { - return deserialize(response, "file", URL.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildImagesURL(baseURL); + return httpClient + .execute(buildMultiPartPost(url, key, token, fileName, content)) + .thenApply( + response -> { + try { + return deserialize(response, "file", URL.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture upload(Token token, File content) throws StreamException { - checkNotNull(content, "No file to upload"); - checkArgument(content.exists(), "No file to upload"); + public CompletableFuture upload(Token token, File content) throws StreamException { + checkNotNull(content, "No file to upload"); + checkArgument(content.exists(), "No file to upload"); - try { - final URL url = buildImagesURL(baseURL); - return httpClient.execute(buildMultiPartPost(url, key, token, content)) - .thenApply(response -> { - try { - return deserialize(response, "file", URL.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildImagesURL(baseURL); + return httpClient + .execute(buildMultiPartPost(url, key, token, content)) + .thenApply( + response -> { + try { + return deserialize(response, "file", URL.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture delete(Token token, URL targetURL) throws StreamException { - checkNotNull(targetURL, "No image to delete"); + public CompletableFuture delete(Token token, URL targetURL) throws StreamException { + checkNotNull(targetURL, "No image to delete"); - try { - final URL url = buildImagesURL(baseURL); - return httpClient.execute(buildDelete(url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildImagesURL(baseURL); + return httpClient + .execute( + buildDelete( + url, key, token, new CustomQueryParameter("url", targetURL.toExternalForm()))) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture process(Token token, URL targetURL, RequestOption option) throws StreamException { - checkNotNull(targetURL, "No image to process"); + public CompletableFuture process(Token token, URL targetURL, RequestOption option) + throws StreamException { + checkNotNull(targetURL, "No image to process"); - try { - final URL url = buildImagesURL(baseURL); - return httpClient.execute(buildGet(url, key, token, option, new CustomQueryParameter("url", targetURL.toExternalForm()))) - .thenApply(response -> { - try { - return deserialize(response, "file", URL.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildImagesURL(baseURL); + return httpClient + .execute( + buildGet( + url, + key, + token, + option, + new CustomQueryParameter("url", targetURL.toExternalForm()))) + .thenApply( + response -> { + try { + return deserialize(response, "file", URL.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamPersonalization.java b/src/main/java/io/getstream/core/StreamPersonalization.java index c2ec481e..b3f24663 100644 --- a/src/main/java/io/getstream/core/StreamPersonalization.java +++ b/src/main/java/io/getstream/core/StreamPersonalization.java @@ -1,5 +1,11 @@ package io.getstream.core; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.*; +import static io.getstream.core.utils.Routes.buildPersonalizationURL; +import static io.getstream.core.utils.Serialization.*; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.getstream.core.exceptions.StreamException; @@ -7,103 +13,117 @@ import io.getstream.core.http.Token; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.RequestOption; -import java8.util.concurrent.CompletableFuture; -import java8.util.concurrent.CompletionException; -import java8.util.stream.StreamSupport; - import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.*; -import static io.getstream.core.utils.Routes.buildPersonalizationURL; -import static io.getstream.core.utils.Serialization.*; +import java8.util.concurrent.CompletableFuture; +import java8.util.concurrent.CompletionException; +import java8.util.stream.StreamSupport; public final class StreamPersonalization { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; - StreamPersonalization(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; - } + StreamPersonalization(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } - public CompletableFuture> get(Token token, String userID, String resource, Map params) throws StreamException { - checkNotNull(resource, "Resource can't be empty"); - checkArgument(!resource.isEmpty(), "Resource can't be empty"); - checkNotNull(params, "Missing params"); + public CompletableFuture> get( + Token token, String userID, String resource, Map params) + throws StreamException { + checkNotNull(resource, "Resource can't be empty"); + checkArgument(!resource.isEmpty(), "Resource can't be empty"); + checkNotNull(params, "Missing params"); - try { - final URL url = buildPersonalizationURL(baseURL, resource + '/'); - final RequestOption[] options = StreamSupport.stream(params.entrySet()) - .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) - .toArray(RequestOption[]::new); - return httpClient.execute(buildGet(url, key, token, options)) - .thenApply(response -> { - try { - return deserialize(response, new TypeReference>() {}); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildPersonalizationURL(baseURL, resource + '/'); + final RequestOption[] options = + StreamSupport.stream(params.entrySet()) + .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) + .toArray(RequestOption[]::new); + return httpClient + .execute(buildGet(url, key, token, options)) + .thenApply( + response -> { + try { + return deserialize(response, new TypeReference>() {}); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture post(Token token, String userID, String resource, Map params, Map payload) throws StreamException { - checkNotNull(resource, "Resource can't be empty"); - checkArgument(!resource.isEmpty(), "Resource can't be empty"); - checkNotNull(params, "Missing params"); - checkNotNull(params, "Missing payload"); + public CompletableFuture post( + Token token, + String userID, + String resource, + Map params, + Map payload) + throws StreamException { + checkNotNull(resource, "Resource can't be empty"); + checkArgument(!resource.isEmpty(), "Resource can't be empty"); + checkNotNull(params, "Missing params"); + checkNotNull(params, "Missing payload"); - try { - final byte[] jsonPayload = toJSON(new Object() { + try { + final byte[] jsonPayload = + toJSON( + new Object() { public final Map data = payload; - }); - final URL url = buildPersonalizationURL(baseURL, resource + '/'); - final RequestOption[] options = StreamSupport.stream(params.entrySet()) - .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) - .toArray(RequestOption[]::new); - return httpClient.execute(buildPost(url, key, token, jsonPayload, options)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildPersonalizationURL(baseURL, resource + '/'); + final RequestOption[] options = + StreamSupport.stream(params.entrySet()) + .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) + .toArray(RequestOption[]::new); + return httpClient + .execute(buildPost(url, key, token, jsonPayload, options)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture delete(Token token, String userID, String resource, Map params) throws StreamException { - checkNotNull(resource, "Resource can't be empty"); - checkArgument(!resource.isEmpty(), "Resource can't be empty"); - checkNotNull(params, "Missing params"); + public CompletableFuture delete( + Token token, String userID, String resource, Map params) + throws StreamException { + checkNotNull(resource, "Resource can't be empty"); + checkArgument(!resource.isEmpty(), "Resource can't be empty"); + checkNotNull(params, "Missing params"); - try { - final URL url = buildPersonalizationURL(baseURL, resource + '/'); - final RequestOption[] options = params.entrySet().stream() - .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) - .toArray(RequestOption[]::new); - return httpClient.execute(buildDelete(url, key, token, options)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildPersonalizationURL(baseURL, resource + '/'); + final RequestOption[] options = + params.entrySet().stream() + .map(entry -> new CustomQueryParameter(entry.getKey(), entry.getValue().toString())) + .toArray(RequestOption[]::new); + return httpClient + .execute(buildDelete(url, key, token, options)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/StreamReactions.java b/src/main/java/io/getstream/core/StreamReactions.java index 52183df7..f9efd86c 100644 --- a/src/main/java/io/getstream/core/StreamReactions.java +++ b/src/main/java/io/getstream/core/StreamReactions.java @@ -1,5 +1,12 @@ package io.getstream.core; +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Request.*; +import static io.getstream.core.utils.Routes.buildReactionsURL; +import static io.getstream.core.utils.Serialization.*; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.ImmutableMap; @@ -23,222 +30,245 @@ import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; +public final class StreamReactions { + private final String key; + private final URL baseURL; + private final HTTPClient httpClient; -import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Request.*; -import static io.getstream.core.utils.Routes.buildReactionsURL; -import static io.getstream.core.utils.Serialization.*; + StreamReactions(String key, URL baseURL, HTTPClient httpClient) { + this.key = key; + this.baseURL = baseURL; + this.httpClient = httpClient; + } -public final class StreamReactions { - private final String key; - private final URL baseURL; - private final HTTPClient httpClient; - - StreamReactions(String key, URL baseURL, HTTPClient httpClient) { - this.key = key; - this.baseURL = baseURL; - this.httpClient = httpClient; + public CompletableFuture get(Token token, String id) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); + + try { + final URL url = buildReactionsURL(baseURL, id + '/'); + return httpClient + .execute(buildGet(url, key, token)) + .thenApply( + response -> { + try { + return deserialize(response, Reaction.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture getPaginated(Token token, String id) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - public CompletableFuture get(Token token, String id) throws StreamException { - checkNotNull(id, "Reaction id can't be null"); - checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - - try { - final URL url = buildReactionsURL(baseURL, id + '/'); - return httpClient.execute(buildGet(url, key, token)) - .thenApply(response -> { - try { - return deserialize(response, Reaction.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildReactionsURL(baseURL, id + '/'); + return httpClient + .execute(buildGet(url, key, token)) + .thenApply( + response -> { + try { + return deserialize(response, Paginated.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture> filter( + Token token, LookupKind lookup, String id, Filter filter, Limit limit, String kind) + throws StreamException { + checkNotNull(lookup, "Lookup kind can't be null"); + checkNotNull(id, "Reaction ID can't be null"); + checkArgument(!id.isEmpty(), "Reaction ID can't be empty"); + checkNotNull(filter, "Filter can't be null"); + checkNotNull(kind, "Kind can't be null"); - public CompletableFuture getPaginated(Token token, String id) throws StreamException { - checkNotNull(id, "Reaction id can't be null"); - checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - - try { - final URL url = buildReactionsURL(baseURL, id + '/'); - return httpClient.execute(buildGet(url, key, token)) - .thenApply(response -> { - try { - return deserialize(response, Paginated.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildReactionsURL(baseURL, lookup.getKind() + '/' + id + '/' + kind); + RequestOption withActivityData = + new CustomQueryParameter( + "with_activity_data", Boolean.toString(lookup == LookupKind.ACTIVITY_WITH_DATA)); + return httpClient + .execute(buildGet(url, key, token, filter, limit, withActivityData)) + .thenApply( + response -> { + try { + return deserializeContainer(response, Reaction.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture> filter(Token token, LookupKind lookup, String id, Filter filter, Limit limit, String kind) throws StreamException { - checkNotNull(lookup, "Lookup kind can't be null"); - checkNotNull(id, "Reaction ID can't be null"); - checkArgument(!id.isEmpty(), "Reaction ID can't be empty"); - checkNotNull(filter, "Filter can't be null"); - checkNotNull(kind, "Kind can't be null"); - - try { - final URL url = buildReactionsURL(baseURL, lookup.getKind() + '/' + id + '/' + kind); - RequestOption withActivityData = new CustomQueryParameter("with_activity_data", Boolean.toString(lookup == LookupKind.ACTIVITY_WITH_DATA)); - return httpClient.execute(buildGet(url, key, token, filter, limit, withActivityData)) - .thenApply(response -> { - try { - return deserializeContainer(response, Reaction.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + public CompletableFuture> paginatedFilter( + Token token, LookupKind lookup, String id, Filter filter, Limit limit, String kind) + throws StreamException { + checkNotNull(lookup, "Lookup kind can't be null"); + checkNotNull(id, "Reaction ID can't be null"); + checkArgument(!id.isEmpty(), "Reaction ID can't be empty"); + checkNotNull(filter, "Filter can't be null"); + checkNotNull(kind, "Kind can't be null"); + + try { + final URL url = buildReactionsURL(baseURL, lookup.getKind() + '/' + id + '/' + kind); + RequestOption withActivityData = + new CustomQueryParameter( + "with_activity_data", Boolean.toString(lookup == LookupKind.ACTIVITY_WITH_DATA)); + return httpClient + .execute(buildGet(url, key, token, filter, limit, withActivityData)) + .thenApply( + response -> { + try { + return deserialize(response, new TypeReference>() {}); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture> paginatedFilter(Token token, String next) + throws StreamException { + checkNotNull(next, "next can't be null"); - public CompletableFuture> paginatedFilter(Token token, LookupKind lookup, String id, Filter filter, Limit limit, String kind) throws StreamException { - checkNotNull(lookup, "Lookup kind can't be null"); - checkNotNull(id, "Reaction ID can't be null"); - checkArgument(!id.isEmpty(), "Reaction ID can't be empty"); - checkNotNull(filter, "Filter can't be null"); - checkNotNull(kind, "Kind can't be null"); - - try { - final URL url = buildReactionsURL(baseURL, lookup.getKind() + '/' + id + '/' + kind); - RequestOption withActivityData = new CustomQueryParameter("with_activity_data", Boolean.toString(lookup == LookupKind.ACTIVITY_WITH_DATA)); - return httpClient.execute(buildGet(url, key, token, filter, limit, withActivityData)) - .thenApply(response -> { - try { - return deserialize(response, new TypeReference>() {}); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = new URL(baseURL, next); + return httpClient + .execute(buildGet(url, key, token)) + .thenApply( + response -> { + try { + return deserialize(response, new TypeReference>() {}); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture> paginatedFilter(Token token, String next) throws StreamException { - checkNotNull(next, "next can't be null"); - - try { - final URL url = new URL(baseURL, next); - return httpClient.execute(buildGet(url, key, token)) - .thenApply(response -> { - try { - return deserialize(response, new TypeReference>() {}); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + public CompletableFuture add( + Token token, String userID, Reaction reaction, FeedID... targetFeeds) throws StreamException { + checkNotNull(reaction, "Reaction can't be null"); + checkArgument( + reaction.getActivityID() != null || reaction.getParent() != null, + "Reaction has to either have and activity ID or parent"); + checkArgument( + reaction.getActivityID() == null || reaction.getParent() == null, + "Reaction can't have both activity ID and parent"); + if (reaction.getActivityID() != null) { + checkArgument(!reaction.getActivityID().isEmpty(), "Reaction activity ID can't be empty"); + } + if (reaction.getParent() != null) { + checkArgument(!reaction.getParent().isEmpty(), "Reaction parent can't be empty"); } + checkNotNull(reaction.getKind(), "Reaction kind can't be null"); + checkArgument(!reaction.getKind().isEmpty(), "Reaction kind can't be empty"); - public CompletableFuture add(Token token, String userID, Reaction reaction, FeedID... targetFeeds) throws StreamException { - checkNotNull(reaction, "Reaction can't be null"); - checkArgument(reaction.getActivityID() != null || reaction.getParent() != null, "Reaction has to either have and activity ID or parent"); - checkArgument(reaction.getActivityID() == null || reaction.getParent() == null, "Reaction can't have both activity ID and parent"); - if (reaction.getActivityID() != null) { - checkArgument(!reaction.getActivityID().isEmpty(), "Reaction activity ID can't be empty"); - } - if (reaction.getParent() != null) { - checkArgument(!reaction.getParent().isEmpty(), "Reaction parent can't be empty"); - } - checkNotNull(reaction.getKind(), "Reaction kind can't be null"); - checkArgument(!reaction.getKind().isEmpty(), "Reaction kind can't be empty"); - - String[] targetFeedIDs = J8Arrays.stream(targetFeeds) - .map(feed -> feed.toString()) - .toArray(String[]::new); - - try { - ImmutableMap.Builder payloadBuilder = ImmutableMap.builder(); - payloadBuilder.put("kind", reaction.getKind()); - payloadBuilder.put("target_feeds", targetFeedIDs); - if (reaction.getActivityID() != null) { - payloadBuilder.put("activity_id", reaction.getActivityID()); - } - if (userID != null || reaction.getUserID() != null) { - payloadBuilder.put("user_id", firstNonNull(userID, reaction.getUserID())); - } - if (reaction.getParent() != null) { - payloadBuilder.put("parent", reaction.getParent()); - } - if (reaction.getId() != null) { - payloadBuilder.put("id", reaction.getId()); - } - if (reaction.getExtra() != null) { - payloadBuilder.put("data", reaction.getExtra()); - } - final byte[] payload = toJSON(payloadBuilder.build()); - final URL url = buildReactionsURL(baseURL); - return httpClient.execute(buildPost(url, key, token, payload)) - .thenApply(response -> { - try { - return deserialize(response, Reaction.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + String[] targetFeedIDs = + J8Arrays.stream(targetFeeds).map(feed -> feed.toString()).toArray(String[]::new); + + try { + ImmutableMap.Builder payloadBuilder = ImmutableMap.builder(); + payloadBuilder.put("kind", reaction.getKind()); + payloadBuilder.put("target_feeds", targetFeedIDs); + if (reaction.getActivityID() != null) { + payloadBuilder.put("activity_id", reaction.getActivityID()); + } + if (userID != null || reaction.getUserID() != null) { + payloadBuilder.put("user_id", firstNonNull(userID, reaction.getUserID())); + } + if (reaction.getParent() != null) { + payloadBuilder.put("parent", reaction.getParent()); + } + if (reaction.getId() != null) { + payloadBuilder.put("id", reaction.getId()); + } + if (reaction.getExtra() != null) { + payloadBuilder.put("data", reaction.getExtra()); + } + final byte[] payload = toJSON(payloadBuilder.build()); + final URL url = buildReactionsURL(baseURL); + return httpClient + .execute(buildPost(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserialize(response, Reaction.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } - public CompletableFuture update(Token token, Reaction reaction, FeedID... targetFeeds) throws StreamException { - checkNotNull(reaction, "Reaction can't be null"); - checkNotNull(reaction.getId(), "Reaction id can't be null"); - checkArgument(!reaction.getId().isEmpty(), "Reaction id can't be empty"); + public CompletableFuture update(Token token, Reaction reaction, FeedID... targetFeeds) + throws StreamException { + checkNotNull(reaction, "Reaction can't be null"); + checkNotNull(reaction.getId(), "Reaction id can't be null"); + checkArgument(!reaction.getId().isEmpty(), "Reaction id can't be empty"); - String[] targetFeedIDs = J8Arrays.stream(targetFeeds) - .map(feed -> feed.toString()) - .toArray(String[]::new); + String[] targetFeedIDs = + J8Arrays.stream(targetFeeds).map(feed -> feed.toString()).toArray(String[]::new); - try { - final byte[] payload = toJSON(new Object() { + try { + final byte[] payload = + toJSON( + new Object() { public final Map data = reaction.getExtra(); public final String[] target_feeds = targetFeedIDs; - }); - final URL url = buildReactionsURL(baseURL, reaction.getId() + '/'); - return httpClient.execute(buildPut(url, key, token, payload)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + }); + final URL url = buildReactionsURL(baseURL, reaction.getId() + '/'); + return httpClient + .execute(buildPut(url, key, token, payload)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } + + public CompletableFuture delete(Token token, String id) throws StreamException { + checkNotNull(id, "Reaction id can't be null"); + checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - public CompletableFuture delete(Token token, String id) throws StreamException { - checkNotNull(id, "Reaction id can't be null"); - checkArgument(!id.isEmpty(), "Reaction id can't be empty"); - - try { - final URL url = buildReactionsURL(baseURL, id + '/'); - return httpClient.execute(buildDelete(url, key, token)) - .thenApply(response -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } catch (MalformedURLException | URISyntaxException e) { - throw new StreamException(e); - } + try { + final URL url = buildReactionsURL(baseURL, id + '/'); + return httpClient + .execute(buildDelete(url, key, token)) + .thenApply( + response -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } catch (MalformedURLException | URISyntaxException e) { + throw new StreamException(e); } + } } diff --git a/src/main/java/io/getstream/core/exceptions/StreamAPIException.java b/src/main/java/io/getstream/core/exceptions/StreamAPIException.java index ec8f15db..a1ecb66c 100644 --- a/src/main/java/io/getstream/core/exceptions/StreamAPIException.java +++ b/src/main/java/io/getstream/core/exceptions/StreamAPIException.java @@ -6,55 +6,56 @@ @JsonIgnoreProperties(ignoreUnknown = true) public final class StreamAPIException extends StreamException { - private final int errorCode; - private final int statusCode; - private final String errorName; - - @JsonCreator - public StreamAPIException( - @JsonProperty("detail") String message, - @JsonProperty("code") int errorCode, - @JsonProperty("status_code") int statusCode, - @JsonProperty("exception") String errorName) { - super(formatMessage(message, errorName, errorCode, statusCode)); - - this.errorCode = errorCode; - this.statusCode = statusCode; - this.errorName = errorName; + private final int errorCode; + private final int statusCode; + private final String errorName; + + @JsonCreator + public StreamAPIException( + @JsonProperty("detail") String message, + @JsonProperty("code") int errorCode, + @JsonProperty("status_code") int statusCode, + @JsonProperty("exception") String errorName) { + super(formatMessage(message, errorName, errorCode, statusCode)); + + this.errorCode = errorCode; + this.statusCode = statusCode; + this.errorName = errorName; + } + + private static String formatMessage( + String message, String errorName, int errorCode, int statusCode) { + StringBuilder result = new StringBuilder(); + if (errorName != null && !errorName.isEmpty()) { + result.append(errorName); } + if (message != null && !message.isEmpty()) { + if (result.length() > 0) { + result.append(": "); + } - private static String formatMessage(String message, String errorName, int errorCode, int statusCode) { - StringBuilder result = new StringBuilder(); - if (errorName != null && !errorName.isEmpty()) { - result.append(errorName); - } - if (message != null && !message.isEmpty()) { - if (result.length() > 0) { - result.append(": "); - } - - result.append(message); - } - if (result.length() > 0) { - result.append(" "); - } - result.append("(code = "); - result.append(errorCode); - result.append(" status = "); - result.append(statusCode); - result.append(')'); - return result.toString(); + result.append(message); } - - public int getErrorCode() { - return errorCode; - } - - public int getStatusCode() { - return statusCode; - } - - public String getErrorName() { - return errorName; + if (result.length() > 0) { + result.append(" "); } + result.append("(code = "); + result.append(errorCode); + result.append(" status = "); + result.append(statusCode); + result.append(')'); + return result.toString(); + } + + public int getErrorCode() { + return errorCode; + } + + public int getStatusCode() { + return statusCode; + } + + public String getErrorName() { + return errorName; + } } diff --git a/src/main/java/io/getstream/core/exceptions/StreamException.java b/src/main/java/io/getstream/core/exceptions/StreamException.java index e9a027d8..2833aa81 100644 --- a/src/main/java/io/getstream/core/exceptions/StreamException.java +++ b/src/main/java/io/getstream/core/exceptions/StreamException.java @@ -1,23 +1,24 @@ package io.getstream.core.exceptions; public class StreamException extends Exception { - public StreamException() { - super(); - } + public StreamException() { + super(); + } - public StreamException(String message) { - super(message); - } + public StreamException(String message) { + super(message); + } - public StreamException(String message, Throwable cause) { - super(message, cause); - } + public StreamException(String message, Throwable cause) { + super(message, cause); + } - public StreamException(Throwable cause) { - super(cause); - } + public StreamException(Throwable cause) { + super(cause); + } - protected StreamException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } + protected StreamException( + String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } } diff --git a/src/main/java/io/getstream/core/http/HTTPClient.java b/src/main/java/io/getstream/core/http/HTTPClient.java index 2f417b63..b120065c 100644 --- a/src/main/java/io/getstream/core/http/HTTPClient.java +++ b/src/main/java/io/getstream/core/http/HTTPClient.java @@ -3,11 +3,11 @@ import java8.util.concurrent.CompletableFuture; public abstract class HTTPClient { - public static Request.Builder requestBuilder() { - return Request.builder(); - } + public static Request.Builder requestBuilder() { + return Request.builder(); + } - public abstract T getImplementation(); + public abstract T getImplementation(); - public abstract CompletableFuture execute(Request request); + public abstract CompletableFuture execute(Request request); } diff --git a/src/main/java/io/getstream/core/http/OKHTTPClientAdapter.java b/src/main/java/io/getstream/core/http/OKHTTPClientAdapter.java index f73228ac..84a8b865 100644 --- a/src/main/java/io/getstream/core/http/OKHTTPClientAdapter.java +++ b/src/main/java/io/getstream/core/http/OKHTTPClientAdapter.java @@ -1,116 +1,119 @@ package io.getstream.core.http; -import io.getstream.core.utils.Info; -import java8.util.concurrent.CompletableFuture; -import okhttp3.*; +import static com.google.common.base.Preconditions.checkNotNull; +import io.getstream.core.utils.Info; import java.io.IOException; import java.io.InputStream; import java.net.URLConnection; - -import static com.google.common.base.Preconditions.checkNotNull; +import java8.util.concurrent.CompletableFuture; +import okhttp3.*; public final class OKHTTPClientAdapter extends HTTPClient { - private static final String userAgentTemplate = "okhttp3 stream-java2 %s v%s"; - - private final OkHttpClient client; - - public OKHTTPClientAdapter() { - this.client = new OkHttpClient.Builder() - .followRedirects(false) - .followSslRedirects(false) - .build(); - } - - public OKHTTPClientAdapter(OkHttpClient client) { - checkNotNull(client); - this.client = client; - } - - @Override - public T getImplementation() { - return (T) client; - } - - private okhttp3.RequestBody buildOkHttpRequestBody(io.getstream.core.http.RequestBody body) { - okhttp3.RequestBody okBody = null; - MediaType mediaType; - switch (body.getType()) { - case JSON: - mediaType = MediaType.parse(body.getType().toString()); - okBody = okhttp3.RequestBody.create(mediaType, body.getBytes()); - break; - case MULTI_PART: - String mimeType = URLConnection.guessContentTypeFromName(body.getFileName()); - mediaType = MediaType.parse(mimeType); - MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); - if (body.getBytes() != null) { - builder.addFormDataPart("file", body.getFileName(), okhttp3.RequestBody.create(mediaType, body.getBytes())); - } else { - builder.addFormDataPart("file", body.getFileName(), okhttp3.RequestBody.create(mediaType, body.getFile())); - } - okBody = builder.build(); - break; + private static final String userAgentTemplate = "okhttp3 stream-java2 %s v%s"; + + private final OkHttpClient client; + + public OKHTTPClientAdapter() { + this.client = + new OkHttpClient.Builder().followRedirects(false).followSslRedirects(false).build(); + } + + public OKHTTPClientAdapter(OkHttpClient client) { + checkNotNull(client); + this.client = client; + } + + @Override + public T getImplementation() { + return (T) client; + } + + private okhttp3.RequestBody buildOkHttpRequestBody(io.getstream.core.http.RequestBody body) { + okhttp3.RequestBody okBody = null; + MediaType mediaType; + switch (body.getType()) { + case JSON: + mediaType = MediaType.parse(body.getType().toString()); + okBody = okhttp3.RequestBody.create(mediaType, body.getBytes()); + break; + case MULTI_PART: + String mimeType = URLConnection.guessContentTypeFromName(body.getFileName()); + mediaType = MediaType.parse(mimeType); + MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); + if (body.getBytes() != null) { + builder.addFormDataPart( + "file", body.getFileName(), okhttp3.RequestBody.create(mediaType, body.getBytes())); + } else { + builder.addFormDataPart( + "file", body.getFileName(), okhttp3.RequestBody.create(mediaType, body.getFile())); } - return okBody; + okBody = builder.build(); + break; } - - private okhttp3.Request buildOkHttpRequest(io.getstream.core.http.Request request) { - String version = Info.getProperties().getProperty(Info.VERSION); - String userAgent = String.format(userAgentTemplate, System.getProperty("os.name"), version); - okhttp3.Request.Builder builder = new okhttp3.Request.Builder() - .url(request.getURL()) - .addHeader("Stream-Auth-Type", "jwt") - .addHeader("Authorization", request.getToken().toString()) - .addHeader("User-Agent", userAgent); - - MediaType mediaType; - switch (request.getMethod()) { - case GET: - builder.get(); - break; - case DELETE: - builder.delete(); - break; - case PUT: - builder.put(buildOkHttpRequestBody(request.getBody())); - break; - case POST: - builder.post(buildOkHttpRequestBody(request.getBody())); - break; - } - return builder.build(); + return okBody; + } + + private okhttp3.Request buildOkHttpRequest(io.getstream.core.http.Request request) { + String version = Info.getProperties().getProperty(Info.VERSION); + String userAgent = String.format(userAgentTemplate, System.getProperty("os.name"), version); + okhttp3.Request.Builder builder = + new okhttp3.Request.Builder() + .url(request.getURL()) + .addHeader("Stream-Auth-Type", "jwt") + .addHeader("Authorization", request.getToken().toString()) + .addHeader("User-Agent", userAgent); + + MediaType mediaType; + switch (request.getMethod()) { + case GET: + builder.get(); + break; + case DELETE: + builder.delete(); + break; + case PUT: + builder.put(buildOkHttpRequestBody(request.getBody())); + break; + case POST: + builder.post(buildOkHttpRequestBody(request.getBody())); + break; } - - private io.getstream.core.http.Response buildResponse(okhttp3.Response response) { - final InputStream body = response.body() != null ? response.body().byteStream() : null; - return new io.getstream.core.http.Response(response.code(), body); - } - - @Override - public CompletableFuture execute(io.getstream.core.http.Request request) { - final CompletableFuture result = new CompletableFuture<>(); - - client.newCall(buildOkHttpRequest(request)).enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { + return builder.build(); + } + + private io.getstream.core.http.Response buildResponse(okhttp3.Response response) { + final InputStream body = response.body() != null ? response.body().byteStream() : null; + return new io.getstream.core.http.Response(response.code(), body); + } + + @Override + public CompletableFuture execute( + io.getstream.core.http.Request request) { + final CompletableFuture result = new CompletableFuture<>(); + + client + .newCall(buildOkHttpRequest(request)) + .enqueue( + new Callback() { + @Override + public void onFailure(Call call, IOException e) { result.completeExceptionally(e); - } + } - @Override - public void onResponse(Call call, okhttp3.Response response) { + @Override + public void onResponse(Call call, okhttp3.Response response) { io.getstream.core.http.Response httpResponse = buildResponse(response); try (InputStream ignored = httpResponse.getBody()) { - result.complete(httpResponse); + result.complete(httpResponse); } catch (Exception e) { - result.completeExceptionally(e); + result.completeExceptionally(e); } finally { - response.body().close(); + response.body().close(); } - } - }); + } + }); - return result; - } + return result; + } } - diff --git a/src/main/java/io/getstream/core/http/Request.java b/src/main/java/io/getstream/core/http/Request.java index b16629db..b5b6d40d 100644 --- a/src/main/java/io/getstream/core/http/Request.java +++ b/src/main/java/io/getstream/core/http/Request.java @@ -1,7 +1,6 @@ package io.getstream.core.http; import com.google.common.base.MoreObjects; - import java.io.File; import java.net.MalformedURLException; import java.net.URI; @@ -10,148 +9,150 @@ import java.util.Objects; public final class Request { - private final Token token; - private final URL url; - private final Method method; - private final RequestBody body; - - private Request(Builder builder) throws MalformedURLException { - token = builder.token; - url = builder.uri.toURL(); - method = builder.method; - body = builder.body; - } - - public Token getToken() { - return token; + private final Token token; + private final URL url; + private final Method method; + private final RequestBody body; + + private Request(Builder builder) throws MalformedURLException { + token = builder.token; + url = builder.uri.toURL(); + method = builder.method; + body = builder.body; + } + + public Token getToken() { + return token; + } + + public URL getURL() { + return url; + } + + public Method getMethod() { + return method; + } + + public RequestBody getBody() { + return body; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return Objects.equals(token, request.token) + && Objects.equals(url, request.url) + && method == request.method + && Objects.equals(body, request.body); + } + + @Override + public int hashCode() { + return Objects.hash(token, url, method, body); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("token", this.token) + .add("url", this.url) + .add("method", this.method) + .add("body", this.body) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public enum Method { + GET, + POST, + PUT, + DELETE + } + + public static final class Builder { + private Token token; + private URI uri; + private StringBuilder query; + private Method method; + private RequestBody body; + + public Builder token(Token token) { + this.token = token; + return this; } - public URL getURL() { - return url; + public Builder url(URL url) throws URISyntaxException { + uri = url.toURI(); + if (uri.getQuery() != null) { + query = new StringBuilder(uri.getQuery()); + } else { + query = new StringBuilder(); + } + return this; } - public Method getMethod() { - return method; + public Builder addQueryParameter(String key, String value) { + if (query.length() > 0) { + query.append('&'); + } + query.append(key); + query.append('='); + query.append(value); + return this; } - public RequestBody getBody() { - return body; + public Builder get() { + this.method = Method.GET; + this.body = null; + return this; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Request request = (Request) o; - return Objects.equals(token, request.token) && - Objects.equals(url, request.url) && - method == request.method && - Objects.equals(body, request.body); + public Builder post(byte[] body) { + this.method = Method.POST; + this.body = new RequestBody(body, RequestBody.Type.JSON); + return this; } - @Override - public int hashCode() { - return Objects.hash(token, url, method, body); + public Builder multiPartPost(String fileName, byte[] body) { + this.method = Method.POST; + this.body = new RequestBody(fileName, body, RequestBody.Type.MULTI_PART); + return this; } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("token", this.token) - .add("url", this.url) - .add("method", this.method) - .add("body", this.body) - .toString(); + public Builder multiPartPost(File body) { + this.method = Method.POST; + this.body = new RequestBody(body, RequestBody.Type.MULTI_PART); + return this; } - public static Builder builder() { - return new Builder(); + public Builder put(byte[] body) { + this.method = Method.PUT; + this.body = new RequestBody(body, RequestBody.Type.JSON); + return this; } - public enum Method { - GET, - POST, - PUT, - DELETE + public Builder delete() { + this.method = Method.DELETE; + this.body = null; + return this; } - public static final class Builder { - private Token token; - private URI uri; - private StringBuilder query; - private Method method; - private RequestBody body; - - public Builder token(Token token) { - this.token = token; - return this; - } - - public Builder url(URL url) throws URISyntaxException { - uri = url.toURI(); - if (uri.getQuery() != null) { - query = new StringBuilder(uri.getQuery()); - } else { - query = new StringBuilder(); - } - return this; - } - - public Builder addQueryParameter(String key, String value) { - if (query.length() > 0) { - query.append('&'); - } - query.append(key); - query.append('='); - query.append(value); - return this; - } - - public Builder get() { - this.method = Method.GET; - this.body = null; - return this; - } - - public Builder post(byte[] body) { - this.method = Method.POST; - this.body = new RequestBody(body, RequestBody.Type.JSON); - return this; - } - - public Builder multiPartPost(String fileName, byte[] body) { - this.method = Method.POST; - this.body = new RequestBody(fileName, body, RequestBody.Type.MULTI_PART); - return this; - } - - public Builder multiPartPost(File body) { - this.method = Method.POST; - this.body = new RequestBody(body, RequestBody.Type.MULTI_PART); - return this; - } - - public Builder put(byte[] body) { - this.method = Method.PUT; - this.body = new RequestBody(body, RequestBody.Type.JSON); - return this; - } - - public Builder delete() { - this.method = Method.DELETE; - this.body = null; - return this; - } - - public Request build() throws MalformedURLException, URISyntaxException { - this.uri = new URI(uri.getScheme(), - uri.getUserInfo(), - uri.getHost(), - uri.getPort(), - uri.getPath(), - query.toString(), - null); - return new Request(this); - } + public Request build() throws MalformedURLException, URISyntaxException { + this.uri = + new URI( + uri.getScheme(), + uri.getUserInfo(), + uri.getHost(), + uri.getPort(), + uri.getPath(), + query.toString(), + null); + return new Request(this); } + } } diff --git a/src/main/java/io/getstream/core/http/RequestBody.java b/src/main/java/io/getstream/core/http/RequestBody.java index 515d08a5..2ea521f5 100644 --- a/src/main/java/io/getstream/core/http/RequestBody.java +++ b/src/main/java/io/getstream/core/http/RequestBody.java @@ -1,93 +1,90 @@ package io.getstream.core.http; import com.google.common.base.MoreObjects; - import java.io.File; import java.util.Arrays; import java.util.Objects; public final class RequestBody { - public enum Type { - JSON("application/json"), - MULTI_PART("multipart/form-data"); - - private final String type; - - Type(String type) { - this.type = type; - } - - @Override - public String toString() { - return type; - } - } - - private final Type type; - private final byte[] bytes; - private final File file; - private final String fileName; + public enum Type { + JSON("application/json"), + MULTI_PART("multipart/form-data"); - RequestBody(byte[] bytes, Type type) { - this.type = type; - this.bytes = bytes; - this.file = null; - this.fileName = null; - } - - RequestBody(String fileName, byte[] bytes, Type type) { - this.type = type; - this.bytes = bytes; - this.file = null; - this.fileName = fileName; - } + private final String type; - RequestBody(File file, Type type) { - this.type = type; - this.bytes = null; - this.file = file; - this.fileName = file.getName(); - } - - public Type getType() { - return type; - } - - public byte[] getBytes() { - return bytes; - } - - public File getFile() { - return file; - } - - public String getFileName() { - return fileName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RequestBody that = (RequestBody) o; - return type == that.type && - Arrays.equals(bytes, that.bytes) && - Objects.equals(file, that.file); - } - - @Override - public int hashCode() { - int result = Objects.hash(type, file); - result = 31 * result + Arrays.hashCode(bytes); - return result; + Type(String type) { + this.type = type; } @Override public String toString() { - return MoreObjects.toStringHelper(RequestBody.class) - .add("type", type) - .add("bytes", bytes) - .add("file", file) - .toString(); + return type; } + } + + private final Type type; + private final byte[] bytes; + private final File file; + private final String fileName; + + RequestBody(byte[] bytes, Type type) { + this.type = type; + this.bytes = bytes; + this.file = null; + this.fileName = null; + } + + RequestBody(String fileName, byte[] bytes, Type type) { + this.type = type; + this.bytes = bytes; + this.file = null; + this.fileName = fileName; + } + + RequestBody(File file, Type type) { + this.type = type; + this.bytes = null; + this.file = file; + this.fileName = file.getName(); + } + + public Type getType() { + return type; + } + + public byte[] getBytes() { + return bytes; + } + + public File getFile() { + return file; + } + + public String getFileName() { + return fileName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RequestBody that = (RequestBody) o; + return type == that.type && Arrays.equals(bytes, that.bytes) && Objects.equals(file, that.file); + } + + @Override + public int hashCode() { + int result = Objects.hash(type, file); + result = 31 * result + Arrays.hashCode(bytes); + return result; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(RequestBody.class) + .add("type", type) + .add("bytes", bytes) + .add("file", file) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/http/Response.java b/src/main/java/io/getstream/core/http/Response.java index c530059f..35fbe8bb 100644 --- a/src/main/java/io/getstream/core/http/Response.java +++ b/src/main/java/io/getstream/core/http/Response.java @@ -1,49 +1,47 @@ package io.getstream.core.http; -import com.google.common.base.MoreObjects; +import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.base.MoreObjects; import java.io.InputStream; import java.util.Objects; -import static com.google.common.base.Preconditions.checkArgument; - public final class Response { - private final int code; - private final InputStream body; - - public Response(int code, InputStream body) { - checkArgument(code >= 100 && code <= 599, "Invalid HTTP status code"); - this.code = code; - this.body = body; - } - - public int getCode() { - return code; - } - - public InputStream getBody() { - return body; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Response response = (Response) o; - return code == response.code && - Objects.equals(body, response.body); - } - - @Override - public int hashCode() { - return Objects.hash(code, body); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("code", this.code) - .add("body", this.body) - .toString(); - } + private final int code; + private final InputStream body; + + public Response(int code, InputStream body) { + checkArgument(code >= 100 && code <= 599, "Invalid HTTP status code"); + this.code = code; + this.body = body; + } + + public int getCode() { + return code; + } + + public InputStream getBody() { + return body; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Response response = (Response) o; + return code == response.code && Objects.equals(body, response.body); + } + + @Override + public int hashCode() { + return Objects.hash(code, body); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("code", this.code) + .add("body", this.body) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/http/Token.java b/src/main/java/io/getstream/core/http/Token.java index 32a294b8..8f8db8e8 100644 --- a/src/main/java/io/getstream/core/http/Token.java +++ b/src/main/java/io/getstream/core/http/Token.java @@ -1,35 +1,35 @@ package io.getstream.core.http; -import java.util.Objects; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Objects; + public final class Token { - private final String token; - - public Token(String token) { - checkNotNull(token, "Token can't be null"); - checkArgument(!token.isEmpty(), "Token can't be null"); - - this.token = token; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Token token1 = (Token) o; - return Objects.equals(token, token1.token); - } - - @Override - public int hashCode() { - return Objects.hash(token); - } - - @Override - public String toString() { - return token; - } + private final String token; + + public Token(String token) { + checkNotNull(token, "Token can't be null"); + checkArgument(!token.isEmpty(), "Token can't be null"); + + this.token = token; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Token token1 = (Token) o; + return Objects.equals(token, token1.token); + } + + @Override + public int hashCode() { + return Objects.hash(token); + } + + @Override + public String toString() { + return token; + } } diff --git a/src/main/java/io/getstream/core/models/Activity.java b/src/main/java/io/getstream/core/models/Activity.java index 64419b78..1234c73f 100644 --- a/src/main/java/io/getstream/core/models/Activity.java +++ b/src/main/java/io/getstream/core/models/Activity.java @@ -1,5 +1,8 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -8,259 +11,259 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import io.getstream.core.models.serialization.DateDeserializer; - import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - @JsonInclude(Include.NON_NULL) @JsonDeserialize(builder = Activity.Builder.class) public class Activity { - private final String id; - private final String actor; - private final String verb; - private final String object; - private final String foreignID; - private final String target; - //TODO: support Java 8 Date/Time types? - private final Date time; - private final String origin; - private final List to; - private final Double score; - private final Map extra; - - private Activity(Builder builder) { - id = builder.id; - actor = builder.actor; - verb = builder.verb; - object = builder.object; - foreignID = builder.foreignID; - target = builder.target; - time = builder.time; - origin = builder.origin; - to = builder.to; - score = builder.score; - extra = builder.extra; + private final String id; + private final String actor; + private final String verb; + private final String object; + private final String foreignID; + private final String target; + // TODO: support Java 8 Date/Time types? + private final Date time; + private final String origin; + private final List to; + private final Double score; + private final Map extra; + + private Activity(Builder builder) { + id = builder.id; + actor = builder.actor; + verb = builder.verb; + object = builder.object; + foreignID = builder.foreignID; + target = builder.target; + time = builder.time; + origin = builder.origin; + to = builder.to; + score = builder.score; + extra = builder.extra; + } + + public String getID() { + return id; + } + + public String getActor() { + return actor; + } + + public String getVerb() { + return verb; + } + + public String getObject() { + return object; + } + + @JsonProperty("foreign_id") + public String getForeignID() { + return foreignID; + } + + public String getTarget() { + return target; + } + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") + public Date getTime() { + return time; + } + + public String getOrigin() { + return origin; + } + + public List getTo() { + return to; + } + + public Double getScore() { + return score; + } + + @JsonAnyGetter + public Map getExtra() { + return extra; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Activity activity = (Activity) o; + return Objects.equals(id, activity.id) + && Objects.equals(actor, activity.actor) + && Objects.equals(verb, activity.verb) + && Objects.equals(object, activity.object) + && Objects.equals(foreignID, activity.foreignID) + && Objects.equals(target, activity.target) + && Objects.equals(time, activity.time) + && Objects.equals(origin, activity.origin) + && Objects.equals(to, activity.to) + && Objects.equals(score, activity.score) + && Objects.equals(extra, activity.extra); + } + + @Override + public int hashCode() { + return Objects.hash(id, actor, verb, object, foreignID, target, time, origin, to, score, extra); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", this.id) + .add("actor", this.actor) + .add("verb", this.verb) + .add("object", this.object) + .add("foreignID", this.foreignID) + .add("target", this.target) + .add("time", this.time) + .add("origin", this.origin) + .add("to", this.to) + .add("score", this.score) + .add("extra", this.extra) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static final class Builder { + private String id; + private String actor; + private String verb; + private String object; + private String foreignID; + private String target; + private Date time; + private String origin; + private List to; + private Double score; + private Map extra; + + public Builder id(String id) { + this.id = id; + return this; } - public String getID() { - return id; + public Builder actor(String actor) { + this.actor = actor; + return this; } - public String getActor() { - return actor; + public Builder verb(String verb) { + this.verb = verb; + return this; } - public String getVerb() { - return verb; + public Builder object(String object) { + this.object = object; + return this; } - public String getObject() { - return object; + @JsonProperty("foreign_id") + public Builder foreignID(String foreignID) { + this.foreignID = foreignID; + return this; } - @JsonProperty("foreign_id") - public String getForeignID() { - return foreignID; + public Builder target(String target) { + this.target = target; + return this; } - public String getTarget() { - return target; + @JsonDeserialize(using = DateDeserializer.class) + public Builder time(Date time) { + this.time = time; + return this; } - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", lenient = OptBoolean.FALSE, timezone = "UTC") - public Date getTime() { - return time; + public Builder origin(String origin) { + this.origin = origin; + return this; } - public String getOrigin() { - return origin; + @JsonProperty("to") + public Builder to(List to) { + this.to = to; + return this; } - public List getTo() { - return to; + @JsonIgnore + public Builder to(Iterable to) { + this.to = Lists.newArrayList(to); + return this; } - public Double getScore() { - return score; + @JsonIgnore + public Builder to(FeedID... to) { + this.to = Lists.newArrayList(to); + return this; } - @JsonAnyGetter - public Map getExtra() { - return extra; + public Builder score(double score) { + this.score = score; + return this; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Activity activity = (Activity) o; - return Objects.equals(id, activity.id) && - Objects.equals(actor, activity.actor) && - Objects.equals(verb, activity.verb) && - Objects.equals(object, activity.object) && - Objects.equals(foreignID, activity.foreignID) && - Objects.equals(target, activity.target) && - Objects.equals(time, activity.time) && - Objects.equals(origin, activity.origin) && - Objects.equals(to, activity.to) && - Objects.equals(score, activity.score) && - Objects.equals(extra, activity.extra); + @JsonAnySetter + public Builder extraField(String key, Object value) { + if (extra == null) { + extra = Maps.newHashMap(); + } + extra.put(key, value); + return this; } - @Override - public int hashCode() { - return Objects.hash(id, actor, verb, object, foreignID, target, time, origin, to, score, extra); + @JsonIgnore + public Builder extra(Map extra) { + if (!extra.isEmpty()) { + this.extra = extra; + } + return this; } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", this.id) - .add("actor", this.actor) - .add("verb", this.verb) - .add("object", this.object) - .add("foreignID", this.foreignID) - .add("target", this.target) - .add("time", this.time) - .add("origin", this.origin) - .add("to", this.to) - .add("score", this.score) - .add("extra", this.extra) - .toString(); + @JsonIgnore + public Builder fromActivity(Activity activity) { + this.id = activity.id; + this.actor = activity.actor; + this.verb = activity.verb; + this.object = activity.object; + this.foreignID = activity.foreignID; + this.target = activity.target; + this.time = activity.time; + this.origin = activity.origin; + this.to = activity.to; + this.score = activity.score; + this.extra = activity.extra; + return this; } - public static Builder builder() { - return new Builder(); + @JsonIgnore + public Builder fromCustomActivity(T custom) { + return fromActivity(convert(custom, Activity.class)); } - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder { - private String id; - private String actor; - private String verb; - private String object; - private String foreignID; - private String target; - private Date time; - private String origin; - private List to; - private Double score; - private Map extra; - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder actor(String actor) { - this.actor = actor; - return this; - } - - public Builder verb(String verb) { - this.verb = verb; - return this; - } - - public Builder object(String object) { - this.object = object; - return this; - } - - @JsonProperty("foreign_id") - public Builder foreignID(String foreignID) { - this.foreignID = foreignID; - return this; - } - - public Builder target(String target) { - this.target = target; - return this; - } - - @JsonDeserialize(using = DateDeserializer.class) - public Builder time(Date time) { - this.time = time; - return this; - } - - public Builder origin(String origin) { - this.origin = origin; - return this; - } - - @JsonProperty("to") - public Builder to(List to) { - this.to = to; - return this; - } - - @JsonIgnore - public Builder to(Iterable to) { - this.to = Lists.newArrayList(to); - return this; - } - - @JsonIgnore - public Builder to(FeedID... to) { - this.to = Lists.newArrayList(to); - return this; - } - - public Builder score(double score) { - this.score = score; - return this; - } - - @JsonAnySetter - public Builder extraField(String key, Object value) { - if (extra == null) { - extra = Maps.newHashMap(); - } - extra.put(key, value); - return this; - } - - @JsonIgnore - public Builder extra(Map extra) { - if (!extra.isEmpty()) { - this.extra = extra; - } - return this; - } - - @JsonIgnore - public Builder fromActivity(Activity activity) { - this.id = activity.id; - this.actor = activity.actor; - this.verb = activity.verb; - this.object = activity.object; - this.foreignID = activity.foreignID; - this.target = activity.target; - this.time = activity.time; - this.origin = activity.origin; - this.to = activity.to; - this.score = activity.score; - this.extra = activity.extra; - return this; - } - - @JsonIgnore - public Builder fromCustomActivity(T custom) { - return fromActivity(convert(custom, Activity.class)); - } - - public Activity build() { - checkNotNull(actor, "Activity 'actor' field required"); - checkNotNull(verb, "Activity 'verb' field required"); - checkNotNull(object, "Activity 'object' field required"); - - return new Activity(this); - } + public Activity build() { + checkNotNull(actor, "Activity 'actor' field required"); + checkNotNull(verb, "Activity 'verb' field required"); + checkNotNull(object, "Activity 'object' field required"); + + return new Activity(this); } + } } diff --git a/src/main/java/io/getstream/core/models/ActivityUpdate.java b/src/main/java/io/getstream/core/models/ActivityUpdate.java index a8a9a547..a4f90348 100644 --- a/src/main/java/io/getstream/core/models/ActivityUpdate.java +++ b/src/main/java/io/getstream/core/models/ActivityUpdate.java @@ -6,109 +6,112 @@ import com.fasterxml.jackson.annotation.OptBoolean; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; - import java.util.Date; import java.util.List; import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) public class ActivityUpdate { - private final String id; - private final String foreignID; - private final Date time; - private final Map set; - private final List unset; - - ActivityUpdate(Builder builder) { - if (builder.id != null) { - id = builder.id; - foreignID = null; - time = null; - } else { - id = null; - foreignID = builder.foreignID; - time = builder.time; - } - set = builder.set; - unset = builder.unset; + private final String id; + private final String foreignID; + private final Date time; + private final Map set; + private final List unset; + + ActivityUpdate(Builder builder) { + if (builder.id != null) { + id = builder.id; + foreignID = null; + time = null; + } else { + id = null; + foreignID = builder.foreignID; + time = builder.time; + } + set = builder.set; + unset = builder.unset; + } + + public String getID() { + return id; + } + + @JsonProperty("foreign_id") + public String getForeignID() { + return foreignID; + } + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") + public Date getTime() { + return time; + } + + public Map getSet() { + return set; + } + + public List getUnset() { + return unset; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private String id; + private String foreignID; + private Date time; + private Map set; + private List unset; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder foreignID(String foreignID) { + this.foreignID = foreignID; + return this; } - public String getID() { - return id; + public Builder time(Date time) { + this.time = time; + return this; } - @JsonProperty("foreign_id") - public String getForeignID() { - return foreignID; + public Builder foreignIDTimePair(ForeignIDTimePair pair) { + foreignID = pair.getForeignID(); + time = pair.getTime(); + return this; } - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", lenient = OptBoolean.FALSE, timezone = "UTC") - public Date getTime() { - return time; + public Builder set(Map set) { + this.set = ImmutableMap.copyOf(set); + return this; } - public Map getSet() { - return set; + public Builder set(Iterable> set) { + this.set = ImmutableMap.copyOf(set); + return this; } - public List getUnset() { - return unset; + public Builder unset(Iterable unset) { + this.unset = Lists.newArrayList(unset); + return this; } - public static Builder builder() { - return new Builder(); + public Builder unset(String... unset) { + this.unset = Lists.newArrayList(unset); + return this; } - public static final class Builder { - private String id; - private String foreignID; - private Date time; - private Map set; - private List unset; - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder foreignID(String foreignID) { - this.foreignID = foreignID; - return this; - } - - public Builder time(Date time) { - this.time = time; - return this; - } - - public Builder foreignIDTimePair(ForeignIDTimePair pair) { - foreignID = pair.getForeignID(); - time = pair.getTime(); - return this; - } - - public Builder set(Map set) { - this.set = ImmutableMap.copyOf(set); - return this; - } - - public Builder set(Iterable> set) { - this.set = ImmutableMap.copyOf(set); - return this; - } - - public Builder unset(Iterable unset) { - this.unset = Lists.newArrayList(unset); - return this; - } - - public Builder unset(String... unset) { - this.unset = Lists.newArrayList(unset); - return this; - } - - public ActivityUpdate build() { - return new ActivityUpdate(this); - } + public ActivityUpdate build() { + return new ActivityUpdate(this); } + } } diff --git a/src/main/java/io/getstream/core/models/CollectionData.java b/src/main/java/io/getstream/core/models/CollectionData.java index 78daf31a..23183ff4 100644 --- a/src/main/java/io/getstream/core/models/CollectionData.java +++ b/src/main/java/io/getstream/core/models/CollectionData.java @@ -1,104 +1,96 @@ package io.getstream.core.models; +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.base.MoreObjects; import com.google.common.collect.Maps; - import java.util.Map; import java.util.Objects; -import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - public final class CollectionData { - private final String id; - private final String collection; - private final Map data; - - @JsonCreator - public CollectionData( - @JsonProperty("collection") - String collection, - @JsonProperty("id") - String id, - @JsonProperty("data") - Map data) { - this.collection = collection; - this.data = firstNonNull(data, Maps.newHashMap()); - this.id = checkNotNull(id, "ID required"); - } - - public CollectionData() { - this(null, "", null); - } - - public CollectionData(String id) { - this(null, id, null); - } - - public static CollectionData buildFrom(T data) { - return convert(data, CollectionData.class); - } - - public String getID() { - return id; - } - - @JsonIgnore - public String getCollection() { - return collection; - } - - @JsonAnyGetter - public Map getData() { - return data; - } - - @JsonAnySetter - public CollectionData set(String key, T value) { - checkArgument(!"id".equals(key), "Key can't be named 'id'"); - checkNotNull(key, "Key can't be null"); - - data.put(key, value); - return this; - } - - public CollectionData from(T data) { - checkNotNull(data, "Can't extract data from null"); - - Map map = convert(data, new TypeReference>() {}); - for (Map.Entry entry : map.entrySet()) { - set(entry.getKey(), entry.getValue()); - } - return this; - } - - public T get(String key) { - return (T) data.get(checkNotNull(key, "Key can't be null")); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CollectionData collectionData = (CollectionData) o; - return Objects.equals(id, collectionData.id) && - Objects.equals(data, collectionData.data); - } - - @Override - public int hashCode() { - return Objects.hash(id, data); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", this.id) - .add("data", this.data) - .toString(); + private final String id; + private final String collection; + private final Map data; + + @JsonCreator + public CollectionData( + @JsonProperty("collection") String collection, + @JsonProperty("id") String id, + @JsonProperty("data") Map data) { + this.collection = collection; + this.data = firstNonNull(data, Maps.newHashMap()); + this.id = checkNotNull(id, "ID required"); + } + + public CollectionData() { + this(null, "", null); + } + + public CollectionData(String id) { + this(null, id, null); + } + + public static CollectionData buildFrom(T data) { + return convert(data, CollectionData.class); + } + + public String getID() { + return id; + } + + @JsonIgnore + public String getCollection() { + return collection; + } + + @JsonAnyGetter + public Map getData() { + return data; + } + + @JsonAnySetter + public CollectionData set(String key, T value) { + checkArgument(!"id".equals(key), "Key can't be named 'id'"); + checkNotNull(key, "Key can't be null"); + + data.put(key, value); + return this; + } + + public CollectionData from(T data) { + checkNotNull(data, "Can't extract data from null"); + + Map map = convert(data, new TypeReference>() {}); + for (Map.Entry entry : map.entrySet()) { + set(entry.getKey(), entry.getValue()); } + return this; + } + + public T get(String key) { + return (T) data.get(checkNotNull(key, "Key can't be null")); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CollectionData collectionData = (CollectionData) o; + return Objects.equals(id, collectionData.id) && Objects.equals(data, collectionData.data); + } + + @Override + public int hashCode() { + return Objects.hash(id, data); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("id", this.id).add("data", this.data).toString(); + } } diff --git a/src/main/java/io/getstream/core/models/Content.java b/src/main/java/io/getstream/core/models/Content.java index 5600ebc1..c88249d8 100644 --- a/src/main/java/io/getstream/core/models/Content.java +++ b/src/main/java/io/getstream/core/models/Content.java @@ -1,5 +1,9 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonCreator; @@ -7,79 +11,74 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.base.MoreObjects; import com.google.common.collect.Maps; - import java.util.Map; import java.util.Objects; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - public final class Content { - private final String foreignID; - private final Map data = Maps.newHashMap(); - - @JsonCreator - public Content(@JsonProperty("foreign_id") String foreignID) { - this.foreignID = checkNotNull(foreignID, "ID required"); - } - - public static Content buildFrom(T data) { - return convert(data, Content.class); - } - - @JsonProperty("foreign_id") - public String getForeignID() { - return foreignID; - } - - @JsonAnyGetter - public Map getData() { - return data; - } - - @JsonAnySetter - public Content set(String key, T value) { - checkArgument(!"foreignID".equals(key), "Key can't be named 'foreignID'"); - checkNotNull(key, "Key can't be null"); - - data.put(key, value); - return this; - } - - public Content from(T data) { - checkNotNull(data, "Can't extract data from null"); - - Map map = convert(data, new TypeReference>() {}); - for (Map.Entry entry : map.entrySet()) { - set(entry.getKey(), entry.getValue()); - } - return this; - } - - public T get(String key) { - return (T) data.get(checkNotNull(key, "Key can't be null")); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Content collectionData = (Content) o; - return Objects.equals(foreignID, collectionData.foreignID) && - Objects.equals(data, collectionData.data); - } - - @Override - public int hashCode() { - return Objects.hash(foreignID, data); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", this.foreignID) - .add("data", this.data) - .toString(); + private final String foreignID; + private final Map data = Maps.newHashMap(); + + @JsonCreator + public Content(@JsonProperty("foreign_id") String foreignID) { + this.foreignID = checkNotNull(foreignID, "ID required"); + } + + public static Content buildFrom(T data) { + return convert(data, Content.class); + } + + @JsonProperty("foreign_id") + public String getForeignID() { + return foreignID; + } + + @JsonAnyGetter + public Map getData() { + return data; + } + + @JsonAnySetter + public Content set(String key, T value) { + checkArgument(!"foreignID".equals(key), "Key can't be named 'foreignID'"); + checkNotNull(key, "Key can't be null"); + + data.put(key, value); + return this; + } + + public Content from(T data) { + checkNotNull(data, "Can't extract data from null"); + + Map map = convert(data, new TypeReference>() {}); + for (Map.Entry entry : map.entrySet()) { + set(entry.getKey(), entry.getValue()); } + return this; + } + + public T get(String key) { + return (T) data.get(checkNotNull(key, "Key can't be null")); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Content collectionData = (Content) o; + return Objects.equals(foreignID, collectionData.foreignID) + && Objects.equals(data, collectionData.data); + } + + @Override + public int hashCode() { + return Objects.hash(foreignID, data); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", this.foreignID) + .add("data", this.data) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/Data.java b/src/main/java/io/getstream/core/models/Data.java index 75fed5a5..bf778e77 100644 --- a/src/main/java/io/getstream/core/models/Data.java +++ b/src/main/java/io/getstream/core/models/Data.java @@ -1,89 +1,84 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.MoreObjects; import com.google.common.collect.Maps; import io.getstream.core.models.serialization.DataDeserializer; - import java.util.Map; import java.util.Objects; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - @JsonDeserialize(using = DataDeserializer.class) public final class Data { - private final String id; - private final Map data = Maps.newHashMap(); - - public Data(String id) { - this.id = checkNotNull(id, "ID required"); - } - - public Data() { - this(""); - } - - public static Data buildFrom(T data) { - return convert(data, Data.class); - } + private final String id; + private final Map data = Maps.newHashMap(); - public String getID() { - return id; - } - - @JsonAnyGetter - public Map getData() { - return data; - } + public Data(String id) { + this.id = checkNotNull(id, "ID required"); + } - public Data set(String key, T value) { - checkArgument(!"id".equals(key), "Key can't be named 'id'"); - checkNotNull(key, "Key can't be null"); + public Data() { + this(""); + } - data.put(key, value); - return this; - } + public static Data buildFrom(T data) { + return convert(data, Data.class); + } - public Data from(T data) { - return from(convert(data, new TypeReference>() {})); - } + public String getID() { + return id; + } - public Data from(Map map) { - checkNotNull(data, "Can't extract data from null"); + @JsonAnyGetter + public Map getData() { + return data; + } - for (Map.Entry entry : map.entrySet()) { - set(entry.getKey(), entry.getValue()); - } - return this; - } + public Data set(String key, T value) { + checkArgument(!"id".equals(key), "Key can't be named 'id'"); + checkNotNull(key, "Key can't be null"); - public T get(String key) { - return (T) data.get(checkNotNull(key, "Key can't be null")); - } + data.put(key, value); + return this; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Data data = (Data) o; - return Objects.equals(id, data.id) && - Objects.equals(data, data.data); - } + public Data from(T data) { + return from(convert(data, new TypeReference>() {})); + } - @Override - public int hashCode() { - return Objects.hash(id, data); - } + public Data from(Map map) { + checkNotNull(data, "Can't extract data from null"); - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", this.id) - .add("data", this.data) - .toString(); + for (Map.Entry entry : map.entrySet()) { + set(entry.getKey(), entry.getValue()); } + return this; + } + + public T get(String key) { + return (T) data.get(checkNotNull(key, "Key can't be null")); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Data data = (Data) o; + return Objects.equals(id, data.id) && Objects.equals(data, data.data); + } + + @Override + public int hashCode() { + return Objects.hash(id, data); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("id", this.id).add("data", this.data).toString(); + } } diff --git a/src/main/java/io/getstream/core/models/Engagement.java b/src/main/java/io/getstream/core/models/Engagement.java index faace27a..37fa8df7 100644 --- a/src/main/java/io/getstream/core/models/Engagement.java +++ b/src/main/java/io/getstream/core/models/Engagement.java @@ -1,5 +1,8 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -7,204 +10,201 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.common.base.MoreObjects; - import java.util.Date; import java.util.List; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - @JsonInclude(Include.NON_NULL) @JsonDeserialize(builder = Engagement.Builder.class) public class Engagement { - private final String feedID; - private final UserData userData; - private final String label; - private final Content content; - private final Integer boost; - private final Integer position; - private final String location; - private final List features; - private final Date trackedAt; - - private Engagement(Builder builder) { - label = builder.label; - content = builder.content; - boost = builder.boost; - position = builder.position; - feedID = builder.feedID; - location = builder.location; - userData = builder.userData; - features = builder.features; - trackedAt = builder.trackedAt; - } - - public static Builder builder() { - return new Builder(); + private final String feedID; + private final UserData userData; + private final String label; + private final Content content; + private final Integer boost; + private final Integer position; + private final String location; + private final List features; + private final Date trackedAt; + + private Engagement(Builder builder) { + label = builder.label; + content = builder.content; + boost = builder.boost; + position = builder.position; + feedID = builder.feedID; + location = builder.location; + userData = builder.userData; + features = builder.features; + trackedAt = builder.trackedAt; + } + + public static Builder builder() { + return new Builder(); + } + + public String getLabel() { + return label; + } + + public Content getContent() { + return content; + } + + public int getBoost() { + return boost; + } + + public int getPosition() { + return position; + } + + @JsonProperty("feed_id") + public String getFeedID() { + return feedID; + } + + public String getLocation() { + return location; + } + + @JsonProperty("user_data") + public UserData getUserData() { + return userData; + } + + public List getFeatures() { + return features; + } + + @JsonProperty("tracked_at") + public Date getTrackedAt() { + return trackedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Engagement that = (Engagement) o; + return Objects.equals(label, that.label) + && Objects.equals(content, that.content) + && Objects.equals(boost, that.boost) + && Objects.equals(position, that.position) + && Objects.equals(feedID, that.feedID) + && Objects.equals(location, that.location) + && Objects.equals(userData, that.userData) + && Objects.equals(features, that.features) + && Objects.equals(trackedAt, that.trackedAt); + } + + @Override + public int hashCode() { + return Objects.hash( + label, content, boost, position, feedID, location, userData, features, trackedAt); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("label", this.label) + .add("content", this.content) + .add("boost", this.boost) + .add("position", this.position) + .add("feedID", this.feedID) + .add("location", this.location) + .add("userData", this.userData) + .add("features", this.features) + .add("trackedAt", this.trackedAt) + .toString(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static final class Builder { + private String label; + private Content content; + private Integer boost; + private Integer position; + private String feedID; + private String location; + private UserData userData; + private List features; + private Date trackedAt; + + public Builder label(String label) { + this.label = label; + return this; } - public String getLabel() { - return label; + public Builder content(Content content) { + this.content = content; + return this; } - public Content getContent() { - return content; + public Builder boost(int boost) { + this.boost = boost; + return this; } - public int getBoost() { - return boost; - } - - public int getPosition() { - return position; + public Builder position(int position) { + this.position = position; + return this; } @JsonProperty("feed_id") - public String getFeedID() { - return feedID; + public Builder feedID(String feedID) { + this.feedID = feedID; + return this; } - public String getLocation() { - return location; + public Builder location(String location) { + this.location = location; + return this; } @JsonProperty("user_data") - public UserData getUserData() { - return userData; + public Builder userData(UserData userData) { + this.userData = userData; + return this; } - public List getFeatures() { - return features; + public Builder features(List features) { + this.features = features; + return this; } @JsonProperty("tracked_at") - public Date getTrackedAt() { - return trackedAt; + public Builder trackedAt(Date trackedAt) { + this.trackedAt = trackedAt; + return this; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Engagement that = (Engagement) o; - return Objects.equals(label, that.label) && - Objects.equals(content, that.content) && - Objects.equals(boost, that.boost) && - Objects.equals(position, that.position) && - Objects.equals(feedID, that.feedID) && - Objects.equals(location, that.location) && - Objects.equals(userData, that.userData) && - Objects.equals(features, that.features) && - Objects.equals(trackedAt, that.trackedAt); + @JsonIgnore + public Builder fromEngagement(Engagement engagement) { + label = engagement.label; + content = engagement.content; + boost = engagement.boost; + position = engagement.position; + feedID = engagement.feedID; + location = engagement.location; + userData = engagement.userData; + features = engagement.features; + trackedAt = engagement.trackedAt; + return this; } - @Override - public int hashCode() { - return Objects.hash(label, content, boost, position, feedID, location, userData, features, trackedAt); + @JsonIgnore + public Builder fromCustomEngagement(T custom) { + return fromEngagement(convert(custom, Engagement.class)); } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("label", this.label) - .add("content", this.content) - .add("boost", this.boost) - .add("position", this.position) - .add("feedID", this.feedID) - .add("location", this.location) - .add("userData", this.userData) - .add("features", this.features) - .add("trackedAt", this.trackedAt) - .toString(); - } + public Engagement build() { + checkNotNull(feedID, "Engagement 'feedID' field required"); + checkNotNull(userData, "Engagement 'userData' field required"); + checkNotNull(label, "Engagement 'label' field required"); + checkNotNull(content, "Engagement 'content' field required"); - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder { - private String label; - private Content content; - private Integer boost; - private Integer position; - private String feedID; - private String location; - private UserData userData; - private List features; - private Date trackedAt; - - public Builder label(String label) { - this.label = label; - return this; - } - - public Builder content(Content content) { - this.content = content; - return this; - } - - public Builder boost(int boost) { - this.boost = boost; - return this; - } - - public Builder position(int position) { - this.position = position; - return this; - } - - @JsonProperty("feed_id") - public Builder feedID(String feedID) { - this.feedID = feedID; - return this; - } - - public Builder location(String location) { - this.location = location; - return this; - } - - @JsonProperty("user_data") - public Builder userData(UserData userData) { - this.userData = userData; - return this; - } - - public Builder features(List features) { - this.features = features; - return this; - } - - @JsonProperty("tracked_at") - public Builder trackedAt(Date trackedAt) { - this.trackedAt = trackedAt; - return this; - } - - @JsonIgnore - public Builder fromEngagement(Engagement engagement) { - label = engagement.label; - content = engagement.content; - boost = engagement.boost; - position = engagement.position; - feedID = engagement.feedID; - location = engagement.location; - userData = engagement.userData; - features = engagement.features; - trackedAt = engagement.trackedAt; - return this; - } - - @JsonIgnore - public Builder fromCustomEngagement(T custom) { - return fromEngagement(convert(custom, Engagement.class)); - } - - public Engagement build() { - checkNotNull(feedID, "Engagement 'feedID' field required"); - checkNotNull(userData, "Engagement 'userData' field required"); - checkNotNull(label, "Engagement 'label' field required"); - checkNotNull(content, "Engagement 'content' field required"); - - return new Engagement(this); - } + return new Engagement(this); } + } } diff --git a/src/main/java/io/getstream/core/models/EnrichedActivity.java b/src/main/java/io/getstream/core/models/EnrichedActivity.java index 434dd0b8..2fd68f68 100644 --- a/src/main/java/io/getstream/core/models/EnrichedActivity.java +++ b/src/main/java/io/getstream/core/models/EnrichedActivity.java @@ -1,5 +1,8 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -8,336 +11,336 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import io.getstream.core.models.serialization.DateDeserializer; - import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - -//TODO: check which fields could actually be enriched +// TODO: check which fields could actually be enriched @JsonInclude(Include.NON_NULL) @JsonDeserialize(builder = EnrichedActivity.Builder.class) public class EnrichedActivity { - private final String id; - private final Data actor; - private final String verb; - private final Data object; - private final String foreignID; - private final Data target; - //TODO: support Java 8 Date/Time types? - private final Date time; - private final Data origin; - private final List to; - private final Double score; - private final Map reactionCounts; - private final Map> ownReactions; - private final Map> latestReactions; - private final Map extra; - - private EnrichedActivity(Builder builder) { - id = builder.id; - actor = builder.actor; - verb = builder.verb; - object = builder.object; - foreignID = builder.foreignID; - target = builder.target; - time = builder.time; - origin = builder.origin; - to = builder.to; - score = builder.score; - reactionCounts = builder.reactionCounts; - ownReactions = builder.ownReactions; - latestReactions = builder.latestReactions; - extra = builder.extra; + private final String id; + private final Data actor; + private final String verb; + private final Data object; + private final String foreignID; + private final Data target; + // TODO: support Java 8 Date/Time types? + private final Date time; + private final Data origin; + private final List to; + private final Double score; + private final Map reactionCounts; + private final Map> ownReactions; + private final Map> latestReactions; + private final Map extra; + + private EnrichedActivity(Builder builder) { + id = builder.id; + actor = builder.actor; + verb = builder.verb; + object = builder.object; + foreignID = builder.foreignID; + target = builder.target; + time = builder.time; + origin = builder.origin; + to = builder.to; + score = builder.score; + reactionCounts = builder.reactionCounts; + ownReactions = builder.ownReactions; + latestReactions = builder.latestReactions; + extra = builder.extra; + } + + public String getID() { + return id; + } + + public Data getActor() { + return actor; + } + + public String getVerb() { + return verb; + } + + public Data getObject() { + return object; + } + + @JsonProperty("foreign_id") + public String getForeignID() { + return foreignID; + } + + public Data getTarget() { + return target; + } + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") + public Date getTime() { + return time; + } + + public Data getOrigin() { + return origin; + } + + public List getTo() { + return to; + } + + public Double getScore() { + return score; + } + + @JsonIgnore + public Map getReactionCounts() { + return reactionCounts; + } + + @JsonIgnore + public Map> getOwnReactions() { + return ownReactions; + } + + @JsonIgnore + public Map> getLatestReactions() { + return latestReactions; + } + + @JsonAnyGetter + public Map getExtra() { + return extra; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EnrichedActivity activity = (EnrichedActivity) o; + return Objects.equals(id, activity.id) + && Objects.equals(actor, activity.actor) + && Objects.equals(verb, activity.verb) + && Objects.equals(object, activity.object) + && Objects.equals(foreignID, activity.foreignID) + && Objects.equals(target, activity.target) + && Objects.equals(time, activity.time) + && Objects.equals(origin, activity.origin) + && Objects.equals(to, activity.to) + && Objects.equals(score, activity.score) + && Objects.equals(extra, activity.extra); + } + + @Override + public int hashCode() { + return Objects.hash(id, actor, verb, object, foreignID, target, time, origin, to, score, extra); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", this.id) + .add("actor", this.actor) + .add("verb", this.verb) + .add("object", this.object) + .add("foreignID", this.foreignID) + .add("target", this.target) + .add("time", this.time) + .add("origin", this.origin) + .add("to", this.to) + .add("score", this.score) + .add("ownReactions", this.ownReactions) + .add("latestReactions", this.latestReactions) + .add("reactionCounts", this.reactionCounts) + .add("extra", this.extra) + .toString(); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static final class Builder { + private String id; + private Data actor; + private String verb; + private Data object; + private String foreignID; + private Data target; + private Date time; + private Data origin; + private List to; + private Double score; + private Map reactionCounts; + private Map> ownReactions; + private Map> latestReactions; + private Map extra; + + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonIgnore + public Builder actor(String actor) { + this.actor = new Data(actor); + return this; } - public String getID() { - return id; + @JsonProperty("actor") + public Builder actor(Data actor) { + this.actor = actor; + return this; } - public Data getActor() { - return actor; + public Builder verb(String verb) { + this.verb = verb; + return this; } - public String getVerb() { - return verb; + @JsonIgnore + public Builder object(String object) { + this.object = new Data(object); + return this; } - public Data getObject() { - return object; + @JsonProperty("object") + public Builder object(Data object) { + this.object = object; + return this; } @JsonProperty("foreign_id") - public String getForeignID() { - return foreignID; + public Builder foreignID(String foreignID) { + this.foreignID = foreignID; + return this; + } + + @JsonIgnore + public Builder target(String target) { + this.target = new Data(target); + return this; } - public Data getTarget() { - return target; + @JsonProperty("target") + public Builder target(Data target) { + this.target = target; + return this; } - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", lenient = OptBoolean.FALSE, timezone = "UTC") - public Date getTime() { - return time; + @JsonDeserialize(using = DateDeserializer.class) + public Builder time(Date time) { + this.time = time; + return this; } - public Data getOrigin() { - return origin; + @JsonIgnore + public Builder origin(String origin) { + this.origin = new Data(origin); + return this; } - public List getTo() { - return to; + @JsonProperty("origin") + public Builder origin(Data origin) { + this.origin = origin; + return this; } - public Double getScore() { - return score; + @JsonProperty("to") + public Builder to(List to) { + this.to = to; + return this; } @JsonIgnore - public Map getReactionCounts() { - return reactionCounts; + public Builder to(Iterable to) { + this.to = Lists.newArrayList(to); + return this; } @JsonIgnore - public Map> getOwnReactions() { - return ownReactions; + public Builder to(FeedID... to) { + this.to = Lists.newArrayList(to); + return this; } - @JsonIgnore - public Map> getLatestReactions() { - return latestReactions; + public Builder score(double score) { + this.score = score; + return this; + } + + @JsonProperty("own_reactions") + public Builder ownReactions(Map> ownReactions) { + this.ownReactions = ownReactions; + return this; } - @JsonAnyGetter - public Map getExtra() { - return extra; + @JsonProperty("latest_reactions") + public Builder latestReactions(Map> latestReactions) { + this.latestReactions = latestReactions; + return this; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - EnrichedActivity activity = (EnrichedActivity) o; - return Objects.equals(id, activity.id) && - Objects.equals(actor, activity.actor) && - Objects.equals(verb, activity.verb) && - Objects.equals(object, activity.object) && - Objects.equals(foreignID, activity.foreignID) && - Objects.equals(target, activity.target) && - Objects.equals(time, activity.time) && - Objects.equals(origin, activity.origin) && - Objects.equals(to, activity.to) && - Objects.equals(score, activity.score) && - Objects.equals(extra, activity.extra); + @JsonProperty("reaction_counts") + public Builder reactionCounts(Map reactionCounts) { + this.reactionCounts = reactionCounts; + return this; } - @Override - public int hashCode() { - return Objects.hash(id, actor, verb, object, foreignID, target, time, origin, to, score, extra); + @JsonAnySetter + public Builder extraField(String key, Object value) { + if (extra == null) { + extra = Maps.newHashMap(); + } + extra.put(key, value); + return this; } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("id", this.id) - .add("actor", this.actor) - .add("verb", this.verb) - .add("object", this.object) - .add("foreignID", this.foreignID) - .add("target", this.target) - .add("time", this.time) - .add("origin", this.origin) - .add("to", this.to) - .add("score", this.score) - .add("ownReactions", this.ownReactions) - .add("latestReactions", this.latestReactions) - .add("reactionCounts", this.reactionCounts) - .add("extra", this.extra) - .toString(); + @JsonIgnore + public Builder extra(Map extra) { + if (!extra.isEmpty()) { + this.extra = extra; + } + return this; + } + + @JsonIgnore + public Builder fromEnrichedActivity(EnrichedActivity activity) { + this.id = activity.id; + this.actor = activity.actor; + this.verb = activity.verb; + this.object = activity.object; + this.foreignID = activity.foreignID; + this.target = activity.target; + this.time = activity.time; + this.origin = activity.origin; + this.to = activity.to; + this.score = activity.score; + this.ownReactions = activity.ownReactions; + this.latestReactions = activity.latestReactions; + this.reactionCounts = activity.reactionCounts; + this.extra = activity.extra; + return this; } - public static Builder builder() { - return new Builder(); + @JsonIgnore + public Builder fromCustomEnrichedActivity(T custom) { + return fromEnrichedActivity(convert(custom, EnrichedActivity.class)); } - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder { - private String id; - private Data actor; - private String verb; - private Data object; - private String foreignID; - private Data target; - private Date time; - private Data origin; - private List to; - private Double score; - private Map reactionCounts; - private Map> ownReactions; - private Map> latestReactions; - private Map extra; - - public Builder id(String id) { - this.id = id; - return this; - } - - @JsonIgnore - public Builder actor(String actor) { - this.actor = new Data(actor); - return this; - } - - @JsonProperty("actor") - public Builder actor(Data actor) { - this.actor = actor; - return this; - } - - public Builder verb(String verb) { - this.verb = verb; - return this; - } - - @JsonIgnore - public Builder object(String object) { - this.object = new Data(object); - return this; - } - - @JsonProperty("object") - public Builder object(Data object) { - this.object = object; - return this; - } - - @JsonProperty("foreign_id") - public Builder foreignID(String foreignID) { - this.foreignID = foreignID; - return this; - } - - @JsonIgnore - public Builder target(String target) { - this.target = new Data(target); - return this; - } - - @JsonProperty("target") - public Builder target(Data target) { - this.target = target; - return this; - } - - @JsonDeserialize(using = DateDeserializer.class) - public Builder time(Date time) { - this.time = time; - return this; - } - - @JsonIgnore - public Builder origin(String origin) { - this.origin = new Data(origin); - return this; - } - - @JsonProperty("origin") - public Builder origin(Data origin) { - this.origin = origin; - return this; - } - - @JsonProperty("to") - public Builder to(List to) { - this.to = to; - return this; - } - - @JsonIgnore - public Builder to(Iterable to) { - this.to = Lists.newArrayList(to); - return this; - } - - @JsonIgnore - public Builder to(FeedID... to) { - this.to = Lists.newArrayList(to); - return this; - } - - public Builder score(double score) { - this.score = score; - return this; - } - - @JsonProperty("own_reactions") - public Builder ownReactions(Map> ownReactions) { - this.ownReactions = ownReactions; - return this; - } - - @JsonProperty("latest_reactions") - public Builder latestReactions(Map> latestReactions) { - this.latestReactions = latestReactions; - return this; - } - - @JsonProperty("reaction_counts") - public Builder reactionCounts(Map reactionCounts) { - this.reactionCounts = reactionCounts; - return this; - } - - @JsonAnySetter - public Builder extraField(String key, Object value) { - if (extra == null) { - extra = Maps.newHashMap(); - } - extra.put(key, value); - return this; - } - - @JsonIgnore - public Builder extra(Map extra) { - if (!extra.isEmpty()) { - this.extra = extra; - } - return this; - } - - @JsonIgnore - public Builder fromEnrichedActivity(EnrichedActivity activity) { - this.id = activity.id; - this.actor = activity.actor; - this.verb = activity.verb; - this.object = activity.object; - this.foreignID = activity.foreignID; - this.target = activity.target; - this.time = activity.time; - this.origin = activity.origin; - this.to = activity.to; - this.score = activity.score; - this.ownReactions = activity.ownReactions; - this.latestReactions = activity.latestReactions; - this.reactionCounts = activity.reactionCounts; - this.extra = activity.extra; - return this; - } - - @JsonIgnore - public Builder fromCustomEnrichedActivity(T custom) { - return fromEnrichedActivity(convert(custom, EnrichedActivity.class)); - } - - public EnrichedActivity build() { - checkNotNull(actor, "EnrichedActivity 'actor' field required"); - checkNotNull(verb, "EnrichedActivity 'verb' field required"); - checkNotNull(object, "EnrichedActivity 'object' field required"); - - return new EnrichedActivity(this); - } + public EnrichedActivity build() { + checkNotNull(actor, "EnrichedActivity 'actor' field required"); + checkNotNull(verb, "EnrichedActivity 'verb' field required"); + checkNotNull(object, "EnrichedActivity 'object' field required"); + + return new EnrichedActivity(this); } + } } diff --git a/src/main/java/io/getstream/core/models/Feature.java b/src/main/java/io/getstream/core/models/Feature.java index ef7d3481..c41a5fb9 100644 --- a/src/main/java/io/getstream/core/models/Feature.java +++ b/src/main/java/io/getstream/core/models/Feature.java @@ -3,46 +3,44 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.MoreObjects; - import java.util.Objects; public final class Feature { - private final String group; - private final String value; - - @JsonCreator - public Feature(@JsonProperty("group") String group, @JsonProperty("value") String value) { - this.group = group; - this.value = value; - } - - public String getGroup() { - return group; - } - - public String getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Feature feature = (Feature) o; - return Objects.equals(group, feature.group) && - Objects.equals(value, feature.value); - } - - @Override - public int hashCode() { - return Objects.hash(group, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("group", this.group) - .add("value", this.value) - .toString(); - } + private final String group; + private final String value; + + @JsonCreator + public Feature(@JsonProperty("group") String group, @JsonProperty("value") String value) { + this.group = group; + this.value = value; + } + + public String getGroup() { + return group; + } + + public String getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Feature feature = (Feature) o; + return Objects.equals(group, feature.group) && Objects.equals(value, feature.value); + } + + @Override + public int hashCode() { + return Objects.hash(group, value); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("group", this.group) + .add("value", this.value) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/FeedID.java b/src/main/java/io/getstream/core/models/FeedID.java index 680609ca..0af7a5ae 100644 --- a/src/main/java/io/getstream/core/models/FeedID.java +++ b/src/main/java/io/getstream/core/models/FeedID.java @@ -1,62 +1,60 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; - import java.util.Objects; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - @JsonSerialize(using = ToStringSerializer.class) public final class FeedID { - private final String slug; - private final String userID; - - public FeedID(String slug, String userID) { - checkNotNull(slug, "Feed slug can't be null"); - checkArgument(!slug.contains(":"), "Invalid slug"); - checkNotNull(userID, "Feed user ID can't be null"); - checkArgument(!userID.contains(":"), "Invalid user ID"); - - this.slug = slug; - this.userID = userID; - } - - public FeedID(String id) { - checkNotNull(id, "Feed ID can't be null"); - checkArgument(id.contains(":"), "Invalid feed ID"); - - String[] parts = id.split(":"); - checkArgument(parts.length == 2, "Invalid feed ID"); - this.slug = parts[0]; - this.userID = parts[1]; - } - - public String getSlug() { - return slug; - } - - public String getUserID() { - return userID; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FeedID feedID = (FeedID) o; - return Objects.equals(slug, feedID.slug) && - Objects.equals(userID, feedID.userID); - } - - @Override - public int hashCode() { - return Objects.hash(slug, userID); - } - - @Override - public String toString() { - return slug + ':' + userID; - } + private final String slug; + private final String userID; + + public FeedID(String slug, String userID) { + checkNotNull(slug, "Feed slug can't be null"); + checkArgument(!slug.contains(":"), "Invalid slug"); + checkNotNull(userID, "Feed user ID can't be null"); + checkArgument(!userID.contains(":"), "Invalid user ID"); + + this.slug = slug; + this.userID = userID; + } + + public FeedID(String id) { + checkNotNull(id, "Feed ID can't be null"); + checkArgument(id.contains(":"), "Invalid feed ID"); + + String[] parts = id.split(":"); + checkArgument(parts.length == 2, "Invalid feed ID"); + this.slug = parts[0]; + this.userID = parts[1]; + } + + public String getSlug() { + return slug; + } + + public String getUserID() { + return userID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FeedID feedID = (FeedID) o; + return Objects.equals(slug, feedID.slug) && Objects.equals(userID, feedID.userID); + } + + @Override + public int hashCode() { + return Objects.hash(slug, userID); + } + + @Override + public String toString() { + return slug + ':' + userID; + } } diff --git a/src/main/java/io/getstream/core/models/FollowRelation.java b/src/main/java/io/getstream/core/models/FollowRelation.java index 6383b5cc..7c0872d5 100644 --- a/src/main/java/io/getstream/core/models/FollowRelation.java +++ b/src/main/java/io/getstream/core/models/FollowRelation.java @@ -1,55 +1,54 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.MoreObjects; - import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; - @JsonIgnoreProperties(ignoreUnknown = true) public final class FollowRelation { - private final String source; - private final String target; - - @JsonCreator - public FollowRelation(@JsonProperty("feed_id") String source, @JsonProperty("target_id") String target) { - checkNotNull(source, "FollowRelation 'source' field required"); - checkNotNull(target, "FollowRelation 'target' field required"); - - this.source = source; - this.target = target; - } - - public String getSource() { - return this.source; - } - - public String getTarget() { - return this.target; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FollowRelation that = (FollowRelation) o; - return Objects.equals(source, that.source) && - Objects.equals(target, that.target); - } - - @Override - public int hashCode() { - return Objects.hash(source, target); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("source", this.source) - .add("target", this.target) - .toString(); - } + private final String source; + private final String target; + + @JsonCreator + public FollowRelation( + @JsonProperty("feed_id") String source, @JsonProperty("target_id") String target) { + checkNotNull(source, "FollowRelation 'source' field required"); + checkNotNull(target, "FollowRelation 'target' field required"); + + this.source = source; + this.target = target; + } + + public String getSource() { + return this.source; + } + + public String getTarget() { + return this.target; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FollowRelation that = (FollowRelation) o; + return Objects.equals(source, that.source) && Objects.equals(target, that.target); + } + + @Override + public int hashCode() { + return Objects.hash(source, target); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("source", this.source) + .add("target", this.target) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/ForeignIDTimePair.java b/src/main/java/io/getstream/core/models/ForeignIDTimePair.java index 0d8b65fa..f1ebfe78 100644 --- a/src/main/java/io/getstream/core/models/ForeignIDTimePair.java +++ b/src/main/java/io/getstream/core/models/ForeignIDTimePair.java @@ -1,46 +1,44 @@ package io.getstream.core.models; import com.google.common.base.MoreObjects; - import java.util.Date; import java.util.Objects; public final class ForeignIDTimePair { - private final String foreignID; - private final Date time; - - public ForeignIDTimePair(String foreignID, Date time) { - this.foreignID = foreignID; - this.time = time; - } - - public String getForeignID() { - return foreignID; - } - - public Date getTime() { - return time; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ForeignIDTimePair that = (ForeignIDTimePair) o; - return Objects.equals(foreignID, that.foreignID) && - Objects.equals(time, that.time); - } - - @Override - public int hashCode() { - return Objects.hash(foreignID, time); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("foreignID", this.foreignID) - .add("time", this.time) - .toString(); - } + private final String foreignID; + private final Date time; + + public ForeignIDTimePair(String foreignID, Date time) { + this.foreignID = foreignID; + this.time = time; + } + + public String getForeignID() { + return foreignID; + } + + public Date getTime() { + return time; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ForeignIDTimePair that = (ForeignIDTimePair) o; + return Objects.equals(foreignID, that.foreignID) && Objects.equals(time, that.time); + } + + @Override + public int hashCode() { + return Objects.hash(foreignID, time); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("foreignID", this.foreignID) + .add("time", this.time) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/Group.java b/src/main/java/io/getstream/core/models/Group.java index 6759b171..afd3c7e4 100644 --- a/src/main/java/io/getstream/core/models/Group.java +++ b/src/main/java/io/getstream/core/models/Group.java @@ -1,108 +1,99 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.MoreObjects; import io.getstream.core.models.serialization.DateDeserializer; - import java.util.Date; import java.util.List; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; - @JsonIgnoreProperties(ignoreUnknown = true) public class Group { - private final String id; - private final String group; - private final List activities; - private final int actorCount; - private final Date createdAt; - private final Date updatedAt; - - @JsonCreator - public Group( - @JsonProperty("id") - String id, - @JsonProperty("group") - String group, - @JsonProperty("activities") - List activities, - @JsonProperty("actor_count") - int actorCount, - @JsonProperty("created_at") - @JsonDeserialize(using = DateDeserializer.class) - Date createdAt, - @JsonProperty("updated_at") - @JsonDeserialize(using = DateDeserializer.class) - Date updatedAt) { - checkNotNull(id, "Group 'id' field required"); - checkNotNull(group, "Group 'group' field required"); - checkNotNull(activities, "Group 'activities' field required"); - - this.id = id; - this.group = group; - this.activities = activities; - this.actorCount = actorCount; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - } - - public String getID() { - return id; - } - - public String getGroup() { - return group; - } - - public String getGroupID() { - return id + '.' + group; - } - - public List getActivities() { - return activities; - } - - public int getActorCount() { - return actorCount; - } - - public Date getCreatedAt() { - return createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Group that = (Group) o; - return actorCount == that.actorCount && - Objects.equals(id, that.id) && - Objects.equals(group, that.group) && - Objects.equals(activities, that.activities) && - Objects.equals(createdAt, that.createdAt) && - Objects.equals(updatedAt, that.updatedAt); - } - - @Override - public int hashCode() { - return Objects.hash(id, group, activities, actorCount, createdAt, updatedAt); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("activities", this.activities) - .add("actorCount", this.actorCount) - .add("createdAt", this.createdAt) - .add("updatedAt", this.updatedAt) - .toString(); - } + private final String id; + private final String group; + private final List activities; + private final int actorCount; + private final Date createdAt; + private final Date updatedAt; + + @JsonCreator + public Group( + @JsonProperty("id") String id, + @JsonProperty("group") String group, + @JsonProperty("activities") List activities, + @JsonProperty("actor_count") int actorCount, + @JsonProperty("created_at") @JsonDeserialize(using = DateDeserializer.class) Date createdAt, + @JsonProperty("updated_at") @JsonDeserialize(using = DateDeserializer.class) Date updatedAt) { + checkNotNull(id, "Group 'id' field required"); + checkNotNull(group, "Group 'group' field required"); + checkNotNull(activities, "Group 'activities' field required"); + + this.id = id; + this.group = group; + this.activities = activities; + this.actorCount = actorCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public String getID() { + return id; + } + + public String getGroup() { + return group; + } + + public String getGroupID() { + return id + '.' + group; + } + + public List getActivities() { + return activities; + } + + public int getActorCount() { + return actorCount; + } + + public Date getCreatedAt() { + return createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Group that = (Group) o; + return actorCount == that.actorCount + && Objects.equals(id, that.id) + && Objects.equals(group, that.group) + && Objects.equals(activities, that.activities) + && Objects.equals(createdAt, that.createdAt) + && Objects.equals(updatedAt, that.updatedAt); + } + + @Override + public int hashCode() { + return Objects.hash(id, group, activities, actorCount, createdAt, updatedAt); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("activities", this.activities) + .add("actorCount", this.actorCount) + .add("createdAt", this.createdAt) + .add("updatedAt", this.updatedAt) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/Impression.java b/src/main/java/io/getstream/core/models/Impression.java index 8e95841c..b01c6d28 100644 --- a/src/main/java/io/getstream/core/models/Impression.java +++ b/src/main/java/io/getstream/core/models/Impression.java @@ -1,5 +1,8 @@ package io.getstream.core.models; +import static com.google.common.base.Preconditions.checkNotNull; +import static io.getstream.core.utils.Serialization.convert; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -8,186 +11,182 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; - import java.util.Date; import java.util.List; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; -import static io.getstream.core.utils.Serialization.convert; - @JsonInclude(Include.NON_NULL) @JsonDeserialize(builder = Impression.Builder.class) public class Impression { - private final String feedID; - private final UserData userData; - private final List contentList; - private final String position; - private final String location; - private final List features; - private final Date trackedAt; - - private Impression(Builder builder) { - position = builder.position; - feedID = builder.feedID; - location = builder.location; - userData = builder.userData; - contentList = builder.contentList; - features = builder.features; - trackedAt = builder.trackedAt; + private final String feedID; + private final UserData userData; + private final List contentList; + private final String position; + private final String location; + private final List features; + private final Date trackedAt; + + private Impression(Builder builder) { + position = builder.position; + feedID = builder.feedID; + location = builder.location; + userData = builder.userData; + contentList = builder.contentList; + features = builder.features; + trackedAt = builder.trackedAt; + } + + public static Builder builder() { + return new Builder(); + } + + public String getPosition() { + return position; + } + + @JsonProperty("feed_id") + public String getFeedID() { + return feedID; + } + + public String getLocation() { + return location; + } + + @JsonProperty("user_data") + public UserData getUserData() { + return userData; + } + + @JsonProperty("content_list") + public List getContentList() { + return contentList; + } + + public List getFeatures() { + return features; + } + + @JsonProperty("tracked_at") + public Date getTrackedAt() { + return trackedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Impression that = (Impression) o; + return Objects.equals(position, that.position) + && Objects.equals(feedID, that.feedID) + && Objects.equals(location, that.location) + && Objects.equals(userData, that.userData) + && Objects.equals(contentList, that.contentList) + && Objects.equals(features, that.features) + && Objects.equals(trackedAt, that.trackedAt); + } + + @Override + public int hashCode() { + return Objects.hash(position, feedID, location, userData, contentList, features, trackedAt); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("position", this.position) + .add("feedID", this.feedID) + .add("location", this.location) + .add("userData", this.userData) + .add("contentList", this.contentList) + .add("features", this.features) + .add("trackedAt", this.trackedAt) + .toString(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static final class Builder { + private String position; + private String feedID; + private String location; + private UserData userData; + private List contentList; + private List features; + private Date trackedAt; + + public Builder position(String position) { + this.position = position; + return this; } - public static Builder builder() { - return new Builder(); + @JsonProperty("feed_id") + public Builder feedID(String feedID) { + this.feedID = feedID; + return this; } - public String getPosition() { - return position; + public Builder location(String location) { + this.location = location; + return this; } - @JsonProperty("feed_id") - public String getFeedID() { - return feedID; + @JsonProperty("user_data") + public Builder userData(UserData userData) { + this.userData = userData; + return this; } - public String getLocation() { - return location; + @JsonProperty("content_list") + public Builder contentList(List contentList) { + this.contentList = contentList; + return this; } - @JsonProperty("user_data") - public UserData getUserData() { - return userData; + @JsonIgnore + public Builder contentList(Iterable contentList) { + this.contentList = Lists.newArrayList(contentList); + return this; } - @JsonProperty("content_list") - public List getContentList() { - return contentList; + @JsonIgnore + public Builder contentList(Content... contentList) { + this.contentList = Lists.newArrayList(contentList); + return this; } - public List getFeatures() { - return features; + public Builder features(List features) { + this.features = features; + return this; } @JsonProperty("tracked_at") - public Date getTrackedAt() { - return trackedAt; + public Builder trackedAt(Date trackedAt) { + this.trackedAt = trackedAt; + return this; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Impression that = (Impression) o; - return Objects.equals(position, that.position) && - Objects.equals(feedID, that.feedID) && - Objects.equals(location, that.location) && - Objects.equals(userData, that.userData) && - Objects.equals(contentList, that.contentList) && - Objects.equals(features, that.features) && - Objects.equals(trackedAt, that.trackedAt); + @JsonIgnore + public Builder fromImpression(Impression impression) { + position = impression.position; + feedID = impression.feedID; + location = impression.location; + userData = impression.userData; + contentList = impression.contentList; + features = impression.features; + trackedAt = impression.trackedAt; + return this; } - @Override - public int hashCode() { - return Objects.hash(position, feedID, location, userData, contentList, features, trackedAt); + @JsonIgnore + public Builder fromCustomImpression(T custom) { + return fromImpression(convert(custom, Impression.class)); } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("position", this.position) - .add("feedID", this.feedID) - .add("location", this.location) - .add("userData", this.userData) - .add("contentList", this.contentList) - .add("features", this.features) - .add("trackedAt", this.trackedAt) - .toString(); - } + public Impression build() { + checkNotNull(feedID, "Impression 'feedID' field required"); + checkNotNull(userData, "Impression 'userData' field required"); - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder { - private String position; - private String feedID; - private String location; - private UserData userData; - private List contentList; - private List features; - private Date trackedAt; - - public Builder position(String position) { - this.position = position; - return this; - } - - @JsonProperty("feed_id") - public Builder feedID(String feedID) { - this.feedID = feedID; - return this; - } - - public Builder location(String location) { - this.location = location; - return this; - } - - @JsonProperty("user_data") - public Builder userData(UserData userData) { - this.userData = userData; - return this; - } - - @JsonProperty("content_list") - public Builder contentList(List contentList) { - this.contentList = contentList; - return this; - } - - @JsonIgnore - public Builder contentList(Iterable contentList) { - this.contentList = Lists.newArrayList(contentList); - return this; - } - - @JsonIgnore - public Builder contentList(Content... contentList) { - this.contentList = Lists.newArrayList(contentList); - return this; - } - - public Builder features(List features) { - this.features = features; - return this; - } - - @JsonProperty("tracked_at") - public Builder trackedAt(Date trackedAt) { - this.trackedAt = trackedAt; - return this; - } - - @JsonIgnore - public Builder fromImpression(Impression impression) { - position = impression.position; - feedID = impression.feedID; - location = impression.location; - userData = impression.userData; - contentList = impression.contentList; - features = impression.features; - trackedAt = impression.trackedAt; - return this; - } - - @JsonIgnore - public Builder fromCustomImpression(T custom) { - return fromImpression(convert(custom, Impression.class)); - } - - public Impression build() { - checkNotNull(feedID, "Impression 'feedID' field required"); - checkNotNull(userData, "Impression 'userData' field required"); - - return new Impression(this); - } + return new Impression(this); } + } } diff --git a/src/main/java/io/getstream/core/models/NotificationGroup.java b/src/main/java/io/getstream/core/models/NotificationGroup.java index 6c3dbff3..27dd2aae 100644 --- a/src/main/java/io/getstream/core/models/NotificationGroup.java +++ b/src/main/java/io/getstream/core/models/NotificationGroup.java @@ -6,74 +6,62 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.MoreObjects; import io.getstream.core.models.serialization.DateDeserializer; - import java.util.Date; import java.util.List; import java.util.Objects; @JsonIgnoreProperties(ignoreUnknown = true) public class NotificationGroup extends Group { - private final boolean seen; - private final boolean read; + private final boolean seen; + private final boolean read; - @JsonCreator - public NotificationGroup( - @JsonProperty("id") - String id, - @JsonProperty("group") - String group, - @JsonProperty("activities") - List activities, - @JsonProperty("actor_count") - int actorCount, - @JsonProperty("created_at") - @JsonDeserialize(using = DateDeserializer.class) - Date createdAt, - @JsonProperty("updated_at") - @JsonDeserialize(using = DateDeserializer.class) - Date updatedAt, - @JsonProperty("is_seen") - boolean isSeen, - @JsonProperty("is_read") - boolean isRead) { - super(id, group, activities, actorCount, createdAt, updatedAt); + @JsonCreator + public NotificationGroup( + @JsonProperty("id") String id, + @JsonProperty("group") String group, + @JsonProperty("activities") List activities, + @JsonProperty("actor_count") int actorCount, + @JsonProperty("created_at") @JsonDeserialize(using = DateDeserializer.class) Date createdAt, + @JsonProperty("updated_at") @JsonDeserialize(using = DateDeserializer.class) Date updatedAt, + @JsonProperty("is_seen") boolean isSeen, + @JsonProperty("is_read") boolean isRead) { + super(id, group, activities, actorCount, createdAt, updatedAt); - this.seen = isSeen; - this.read = isRead; - } + this.seen = isSeen; + this.read = isRead; + } - public boolean isSeen() { - return seen; - } + public boolean isSeen() { + return seen; + } - public boolean isRead() { - return read; - } + public boolean isRead() { + return read; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - NotificationGroup that = (NotificationGroup) o; - return seen == that.seen && - read == that.read; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + NotificationGroup that = (NotificationGroup) o; + return seen == that.seen && read == that.read; + } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), seen, read); - } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), seen, read); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("activities", getActivities()) - .add("actorCount", getActorCount()) - .add("createdAt", getCreatedAt()) - .add("updatedAt", getUpdatedAt()) - .add("isSeen", seen) - .add("isRead", read) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("activities", getActivities()) + .add("actorCount", getActorCount()) + .add("createdAt", getCreatedAt()) + .add("updatedAt", getUpdatedAt()) + .add("isSeen", seen) + .add("isRead", read) + .toString(); + } } diff --git a/src/main/java/io/getstream/core/models/OGData.java b/src/main/java/io/getstream/core/models/OGData.java index 3fd9d6b2..46f88be4 100644 --- a/src/main/java/io/getstream/core/models/OGData.java +++ b/src/main/java/io/getstream/core/models/OGData.java @@ -3,266 +3,236 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class OGData { - public static class Image { - private final String image; - private final String url; - private final String secureUrl; - private final String width; - private final String height; - private final String type; - private final String alt; - - @JsonCreator - public Image( - @JsonProperty("image") - String image, - @JsonProperty("url") - String url, - @JsonProperty("secure_url") - String secureUrl, - @JsonProperty("width") - String width, - @JsonProperty("height") - String height, - @JsonProperty("type") - String type, - @JsonProperty("alt") - String alt) { - this.image = image; - this.url = url; - this.secureUrl = secureUrl; - this.width = width; - this.height = height; - this.type = type; - this.alt = alt; - } - - public String getImage() { - return image; - } - - public String getURL() { - return url; - } - - public String getSecureUrl() { - return secureUrl; - } - - public String getWidth() { - return width; - } - - public String getHeight() { - return height; - } - - public String getType() { - return type; - } - - public String getAlt() { - return alt; - } + public static class Image { + private final String image; + private final String url; + private final String secureUrl; + private final String width; + private final String height; + private final String type; + private final String alt; + + @JsonCreator + public Image( + @JsonProperty("image") String image, + @JsonProperty("url") String url, + @JsonProperty("secure_url") String secureUrl, + @JsonProperty("width") String width, + @JsonProperty("height") String height, + @JsonProperty("type") String type, + @JsonProperty("alt") String alt) { + this.image = image; + this.url = url; + this.secureUrl = secureUrl; + this.width = width; + this.height = height; + this.type = type; + this.alt = alt; } - public static class Video { - private final String video; - private final String alt; - private final String url; - private final String secureURL; - private final String type; - private final String width; - private final String height; - - @JsonCreator - public Video( - @JsonProperty("video") - String video, - @JsonProperty("alt") - String alt, - @JsonProperty("url") - String url, - @JsonProperty("secure_url") - String secureURL, - @JsonProperty("type") - String type, - @JsonProperty("width") - String width, - @JsonProperty("height") - String height) { - this.video = video; - this.alt = alt; - this.url = url; - this.secureURL = secureURL; - this.type = type; - this.width = width; - this.height = height; - } - - public String getSecureURL() { - return secureURL; - } - - public String getURL() { - return url; - } - - public String getWidth() { - return width; - } - - public String getHeight() { - return height; - } - - public String getType() { - return type; - } - - public String getAlt() { - return alt; - } - - public String getVideo() { - return video; - } + public String getImage() { + return image; } - public static class Audio { - private final String url; - private final String secureURL; - private final String type; - private final String audio; - - @JsonCreator - public Audio( - @JsonProperty("url") - String url, - @JsonProperty("secure_url") - String secureURL, - @JsonProperty("type") - String type, - @JsonProperty("audio") - String audio) { - this.type = type; - this.audio = audio; - this.url = url; - this.secureURL = secureURL; - } - - public String getSecureURL() { - return secureURL; - } - - public String getURL() { - return url; - } - - public String getType() { - return type; - } - - public String getAudio() { - return audio; - } + public String getURL() { + return url; } - private final String title; - private final String type; - private final String description; - private final String determiner; - private final String locale; - private final String siteName; - private final List images; - private final List