Package com.flagsmith
Class FlagsmithClient
java.lang.Object
com.flagsmith.FlagsmithClient
public class FlagsmithClient extends Object
A client for Flagsmith API.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFlagsmithClient.Builder -
Method Summary
Modifier and Type Method Description voidclose()Should be called when terminating the client to clean up any resources that need cleaning up.FlagsmithCachegetCache()Returns a FlagsmithCache cache object that encapsulates methods to manipulate the cache.FlagsgetEnvironmentFlags()Get all the default for flags for the current environment.FlagsgetIdentityFlags(String identifier)Get all the flags for the current environment for a given identity.FlagsgetIdentityFlags(String identifier, Map<String,Object> traits)Get all the flags for the current environment for a given identity.FlagsgetIdentityFlags(String identifier, Map<String,Object> traits, boolean isTransient)Get all the flags for the current environment for a given identity.List<Segment>getIdentitySegments(String identifier)Get a list of segments that the given identity is in.List<Segment>getIdentitySegments(String identifier, Map<String,Object> traits)Get a list of segments that the given identity is in.static FlagsmithClient.BuildernewBuilder()voidupdateEnvironment()Load the environment flags in the environment variable from the API.
-
Method Details
-
newBuilder
-
updateEnvironment
public void updateEnvironment()Load the environment flags in the environment variable from the API. -
getEnvironmentFlags
Get all the default for flags for the current environment.- Returns:
- environment flags
- Throws:
FlagsmithClientError
-
getIdentityFlags
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 FlagsmithClientErrorGet 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 stringtraits- 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 FlagsmithClientErrorGet 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 stringtraits- a map of trait keys to trait valuesisTransient- set to true to prevent identity persistence- Returns:
- result of flag evaluation for given identity
- Throws:
FlagsmithClientError- See Also:
TraitConfig
-
getIdentitySegments
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 FlagsmithClientErrorGet 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, uuidtraits- 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
Returns a FlagsmithCache cache object that encapsulates methods to manipulate the cache.- Returns:
- a FlagsmithCache if enabled, otherwise null.
-