# `CaptchaFox`
[🔗](https://github.com/CaptchaFox/captchafox-elixir/blob/v1.0.0/lib/captchafox.ex#L1)

Verifies tokens of the CaptchaFox widget with siteverify, with the secret key of a site.

Create a client once with `new/2` and reuse it; it holds no process and can be shared freely.

# `outcome`

```elixir
@type outcome() ::
  {:ok, CaptchaFox.Passed.t() | CaptchaFox.Rejected.t()}
  | {:error, CaptchaFox.UnavailableError.t()}
```

# `t`

```elixir
@opaque t()
```

# `verify_option`

```elixir
@type verify_option() ::
  {:sitekey, String.t() | nil}
  | {:remote_ip, String.t() | :inet.ip_address() | nil}
```

# `new`

```elixir
@spec new(String.t(), [{:timeout, pos_integer()}]) :: t()
```

Creates a client with the secret key of the site.

## Options

  * `:timeout` - how long a verification may take in milliseconds, from connecting to siteverify
    to the end of its answer. Defaults to 5000.

Raises `ArgumentError` if the secret key is empty or no string, or the timeout is no positive integer.

# `verify`

```elixir
@spec verify(t(), String.t() | nil, [verify_option()]) :: outcome()
```

Verifies a token.

Returns `{:ok, %CaptchaFox.Passed{}}` or `{:ok, %CaptchaFox.Rejected{}}` when siteverify evaluated
the token, and `{:error, %CaptchaFox.UnavailableError{}}` when siteverify cannot be evaluated.
An empty or `nil` token is rejected with `missing-input-response` without a request.

## Options

  * `:sitekey` - the site key the token was issued for; not sent when `nil` or empty.
  * `:remote_ip` - the IP address of the visitor, as a string or a tuple such as `conn.remote_ip`;
    not sent when `nil` or empty.

Raises `ArgumentError` if an argument has the wrong type, and `RuntimeError` if the operating system
provides no CA certificates to check the certificate of siteverify with.

---

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