-
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.
Merge pull request #151 from GetStream/moderation
[MOD-195] add moderation endpoints
- Loading branch information
Showing
12 changed files
with
435 additions
and
16 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.getstream.client; | ||
|
||
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.exceptions.StreamException; | ||
import io.getstream.core.http.Response; | ||
import io.getstream.core.http.Token; | ||
import io.getstream.core.utils.Auth; | ||
import java.util.Map; | ||
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); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +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.http.Token; | ||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
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; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.getstream.core.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class APIError { | ||
private String Code; | ||
private String Message; | ||
private String Status; | ||
|
||
public String toString() { | ||
return "{Code='" + Code + "', Message=" + Message + "}"; | ||
} | ||
|
||
// Default constructor | ||
public APIError() {} | ||
|
||
// Constructor with parameters | ||
@JsonCreator | ||
public APIError( | ||
@JsonProperty("code") String code, | ||
@JsonProperty("message") String message, | ||
@JsonProperty("status") String status) { | ||
this.Code = code; | ||
this.Message = message; | ||
this.Status = status; | ||
} | ||
|
||
// Getters | ||
public String getCode() { | ||
return Code; | ||
} | ||
|
||
public String getMessage() { | ||
return Message; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/io/getstream/core/models/ModerationResponse.java
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.getstream.core.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class ModerationResponse { | ||
private String Status; | ||
private String RecommendedAction; | ||
private APIError APIError; | ||
private String OriginFeed; | ||
|
||
// Default constructor | ||
public ModerationResponse() {} | ||
|
||
// Constructor with parameters | ||
@JsonCreator | ||
public ModerationResponse( | ||
@JsonProperty("status") String status, | ||
@JsonProperty("recommended_action") String recommendedAction, | ||
@JsonProperty("api_error") APIError apiError, | ||
@JsonProperty("origin_feed") String originFeed) { | ||
this.Status = status; | ||
this.RecommendedAction = recommendedAction; | ||
this.APIError = apiError; | ||
this.OriginFeed = originFeed; | ||
} | ||
|
||
// Getters | ||
public String getStatus() { | ||
return Status; | ||
} | ||
|
||
public String getRecommendedAction() { | ||
return RecommendedAction; | ||
} | ||
|
||
public APIError getAPIError() { | ||
return APIError; | ||
} | ||
|
||
public String getOriginFeed() { | ||
return OriginFeed; | ||
} | ||
} |
Oops, something went wrong.