Java Client for Bullet-Train. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://bullet-train.io/
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src comments updated Jan 9, 2019
.gitignore
LICENSE
README.md
hero.png
pom.xml

README.md

Bullet Train SDK for Java

Bullet Train allows you to manage feature flags and remote config across multiple projects, environments and organisations.

The SDK for Android and Java applications for https://bullet-train.io/.

Getting Started

Quick Setup

The client library is available from the Central Maven Repository and can be added to your project by many tools:

Maven

Add following dependencies to your project in pom.xml

<dependency>
  <groupId>com.solidstategroup</groupId>
  <artifactId>bullet-train-client</artifactId>
  <version>1.3</version>
</dependency>

Gradle

implementation 'com.solidstategroup:bullet-train-client:1.3'

Usage

Retrieving feature flags for your project

For full documentation visit https://docs.bullet-train.io

Sign Up and create account at https://bullet-train.io/

In your application initialise BulletTrain client with your API key

BulletTrainClient bulletClient = BulletTrainClient.newBuilder()
                .setApiKey("YOUR_ENV_API_KEY")
                .build();

To check if feature flag exist and enabled:

boolean featureEnabled = bulletClient.hasFeatureFlag("my_test_feature");
if (featureEnabled) {
    // run the code to execute enabled feature
} else {
    // run the code if feature switched off
}

To get configuration value for feature flag:

String myRemoteConfig = bulletClient.getFeatureFlagValue("my_test_feature");
if (myRemoteConfig != null) {    
    // run the code to use remote config value
} else {
    // run the code without remote config
}

Identifying users

Identifying users allows you to target specific users from the Bullet Train dashboard.

To check if feature exist for given user context:

User user = new User();
user.setIdentifier("bullet_train_sample_user");
boolean featureEnabled = bulletClient.hasFeatureFlag("my_test_feature", user);
if (featureEnabled) {
    // run the code to execute enabled feature for given user
} else {
    // run the code when feature switched off
}

To get configuration value for feature flag for given user context:

String myRemoteConfig = bulletClient.getFeatureFlagValue("my_test_feature", user);
if (myRemoteConfig != null) {    
    // run the code to use remote config value
} else {
    // run the code without remote config
}

To get user traits for given user context:

List<Trait> userTraits = bulletClient.getTraits(user)
if (userTraits != null && userTraits) {    
    // run the code to use user traits
} else {
    // run the code without user traits
}

To get user trait for given user context and specific key:

Trait userTrait = bulletClient.getTrait(user, "cookies_key");
if (userTrait != null) {    
    // run the code to use user trait
} else {
    // run the code without user trait
}

Or get user traits for given user context and specific keys:

 List<Trait> userTraits = bulletClient.getTraits(user, "cookies_key", "other_trait");
if (userTraits != null) {    
    // run the code to use user traits
} else {
    // run the code without user traits
}

To update value for user traits for given user context and specific keys:

 Trait userTrait = bulletClient.getTrait(user, "cookies_key");
if (userTrait != null) {    
    // update value for user trait
    userTrait.setValue("new value");
    Trait updated = bulletClient.updateTrait(user, userTrait);
} else {
    // run the code without user trait
}

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Getting Help

If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.

Get in touch

If you have any questions about our projects you can email projects@solidstategroup.com.