GithubHelp home page GithubHelp logo

isabella232 / ff-ruby-server-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harness/ff-ruby-server-sdk

0.0 0.0 0.0 259 KB

Ruby Server SDK for integrating with Harness Feature Flag service.

Home Page: https://www.harness.io/

License: Apache License 2.0

Shell 3.74% Ruby 96.26%

ff-ruby-server-sdk's Introduction

Harness CF Ruby Server SDK

Overview


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


Setup

Add the following snippet to your project's Gemfile file:

gem "ff-ruby-server-sdk"

Cloning the SDK repository

In order to clone SDK repository properly perform cloning like in the following example:

git clone --recurse-submodules [email protected]:harness/ff-ruby-server-sdk.git

After dependency has been added, the SDK elements, primarily CfClient should be accessible in the main application.

Initialization

CfClient is a base class that provides all features of the SDK.

We can instantiate by calling the instance method or by using public constructor (making multiple instances).

require 'ff/ruby/server/sdk/api/config'
require 'ff/ruby/server/sdk/dto/target'
require 'ff/ruby/server/sdk/api/cf_client'
require 'ff/ruby/server/sdk/api/config_builder'

client = CfClient.instance

key = "YOUR_API_KEY_GOES_HERE"

logger = Logger.new(STDOUT)

# Or saving logs into the filesystem with daily rotation:
# logger = Logger.new("example.log", "daily")

config = ConfigBuilder.new
                      .logger(logger)
                      .build

client.init(key, config)

config.logger.debug 'We will wait for the initialization'

client.wait_for_initialization

config.logger.debug 'Initialization is complete'

target = Target.new("YOUR_TARGET_NAME")

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

"YOUR_API_KEY" is an 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:

Instantiate, initialize and close when done:

  • def initialize(api_key = nil, config = nil, connector = nil)
  • def init(api_key = nil, config = nil, connector = nil)
  • def wait_for_initialization
  • def close

Evaluations:

  • def bool_variation(identifier, target, default_value)
  • def string_variation(identifier, target, default_value)
  • def number_variation(identifier, target, default_value)
  • def json_variation(identifier, target, default_value)

Fetch evaluation's value

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

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

Bool variation

bool_result = client.bool_variation(bool_flag, target, false)  

Number variation

number_result = client.number_variation(number_flag, target, -1)  

String variation

string_result = client.string_variation(string_flag, target, "unavailable !!!")  

JSON variation

json_result = client.json_variation(json_flag, target, JSON.parse("{}"))

Using feature flags metrics

Metrics API endpoint can be changed like this (if ever needed):

config = ConfigBuilder.new
                      .event_url("SOME_ENDPOINT_URL")
                      .build

Otherwise, the default metrics endpoint URL will be used.

Connector

This is a new feature that allows you to create or use other connectors. Connector is just a proxy to your data. Currently supported connectors:

  • Harness (the default implementation)
connector = YourConnectorImplementation.new

client.init(

  key,
  config,
  connector
)

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 the close method:

client.close

ff-ruby-server-sdk's People

Contributors

milos85vasic 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.