All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getstream.core.Moderation Maven / Gradle / Ivy

There is a newer version: 3.15.0
Show newest version
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 flag(
      Token token,
      String entityType,
      String entityId,
      String reportingUser,
      String Reason,
      Map options)
      throws StreamException {
    try {
      final byte[] payload =
          toJSON(
              new Object() {
                public final String user_id = reportingUser;
                public final String entity_type = entityType;
                public final String entity_id = 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);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy