Skip to content

Commit

Permalink
Merge pull request #25 from harness/readme-standardisation
Browse files Browse the repository at this point in the history
Readme standardisation
  • Loading branch information
jcox250 committed Mar 11, 2022
2 parents a4a1c8a + 927d93d commit 27bced0
Showing 1 changed file with 59 additions and 26 deletions.
85 changes: 59 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,72 @@ After dependency has been added, the SDK elements, primarily `CfClient` should b

Class can be accessed as Singleton instance.

```
```c#
using System;
using io.harness.cfsdk.client.dto;
using io.harness.cfsdk.client.api;
using System.Threading;
using Serilog;

/**
* Put the API Key here from your environment
*/
String API_KEY = "YOUR_API_KEY";

config = Config.Builder()
namespace ff_sdk
{
class Program
{
static void Main(string[] args)
{
Config config;

// If you want you can uncoment this configure serilog sink you want and see internal SDK information messages:
// Note you will need to add the following nuget packages:
// - Serilog 2.10.0
// - Serilog.Sinks.Console 4.0.1
// View Serilog docs for more additional information https://github.com/serilog/serilog/wiki/Getting-Started
// Log.Logger = new LoggerConfiguration()
// .MinimumLevel.Debug()
// .WriteTo.Console()
// .CreateLogger();
// Add your API Key here that you created in Harness
String API_KEY = "01ca2527-9f0a-41c4-8ee7-1e150de87f6a";
config = Config.Builder()
.SetPollingInterval(60000)
.SetAnalyticsEnabled()
.SetStreamEnabled(true)
.Build();

/**
* Call to Initialize will start authentication, while await will pause execution
* until initiazition is completed.
*/
await CfClient.Instance.Initialize(API_KEY, config);
/**
* Define you target on which you would like to evaluate
* the featureFlag
*/
Target target = io.harness.cfsdk.client.dto.Target.builder()
.Name("User1") //can change with your target name
.Identifier("user1@example.com") //can change with your target identifier
.build();
CfClient.Instance.Initialize(API_KEY, config);


/**
* Define you target on which you would like to evaluate
* the featureFlag
*/
Target target = io.harness.cfsdk.client.dto.Target.builder()
.Name("User1") //can change with your target name
.Identifier("user1@example.com") //can change with your target identifier
.build();

string yourFlag = "SimpleBool"; // Can change to your flag name
while (true)
{
// If the flag you created in Harness is a boolean flag then use boolVariation.
// If it's a number or string use numberVaraition or stringVariation e.g
//double resultNumber = CfClient.Instance.numberVariation(yourFlag, target, -1.0);
//string resultString = CfClient.Instance.stringVariation(yourFlag, target, "NO VALUE !!!");
bool resultBool = CfClient.Instance.boolVariation(yourFlag, target, false);
Console.WriteLine("Bool value ---->" + resultBool);

Thread.Sleep(10 * 1000);
}
}
}
}
```

Alternativly user can directly instantiate `CfClient`, pass required configration parameters, and initiate authentication process
```
```c#
// Creates instance of a client
var client = new CfClient(API_KEY, Config.Builder().Build());

Expand All @@ -81,7 +114,7 @@ Connector is just a proxy to your data. Currently supported connectors:
* Harness (Used by default)
* Local (used only in development)

```
```c#
LocalConnector connector = new LocalConnector("local");
client = new CfClient(connector);
```
Expand All @@ -92,7 +125,7 @@ For offline support and asynchronous startup of SDK user should use storage inte
When SDK is used without waiting on async methods, and configuration is provided with file storage, then all flags are loaded from last saved configurations.
If there is no flag in a storage then they will be evaluated from defaultValue argument.

```
```c#
FileMapStore fileStore = new FileMapStore("Non-Freemium");
LocalConnector connector = new LocalConnector("local");
client = new CfClient(connector, Config.builder().store(fileStore).build());
Expand All @@ -109,15 +142,15 @@ Use the appropriate method to fetch the desired Evaluation of a certain type.

Library exposes two events for user to subscribe on getting internal notifications.

```
```c#
client.InitializationCompleted += (sender, e) =>
{
// fired when authentication is completed and recent configuration is fetched from server
Console.WriteLine("Notification Initialization Completed");
};
client.EvaluationChanged += (sender, identifier) =>
{
// Fired when fleg value changes.
// Fired when flag value changes.
Console.WriteLine($"Flag changed for {identifier}");
};
```
Expand All @@ -143,7 +176,7 @@ client.EvaluationChanged += (sender, identifier) =>

Metrics API endpoint can be changed like this:

```
```c#
Config.builder()
.EventUrl("METRICS_API_EVENTS_URL")
.build();
Expand Down

0 comments on commit 27bced0

Please sign in to comment.