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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1,107 changes: 601 additions & 506 deletions example/Example.java

Large diffs are not rendered by default.

1,036 changes: 692 additions & 344 deletions src/main/java/io/getstream/client/AggregatedFeed.java

Large diffs are not rendered by default.

92 changes: 49 additions & 43 deletions src/main/java/io/getstream/client/AnalyticsClient.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
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;
import io.getstream.core.http.Token;
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<Void> trackEngagement(Iterable<Engagement> events) throws StreamException {
return trackEngagement(Iterables.toArray(events, Engagement.class));
}

public CompletableFuture<Void> trackEngagement(Engagement... events) throws StreamException {
final Token token = buildAnalyticsToken(secret, TokenAction.WRITE);
return analytics.trackEngagement(token, events);
}

public CompletableFuture<Void> 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<Impression> impressions, Iterable<Engagement> 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<Void> trackEngagement(Iterable<Engagement> events)
throws StreamException {
return trackEngagement(Iterables.toArray(events, Engagement.class));
}

public CompletableFuture<Void> trackEngagement(Engagement... events) throws StreamException {
final Token token = buildAnalyticsToken(secret, TokenAction.WRITE);
return analytics.trackEngagement(token, events);
}

public CompletableFuture<Void> 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<Impression> impressions, Iterable<Engagement> 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);
}
}
218 changes: 118 additions & 100 deletions src/main/java/io/getstream/client/BatchClient.java
Original file line number Diff line number Diff line change
@@ -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<Void> addToMany(Activity activity, FeedID... feeds) throws StreamException {
final Token token = buildFeedToken(secret, TokenAction.WRITE);
return batch.addToMany(token, activity, feeds);
}

public CompletableFuture<Void> followMany(int activityCopyLimit, FollowRelation... follows) throws StreamException {
final Token token = buildFollowToken(secret, TokenAction.WRITE);
return batch.followMany(token, activityCopyLimit, follows);
}

public CompletableFuture<Void> followMany(int activityCopyLimit, Iterable<FollowRelation> follows) throws StreamException {
return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class));
}

public CompletableFuture<Void> followMany(FollowRelation... follows) throws StreamException {
return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows);
}

public CompletableFuture<Void> followMany(Iterable<FollowRelation> follows) throws StreamException {
return followMany(Iterables.toArray(follows, FollowRelation.class));
}

public CompletableFuture<Void> 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<Void> 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<Void> unfollowMany(UnfollowOperation... unfollows) throws StreamException {
final Token token = buildFollowToken(secret, TokenAction.WRITE);
return batch.unfollowMany(token, unfollows);
}

public CompletableFuture<List<Activity>> getActivitiesByID(Iterable<String> activityIDs) throws StreamException {
return getActivitiesByID(Iterables.toArray(activityIDs, String.class));
}

public CompletableFuture<List<Activity>> getActivitiesByID(String... activityIDs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getActivitiesByID(token, activityIDs);
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(Iterable<String> activityIDs) throws StreamException {
return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class));
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(String... activityIDs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getEnrichedActivitiesByID(token, activityIDs);
}

public CompletableFuture<List<Activity>> getActivitiesByForeignID(Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException {
return getActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class));
}

public CompletableFuture<List<Activity>> getActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getActivitiesByForeignID(token, activityIDTimePairs);
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException {
return getEnrichedActivitiesByForeignID(Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class));
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(ForeignIDTimePair... activityIDTimePairs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs);
}

public CompletableFuture<Void> updateActivities(Iterable<Activity> activities) throws StreamException {
return updateActivities(Iterables.toArray(activities, Activity.class));
}

public CompletableFuture<Void> 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<Void> addToMany(Activity activity, FeedID... feeds)
throws StreamException {
final Token token = buildFeedToken(secret, TokenAction.WRITE);
return batch.addToMany(token, activity, feeds);
}

public CompletableFuture<Void> followMany(int activityCopyLimit, FollowRelation... follows)
throws StreamException {
final Token token = buildFollowToken(secret, TokenAction.WRITE);
return batch.followMany(token, activityCopyLimit, follows);
}

public CompletableFuture<Void> followMany(int activityCopyLimit, Iterable<FollowRelation> follows)
throws StreamException {
return followMany(activityCopyLimit, Iterables.toArray(follows, FollowRelation.class));
}

public CompletableFuture<Void> followMany(FollowRelation... follows) throws StreamException {
return followMany(DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT, follows);
}

public CompletableFuture<Void> followMany(Iterable<FollowRelation> follows)
throws StreamException {
return followMany(Iterables.toArray(follows, FollowRelation.class));
}

public CompletableFuture<Void> 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<Void> 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<Void> unfollowMany(UnfollowOperation... unfollows)
throws StreamException {
final Token token = buildFollowToken(secret, TokenAction.WRITE);
return batch.unfollowMany(token, unfollows);
}

public CompletableFuture<List<Activity>> getActivitiesByID(Iterable<String> activityIDs)
throws StreamException {
return getActivitiesByID(Iterables.toArray(activityIDs, String.class));
}

public CompletableFuture<List<Activity>> getActivitiesByID(String... activityIDs)
throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getActivitiesByID(token, activityIDs);
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(
Iterable<String> activityIDs) throws StreamException {
return getEnrichedActivitiesByID(Iterables.toArray(activityIDs, String.class));
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByID(String... activityIDs)
throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getEnrichedActivitiesByID(token, activityIDs);
}

public CompletableFuture<List<Activity>> getActivitiesByForeignID(
Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException {
return getActivitiesByForeignID(
Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class));
}

public CompletableFuture<List<Activity>> getActivitiesByForeignID(
ForeignIDTimePair... activityIDTimePairs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getActivitiesByForeignID(token, activityIDTimePairs);
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(
Iterable<ForeignIDTimePair> activityIDTimePairs) throws StreamException {
return getEnrichedActivitiesByForeignID(
Iterables.toArray(activityIDTimePairs, ForeignIDTimePair.class));
}

public CompletableFuture<List<EnrichedActivity>> getEnrichedActivitiesByForeignID(
ForeignIDTimePair... activityIDTimePairs) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.READ);
return batch.getEnrichedActivitiesByForeignID(token, activityIDTimePairs);
}

public CompletableFuture<Void> updateActivities(Iterable<Activity> activities)
throws StreamException {
return updateActivities(Iterables.toArray(activities, Activity.class));
}

public CompletableFuture<Void> updateActivities(Activity... activities) throws StreamException {
final Token token = buildActivityToken(secret, TokenAction.WRITE);
return batch.updateActivities(token, activities);
}
}
Loading