Skip to content

Commit

Permalink
New client methods groundwork (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Sep 4, 2023
2 parents 7c5cd23 + b2cf688 commit 7e9453c
Show file tree
Hide file tree
Showing 17 changed files with 273 additions and 86 deletions.
20 changes: 20 additions & 0 deletions src/androidTest/java/fake/SplitClientStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ public Map<String, SplitResult> getTreatmentsWithConfig(List<String> featureFlag
return null;
}

@Override
public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes) {
return null;
}

@Override
public Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes) {
return null;
}

@Override
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes) {
return null;
}

@Override
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes) {
return null;
}

@Override
public void destroy() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.split.android.client.events.SplitEvent;
import io.split.android.client.events.SplitEventTask;
import io.split.android.grammar.Treatments;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,6 +60,26 @@ public SplitResult getTreatmentWithConfig(String featureFlagName, Map<String, Ob
return new SplitResult(Treatments.CONTROL);
}

@Override
public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes) {
return Collections.emptyMap(); //TODO
}

@Override
public Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes) {
return Collections.emptyMap(); //TODO
}

@Override
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes) {
return Collections.emptyMap(); //TODO
}

@Override
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes) {
return Collections.emptyMap(); //TODO
}

@Override
public boolean setAttribute(String attributeName, Object value) {
return true;
Expand Down Expand Up @@ -149,6 +171,4 @@ public boolean track(String eventType, Map<String, Object> properties) {
public boolean track(String eventType, double value, Map<String, Object> properties) {
return false;
}


}
2 changes: 1 addition & 1 deletion src/main/java/io/split/android/client/FilterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String buildQueryString() {
}

@NonNull
public ArrayList<SplitFilter> getGroupedFilter() {
public List<SplitFilter> getGroupedFilter() {
return new ArrayList<>(mFilterGrouper.group(mFilters));
}

Expand Down
143 changes: 89 additions & 54 deletions src/main/java/io/split/android/client/SplitClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.split.android.client;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -50,8 +53,8 @@ public interface SplitClient extends AttributesManager {
* vs. premium plan. Another example is to show a different treatment
* to users created after a certain date.
*
* @param featureFlagName the feature flag we want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @param featureFlagName the feature flag we want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @return the evaluated treatment, the default treatment of this feature flag, or 'control'.
*/
String getTreatment(String featureFlagName, Map<String, Object> attributes);
Expand All @@ -67,10 +70,10 @@ public interface SplitClient extends AttributesManager {
* vs. premium plan. Another example is to show a different treatment
* to users created after a certain date.
*
* @param featureFlagName the feature flag we want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @param featureFlagName the feature flag we want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @return the evaluated treatment, the default treatment of this feature flag, or 'control'
* with its corresponding configurations if it has one.
* with its corresponding configurations if it has one.
*/
SplitResult getTreatmentWithConfig(String featureFlagName, Map<String, Object> attributes);

Expand All @@ -81,8 +84,8 @@ public interface SplitClient extends AttributesManager {
* <p/>
* It can be used to cache treatments you know it won't change very often.
*
* @param featureFlagNames the feature flags you want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @param featureFlagNames the feature flags you want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @return the evaluated treatments, the default treatment of a feature, or 'control'.
*/
Map<String, String> getTreatments(List<String> featureFlagNames, Map<String, Object> attributes);
Expand All @@ -95,13 +98,53 @@ public interface SplitClient extends AttributesManager {
* <p/>
* It can be used to cache treatments you know it won't change very often.
*
* @param featureFlagNames the feature flags you want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @param featureFlagNames the feature flags you want to evaluate. MUST NOT be null.
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty.
* @return the evaluated treatments, the default treatment of a feature flag, or 'control'
* with its corresponding configurations if it has one.
*/
Map<String, SplitResult> getTreatmentsWithConfig(List<String> featureFlagNames, Map<String, Object> attributes);

/**
* This method is useful when you want to determine the treatment of several feature flags
* belonging to a specific Flag Set at the same time.
*
* @param flagSet the Flag Set name that you want to evaluate. Must not be null or empty
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty
* @return a {@link Map} containing for each feature flag the evaluated treatment, the default treatment of this feature flag, or 'control'
*/
Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes);

/**
* This method is useful when you want to determine the treatment of several feature flags
* belonging to a specific list of Flag Sets at the same time.
*
* @param flagSets the Flag Sets names that you want to evaluate. Must not be null or empty
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty
* @return a {@link Map} containing for each feature flag the evaluated treatment, the default treatment of this feature flag, or 'control'
*/
Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes);

/**
* This method is useful when you want to determine the treatment of several feature flags
* belonging to a specific Flag Set
*
* @param flagSet the Flag Set name that you want to evaluate. Must not be null or empty
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty
* @return a {@link Map} containing for each feature flag the evaluated treatment, the default treatment of this feature flag, or 'control'
*/
Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes);

/**
* This method is useful when you want to determine the treatment of several feature flags
* belonging to a specific list of Flag Sets
*
* @param flagSets the Flag Sets names that you want to evaluate. Must not be null or empty
* @param attributes of the customer (user, account etc.) to use in evaluation. Can be null or empty
* @return a {@link Map} containing for each feature flag the evaluated treatment, the default treatment of this feature flag, or 'control'
*/
Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes);

/**
* Destroys the background processes and clears the cache, releasing the resources used by
* any instances of SplitClient or SplitManager generated by the client's parent SplitFactory
Expand All @@ -115,6 +158,7 @@ public interface SplitClient extends AttributesManager {

/**
* Checks if cached data is ready to perform treatment evaluations
*
* @return true if the sdk is ready, if false, calls to getTreatment will return control
*/
boolean isReady();
Expand All @@ -123,118 +167,109 @@ public interface SplitClient extends AttributesManager {

/**
* Enqueue a new event to be sent to Split data collection services.
*
* <p>
* The traffic type used is the one set by trafficType() in SplitClientConfig.
*
* <p>
* Example:
* client.track(“checkout”)
* client.track(“checkout”)
*
* @param eventType the type of the event
*
* @return true if the track was successful, false otherwise
*/
boolean track(String eventType);

/**
* Enqueue a new event to be sent to Split data collection services
*
* <p>
* Example:
* client.track(“account”, “checkout”, 200.00)
* client.track(“account”, “checkout”, 200.00)
*
* @param trafficType the type of the event
* @param eventType the type of the event
* @param value the value of the event
*
* @param eventType the type of the event
* @param value the value of the event
* @return true if the track was successful, false otherwise
*/
boolean track(String trafficType, String eventType, double value);

/**
* Enqueue a new event to be sent to Split data collection services
*
* <p>
* Example:
* client.track(“account”, “checkout”)
* client.track(“account”, “checkout”)
*
* @param trafficType the type of the event
* @param eventType the type of the event
*
* @param eventType the type of the event
* @return true if the track was successful, false otherwise
*/
boolean track(String trafficType, String eventType);

/**
* Enqueue a new event to be sent to Split data collection services
*
* <p>
* The traffic type used is the one set by trafficType() in SplitClientConfig.
* <p>
* Example:
* client.track(“checkout”, 200.00)
* client.track(“checkout”, 200.00)
*
* @param eventType the type of the event
* @param value the value of the event
*
* @param value the value of the event
* @return true if the track was successful, false otherwise
*/
boolean track(String eventType, double value);

/**
* Enqueue a new event to be sent to Split data collection services.
*
* <p>
* The traffic type used is the one set by trafficType() in SplitClientConfig.
*
* <p>
* Example:
* client.track(“checkout”)
* client.track(“checkout”)
*
* @param eventType the type of the event
* @param eventType the type of the event
* @param properties custom user data map
*
* @return true if the track was successful, false otherwise
*/
boolean track(String eventType, Map<String,Object> properties);
boolean track(String eventType, Map<String, Object> properties);

/**
* Enqueue a new event to be sent to Split data collection services
*
* <p>
* Example:
* client.track(“account”, “checkout”, 200.00)
* client.track(“account”, “checkout”, 200.00)
*
* @param trafficType the type of the event
* @param eventType the type of the event
* @param value the value of the event
* @param properties custom user data map
*
* @param eventType the type of the event
* @param value the value of the event
* @param properties custom user data map
* @return true if the track was successful, false otherwise
*/
boolean track(String trafficType, String eventType, double value, Map<String,Object> properties);
boolean track(String trafficType, String eventType, double value, Map<String, Object> properties);

/**
* Enqueue a new event to be sent to split data collection services
*
* <p>
* Example:
* client.track(“account”, “checkout”)
* client.track(“account”, “checkout”)
*
* @param trafficType the type of the event
* @param eventType the type of the event
* @param properties custom user data map
*
* @param eventType the type of the event
* @param properties custom user data map
* @return true if the track was successful, false otherwise
*/
boolean track(String trafficType, String eventType, Map<String,Object> properties);
boolean track(String trafficType, String eventType, Map<String, Object> properties);

/**
* Enqueue a new event to be sent to Split data collection services
*
* <p>
* The traffic type used is the one set by trafficType() in SplitClientConfig.
* <p>
* Example:
* client.track(“checkout”, 200.00)
* client.track(“checkout”, 200.00)
*
* @param eventType the type of the event
* @param value the value of the event
* @param eventType the type of the event
* @param value the value of the event
* @param properties custom user data map
*
* @return true if the track was successful, false otherwise
*/
boolean track(String eventType, double value, Map<String,Object> properties);

boolean track(String eventType, double value, Map<String, Object> properties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import androidx.annotation.NonNull;

import java.util.Set;

import io.split.android.client.api.Key;
import io.split.android.client.attributes.AttributesManagerFactory;
import io.split.android.client.attributes.AttributesManagerFactoryImpl;
Expand Down Expand Up @@ -55,7 +57,8 @@ public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
@NonNull ValidationMessageLogger validationLogger,
@NonNull KeyValidator keyValidator,
@NonNull EventsTracker eventsTracker,
@NonNull ImpressionListener customerImpressionListener) {
@NonNull ImpressionListener customerImpressionListener,
@NonNull Set<String> configuredFlagSets) {
mSplitFactory = checkNotNull(splitFactory);
mClientContainer = checkNotNull(clientContainer);
mConfig = checkNotNull(config);
Expand All @@ -79,7 +82,8 @@ public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
config.labelsEnabled(),
new AttributesMergerImpl(),
mStorageContainer.getTelemetryStorage(),
new EvaluatorImpl(mStorageContainer.getSplitsStorage(), mSplitParser)
new EvaluatorImpl(mStorageContainer.getSplitsStorage(), mSplitParser),
checkNotNull(configuredFlagSets)
);
}

Expand Down
Loading

0 comments on commit 7e9453c

Please sign in to comment.