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

io.getstream.client.PersonalizationClient Maven / Gradle / Ivy

There is a newer version: 3.15.0
Show newest version
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 java.util.Map;
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);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy