Package com.flagsmith

Class FlagsmithClient

java.lang.Object
com.flagsmith.FlagsmithClient

public class FlagsmithClient
extends Object
A client for Flagsmith API.
  • Method Details

    • newBuilder

      public static FlagsmithClient.Builder newBuilder()
    • updateEnvironment

      public void updateEnvironment()
      Load the environment flags in the environment variable from the API.
    • getEnvironmentFlags

      public Flags getEnvironmentFlags() throws FlagsmithClientError
      Get all the default for flags for the current environment.
      Returns:
      environment flags
      Throws:
      FlagsmithClientError
    • getIdentityFlags

      public Flags getIdentityFlags​(String identifier) throws FlagsmithClientError
      Get all the flags for the current environment for a given identity.
      Parameters:
      identifier - identifier string
      Returns:
      result of flag evaluation for given identity
      Throws:
      FlagsmithClientError
    • getIdentityFlags

      public Flags getIdentityFlags​(String identifier, Map<String,​Object> traits) throws FlagsmithClientError
      Get all the flags for the current environment for a given identity. Will also upsert traits to the Flagsmith API for future evaluations.

      A trait with a value of null will remove the trait from the identity if it exists.

      To specify a transient trait, use the TraitConfig class with isTransient set to true as the trait value.

      Parameters:
      identifier - identifier string
      traits - a map of trait keys to trait values
      Throws:
      FlagsmithClientError
      See Also:
      TraitConfig
    • getIdentityFlags

      public Flags getIdentityFlags​(String identifier, Map<String,​Object> traits, boolean isTransient) throws FlagsmithClientError
      Get all the flags for the current environment for a given identity. Will also upsert traits to the Flagsmith API for future evaluations, if isTransient set to false.

      A trait with a value of null will remove the trait from the identity if it exists.

      To specify a transient trait, use the TraitConfig class with isTransient set to true as the trait value.

      Parameters:
      identifier - identifier string
      traits - a map of trait keys to trait values
      isTransient - set to true to prevent identity persistence
      Returns:
      result of flag evaluation for given identity
      Throws:
      FlagsmithClientError
      See Also:
      TraitConfig
    • getIdentitySegments

      public List<Segment> getIdentitySegments​(String identifier) throws FlagsmithClientError
      Get a list of segments that the given identity is in.
      Parameters:
      identifier - a unique identifier for the identity in the current environment, e.g. email address, username, uuid
      Throws:
      FlagsmithClientError
    • getIdentitySegments

      public List<Segment> getIdentitySegments​(String identifier, Map<String,​Object> traits) throws FlagsmithClientError
      Get a list of segments that the given identity is in.
      Parameters:
      identifier - a unique identifier for the identity in the current environment, e.g. email address, username, uuid
      traits - a dictionary of traits to add / update on the identity in Flagsmith, e.g. {"num_orders": 10}
      Throws:
      FlagsmithClientError
    • close

      public void close()
      Should be called when terminating the client to clean up any resources that need cleaning up.
    • getCache

      public FlagsmithCache getCache()
      Returns a FlagsmithCache cache object that encapsulates methods to manipulate the cache.
      Returns:
      a FlagsmithCache if enabled, otherwise null.