Giter Site home page Giter Site logo

ff-android-client-sdk's Introduction

Harness CF Android SDK

Overview


Harness is a feature management platform that helps teams to build better software and to test features quicker.


Setup

Add following snippet to root project's build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }

In app module's build.gradle file add dependency for Harness's SDK implementation 'io.harness:ff-android-client-sdk:0.0.4'

After this step, the SDK elements, primarily CfClient should be accessible in main application.

Initialization

CfClient is base class that provides all features of SDK. This is singleton and it is acessed with CfClient.getInstance().

val sdkConfiguration = CfConfiguration.builder()
    .baseUrl("BASE_API_URL")
    .pollingInterval(30) //time in seconds
    .enableStream(true)
    .streamUrl("STREAM_URL")
    .build()

val target = Target().identifier("target")

CfClient.getInstance().initialize(context, "YOUR_API_KEY", sdkConfiguration, target)

target represents a desired target for which we want features to be evaluated.

"YOUR_API_KEY" is a authentication key, needed for access to Harness services.

Your Harness SDK is now initialized. Congratulations!!!



Public API Methods

The Public API exposes a few methods that you can utilize:

  • public void initialize(Context context, String clientId, CfConfiguration configuration, CloudCache cloudCache, AuthCallback authCallback)

  • public boolean boolVariation(String evaluationId, boolean defaultValue)

  • public String stringVariation(String evaluationId, String defaultValue)

  • public double numberVariation(String evaluationId, double defaultValue)

  • public JSONObject jsonVariation(String evaluationId, JSONObject defaultValue)

  • public void registerEventsListener(EventsListener listener)

  • public void unregisterEventsListener(EventsListener observer)

  • public void destroy()

Fetch evaluation's value

It is possible to fetch a value for a given evaluation. Evaluation is performed based on different type. In case there is no evaluation with provided id, the default value is returned.

Use appropriate method to fetch the desired Evaluation of a certain type.

boolVariation(String evaluationId, boolean defaultValue)

//get boolean evaluation
val evaluation: Boolean = CfClient.getInstance().boolVariation("demo_evaluation", false)  

numberVariation(String evaluationId, double defaultValue)

//get number evaluation
val numberEvaluation: Double = CfClient.getInstance().numberVariation("demo_number_evaluation", 0)  

stringVariation(String evaluationId, String defaultValue)

//get String evaluation
val stringEvaluation: String = CfClient.getInstance().stringVariation("demo_string_evaluation", "demo_value")  

Register for events

This method provides a way to register a listener for different events that might be triggered by SDK, indicating specific change in SDK itself.

private final EventsListener eventsListener = statusEvent -> {
    if (statusEvent.getEventType() == EVALUATION_CHANGE) {
        Evaluation evaluation = statusEvent.extractPayload();
    }
}

CfClient.getInstance().registerEventsListener(eventsListener)

Triggered event will have one of the following types:

public enum EVENT_TYPE {
        SSE_START, 
        SSE_END, 
        EVALUATION_CHANGE,
        EVALUATION_RELOAD
    }

Following table provides summary on possible event types and corresponding responses.

EVENT_TYPE Response
SSE_START -
SSE_END -
EVALUATION_CHANGE Evaluation
EVALUATION_RELOAD List<Evaluation>

To avoid unexpected behaviour, when listener is not needed anymore, a caller should call CfClient.getInstance().unregisterEventsListener(eventsListener). This way the sdk will remove desired listener from internal list.

Shutting down the SDK

To avoid potential memory leak, when SDK is no longer needed (when the app is closed, for example), a caller should call this method

CfClient.getInstance().destroy()

ff-android-client-sdk's People

Contributors

rushabh-harness avatar tanovicstef92 avatar puneetsar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.