# C\#

## Getting Started

If still not registered, sign up and create an account at [https://koople.io](https://koople.io).

1. Add SDK library&#x20;

{% tabs %}
{% tab title="Package Manager" %}
```
Install-Package koople-sdk -Version 0.1.1
```
{% endtab %}

{% tab title=".NET CLI" %}
```
dotnet add package koople-sdk --version 0.1.1
```
{% endtab %}

{% tab title="PackageReference" %}
```
<PackageReference Include="koople-sdk" Version="0.1.1" />
```
{% endtab %}

{% tab title="Paket CLI" %}
```
paket add koople-sdk --version 0.1.1
```
{% endtab %}
{% endtabs %}

{% hint style="info" %}
Refer to the [Nuget release page](https://www.nuget.org/packages/koople-sdk/) to identify the latest version.
{% endhint %}

2\. Initliaze the SDK

```csharp
var kClient = KClient.Initialize('YOUR_API_KEY');
```

3\. Get your feature flags values

```csharp
var user = KUser.Create('aUserId');
var isEnabled = kClient.IsEnabled('myAwesomeFeature', user);
if (isEnabled) {
    // Do something when the feature is enabled.
} else {
    // Do something when the feature is not enabled.
}
```

Identify users to allow specific targets. See [KUser](#pfuser).

```csharp
var user = KUser.Create('aUserId');
var isEnabled = kClient.IsEnabled('myAwesomeFeature', user);
if (isEnabled) {
    // Do something when the feature is enabled.
} else {
    // Do something when the feature is not enabled.
}
```

## Methods

### Initialize

Use `initialize` to get a validated client object.

| Parameter         | Description                                                                                          |          |
| ----------------- | ---------------------------------------------------------------------------------------------------- | -------- |
| `apiKey`          | The server ApiKey for your project environment.                                                      | required |
| `poolingInterval` | Interval in seconds with which the SDK makes requests to the server to update the evaluation object. | optional |

Interval in seconds with which the SDK makes requests to the server to update the evaluation object. The minimum value is `10` seconds. If the value is less than `10` it will be ignored and automatically set to `10`. The default value is `60` seconds.

```csharp
var fclient = KClient.Initialize('YOUR_API_KEY', 30);
```

### IsEnabled

The `isEnabled` method will return a boolean indicating whether a release toggle is enabled or disabled.

| Name               | Type     |          |
| ------------------ | -------- | -------- |
| `releaseToggleKey` | `string` | required |
| `user`             | `KUser`  | optional |

```csharp
//anonymous evaluation
kClient.IsEnabled('myAwesomeFeature');
```

```csharp
var user = KUser.create('aUserId');
kClient.IsEnabled('myAwesomeFeature', user);
```

The evaluation of an unexistent `releaseToggleKey` will return `false` as an evaluation result.

### ValueOf

The valueOf method will return a value for a remote config. You can pass an optional second parameter that will be used as a fallback if there is no value.

| Name              | Type     |          |
| ----------------- | -------- | -------- |
| `remoteConfigKey` | `string` | required |
| `user`            | `KUser`  | optional |
| `defaultValue`    | `string` | optional |

```csharp
kClient.ValueOf('theme');
// or
kClient.ValueOf('theme', 'defaultValue');
```

```csharp
var user = KUser.Create('aUserId');

kClient.ValueOf('theme', user);
//or
kClient.ValueOf('theme', user, 'defaultValue');
```

## Objects

### KUser

The `KUser` object represents a user with the properties to be evaluated. The properties can be added in the following ways.

| Name         | Type                   |          |
| ------------ | ---------------------- | -------- |
| `identity`   | `string`               | required |
| `attributes` | `List<KUserAttribute>` | optional |

```csharp
var attributes = new[] { 
    new KUserAttribute("age", 17), 
    new KUserAttribute("gender", "male")
};

var kUser = KUser.Create("userId", attributes);
```

The user can be created first for adding attributes later.

```java
var kUser = KUser.Create("userId")
                .With("age", 17)
                .With("gender", "male");
```

Also, the user can be created as an anonymous user.

```csharp
var kUser = KUser.Anonymous();
```

### KUserAttribute

The `KUserAttribute` represents a key-value object to set the name and value of a user attribute.

| Name    | Type     |          |
| ------- | -------- | -------- |
| `name`  | `string` | required |
| `value` | `Object` | required |

{% hint style="info" %}
Value object can be a string, a number or a boolean type.
{% endhint %}

```csharp
new KUserAttribute("age", 17);
new KUserAttribute("gender", "male");
new KUserAttribute("vip", true);
```
