GitHunt
PB

pbazydlo/hobknob-client-net

A .net client library for Hobknob

hobknob-client-net

A .net client library for Hobknob

Installation

Either use the Nuget user interface in Visual Studio, or type the following in to a compatible prompt:

Install-package hobknob-client-net

Usage

var etcdHost = "localhost";
var etcdPort = 4001;
var applicationName = "radApp";
var cacheUpdateInterval = TimeSpan.FromSeconds(180);

var client = new HobknobClientFactory().Create(etcdHost, etcdPort, applicationName, cacheUpdateInterval);

var toggleValue1 = client.GetOrDefault("Feature1", true); // Feature1 is false => false
var toggleValue2 = client.GetOrDefault("Feature2", true); // Feature2 does not exist => true

var toggleValue3 = client.GetOrDefault("DomainFeature1", "com", true); // Feature1/com exists => false
var toggleValue4 = client.GetOrDefault("DomainFeature1", "couk", true); // Feature1/couk does not exist => true

API

HobknobClientFactory().Create(string etcdHost, int etcdPort, string applicationName, TimeSpan cacheUpdateInterval)

Creates a new feature toggle client.

  • etcdHost the host of the Etcd instance
  • etcdPort the port of the Etcd instance
  • applicationName the name of the application used to find feature toggles
  • cacheUpdateInterval interval for the cache update, which loads all the applications toggles into memory

client.GetOrDefault(string featureName, bool defaultValue)

Gets the boolean value of a simple feature toggle if it exists, otherwise return the default value

  • featureName the name of the feature, used with the application name to get the feature toggle value
  • defaultValue the value to return if the feature does not exist
var featureToggleValue = client.GetOrDefault("feature1", false);

client.GetOrDefault(string featureName, string toggleName, bool defaultValue)

Gets the boolean value of a multi feature toggle if it exists, otherwise return the default value

  • featureName the name of the feature
  • toggleName the name of the toggle (used when dealing with multi-features, e.g. Feature1/com)
  • defaultValue the value to return if the feature toggle does not exist
var featureToggleValueForCom = client.GetOrDefault("DomainFeature1", "com", false);

client.CacheUpdated

An event which is raised on each cache update

client.CacheUpdated += (sender, eventArgs) => { console.Write("Updated"); }

client.CacheUpdateFailed

An event which is raised when there is an error updating the cache

client.CacheUpdateFailed += (sender, eventArgs) => { console.Write(eventArgs.Exception.ToString()); }

Building from source

This project uses Grunt to build and create a Nuget package. Run the following in the command line:

npm install
grunt build

There is a file called HobknobClientNet.nuspec which is used to configure the Nuget package. See http://docs.nuget.org/ for more information.

Testing

There are end-to-end tests which can be run via grunt.

These tests require Etcd to be installed locally on port 4001 (this can be done via Vagrant by executing vagrant up in the root directory).

grunt test

Publishing package to Nuget

The grunt plug-in grunt-nuget is used to package and publish nuget packages. To publish this package, run the following:

grunt build
grunt nugetpush:dist

Notes:

  1. The version number in the HobknobClientNet.nuspec file must be incremented on each publish.
  2. You must specify a user auth key to publish to Nuget (see https://github.com/spatools/grunt-nuget/wiki/Key-Options)

Etcd

Feature toggles are stored in Etcd using the following convention:
http://host:port/v2/keys/v1/toggles/applicationName/featureName[/toggleName]