-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
288 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
package io.getstream.client; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import static io.getstream.core.utils.Auth.buildReactionsToken; | ||
import static io.getstream.core.utils.Routes.*; | ||
import static io.getstream.core.utils.Serialization.*; | ||
|
||
import io.getstream.core.Moderation; | ||
import io.getstream.core.StreamBatch; | ||
import io.getstream.core.exceptions.StreamException; | ||
import io.getstream.core.http.HTTPClient; | ||
import io.getstream.core.http.Response; | ||
import io.getstream.core.http.Token; | ||
import io.getstream.core.utils.Auth; | ||
import java8.util.concurrent.CompletableFuture; | ||
import java8.util.concurrent.CompletionException; | ||
import io.getstream.core.http.Response; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
import static io.getstream.core.utils.Auth.buildReactionsToken; | ||
import static io.getstream.core.utils.Routes.*; | ||
|
||
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.Request.buildPost; | ||
import static io.getstream.core.utils.Serialization.*; | ||
import java8.util.concurrent.CompletableFuture; | ||
|
||
public class ModerationClient { | ||
private final String secret; | ||
private final Moderation mod; | ||
|
||
ModerationClient(String secret, Moderation mod) { | ||
this.secret = secret; | ||
this.mod = mod; | ||
} | ||
|
||
public CompletableFuture<Response> flagUser(String flaggedUserId, String reason, Map<String, Object> options)throws StreamException { | ||
return flag("stream:user", flaggedUserId, "", reason, options); | ||
} | ||
|
||
public CompletableFuture<Response> flagActivity(String entityId, String entityCreatorId, String reason, Map<String, Object> options) throws StreamException{ | ||
return flag("stream:feeds:v2:activity", entityId, entityCreatorId, reason, options); | ||
} | ||
|
||
public CompletableFuture<Response> flagReaction(String entityId, String entityCreatorId, String reason, Map<String, Object> options) throws StreamException{ | ||
return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options); | ||
} | ||
|
||
private CompletableFuture<Response> flag(String entityType, String entityId, String entityCreatorId, | ||
String reason, Map<String, Object> options)throws StreamException { | ||
final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE); | ||
return mod.flag(token, entityType, entityId, entityCreatorId, reason, options); | ||
} | ||
private final String secret; | ||
private final Moderation mod; | ||
|
||
ModerationClient(String secret, Moderation mod) { | ||
this.secret = secret; | ||
this.mod = mod; | ||
} | ||
|
||
public CompletableFuture<Response> flagUser( | ||
String flaggedUserId, String reason, Map<String, Object> options) throws StreamException { | ||
return flag("stream:user", flaggedUserId, "", reason, options); | ||
} | ||
|
||
public CompletableFuture<Response> flagActivity( | ||
String entityId, String entityCreatorId, String reason, Map<String, Object> options) | ||
throws StreamException { | ||
return flag("stream:feeds:v2:activity", entityId, entityCreatorId, reason, options); | ||
} | ||
|
||
public CompletableFuture<Response> flagReaction( | ||
String entityId, String entityCreatorId, String reason, Map<String, Object> options) | ||
throws StreamException { | ||
return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options); | ||
} | ||
|
||
private CompletableFuture<Response> flag( | ||
String entityType, | ||
String entityId, | ||
String entityCreatorId, | ||
String reason, | ||
Map<String, Object> options) | ||
throws StreamException { | ||
final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE); | ||
return mod.flag(token, entityType, entityId, entityCreatorId, reason, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
package io.getstream.core; | ||
|
||
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 io.getstream.core.exceptions.StreamException; | ||
import io.getstream.core.http.HTTPClient; | ||
import io.getstream.core.http.Response; | ||
import io.getstream.core.models.Activity; | ||
import java8.util.concurrent.CompletableFuture; | ||
import java8.util.concurrent.CompletionException; | ||
import io.getstream.core.http.Token; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import static io.getstream.core.utils.Routes.*; | ||
|
||
import static io.getstream.core.utils.Request.buildPost; | ||
import static io.getstream.core.utils.Serialization.*; | ||
import java8.util.concurrent.CompletableFuture; | ||
import java8.util.concurrent.CompletionException; | ||
|
||
public class Moderation { | ||
private final String key; | ||
private final URL baseURL; | ||
private final HTTPClient httpClient; | ||
|
||
public Moderation(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 Moderation(String key, URL baseURL, HTTPClient httpClient) { | ||
this.key = key; | ||
this.baseURL = baseURL; | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public CompletableFuture<Response> flag( | ||
Token token, | ||
String entityType, | ||
String entityId, | ||
String entityCreatorId, | ||
String reason, | ||
Map<String, Object> options) | ||
throws StreamException { | ||
try { | ||
final byte[] payload = | ||
toJSON( | ||
new Object() { | ||
public final String UserId = entityCreatorId; | ||
public final String EntityType = entityType; | ||
public final String EntityId = entityId; | ||
public final String Reason = reason; | ||
}); | ||
|
||
final URL url = buildModerationFlagURL(baseURL); | ||
return httpClient.execute(buildPost(url, key, token, payload)); | ||
} catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { | ||
throw new CompletionException(e); | ||
} | ||
|
||
public CompletableFuture<Response> flag(Token token, String entityType, String entityId, String entityCreatorId, | ||
String reason, Map<String, Object> options) throws StreamException { | ||
try { | ||
final byte[] payload = | ||
toJSON( | ||
new Object() { | ||
public final String UserId = entityCreatorId; | ||
public final String EntityType = entityType; | ||
public final String EntityId = entityId; | ||
public final String Reason = reason; | ||
}); | ||
|
||
|
||
final URL url = buildModerationFlagURL(baseURL); | ||
return httpClient.execute(buildPost(url, key, token, payload)); | ||
} catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { | ||
throw new CompletionException(e); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,4 +155,4 @@ public Request build() throws MalformedURLException, URISyntaxException { | |
return new Request(this); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.