# `Zexbox.Flags`
[🔗](https://github.com/Intellection/zexbox/blob/main/lib/zexbox/flags.ex#L1)

An Elixir wrapper around the LaunchDarkly Erlang client

To start the client, call `Zexbox.Flags.start/2` when starting your application
with a map of config options and an optional tag:

```elixir
def start(_type, _args) do
  Zexbox.Flags.start()
  ...
end
```

To make sure that the client shuts down, you should call Zexbox.Flags.stop/1
when your application shuts down:

```elixir
def stop(_type, _args) do
  Zexbox.Flags.stop()
  ...
end
```

# `start`

```elixir
@spec start() :: :ok | {:error, atom(), term()}
```

Starts the LaunchDarkly client using the `:flags` application config and the `:default` tag.

## Examples

    iex> Zexbox.Flags.start()
    :ok
    iex> Zexbox.Flags.start()
    {:error, :already_started, #PID<0.602.0>}

# `start`

```elixir
@spec start(tag :: atom()) :: :ok | {:error, atom(), term()}
```

Starts the LaunchDarkly client with the given config or the given tag.

## Examples

    iex> Zexbox.Flags.start(%{sdk_key: "my-sdk-key"})
    :ok
    iex> Zexbox.Flags.start(%{sdk_key: "my-sdk-key"})
    {:error, :already_started, #PID<0.602.0>}
    iex>

# `start`

```elixir
@spec start(config :: map(), tag :: atom()) :: :ok | {:error, atom(), term()}
```

Starts the LaunchDarkly client with the given config and tag.

## Examples

    iex> Zexbox.Flags.start(%{sdk_key: "my-sdk-key"}, :my_tag)
    :ok

    iex> Zexbox.Flags.start(%{sdk_key: "my-sdk-key"}, :my_tag)
    {:error, :already_started, #PID<0.602.0>}

# `stop`

```elixir
@spec stop() :: :ok
```

Stops the ldclient with the default tag.

# `stop`

```elixir
@spec stop(tag :: atom()) :: :ok
```

Stops the ldclient with the given tag.

# `variation`

```elixir
@spec variation(key :: String.t(), context :: map(), default :: any()) :: any()
```

Gets the variation of a flag for the given key, context, and default tag.

## Examples

    iex> Zexbox.Flags.variation("my-flag", %{key: "user-key"}, false)
    true

    iex> Zexbox.Flags.variation("my-flag", %{key: "user-key"}, false)
    {:error, {:not_found, "my-flag"}}

# `variation`

```elixir
@spec variation(key :: String.t(), context :: map(), default :: any(), tag :: atom()) ::
  any()
```

Gets the variation of a flag for the given key, context, default value, and tag.

## Examples

    iex> Zexbox.Flags.variation("my-flag", %{key: "user-key"}, false, :my_tag)
    true

    iex> Zexbox.Flags.variation("my-flag", %{key: "user-key"}, false, :my_tag)
    {:error, {:not_found, "my-flag"}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
