# `SwooshCloudflare.Subdomains`
[🔗](https://github.com/devaction-labs/swoosh_cloudflare/blob/v0.7.1/lib/swoosh_cloudflare/subdomains.ex#L1)

Manage Cloudflare Email Service sending subdomains.

Sending subdomains are scoped to a zone, so every function takes the `zone_id`
as its first argument. The `config` keyword list is the same as the mailer's;
only `:api_token` is required (`:account_id` is not used here), and
`:base_url` and `:req_options` are honoured as usual.

    config = Application.get_env(:my_app, MyApp.Mailer)
    zone_id = "023e105f4ecef8ad9ca31a8372d0c353"

    {:ok, subdomains} = SwooshCloudflare.Subdomains.list(zone_id, config)
    {:ok, subdomain} = SwooshCloudflare.Subdomains.create(zone_id, "send.example.com", config)
    {:ok, subdomain} = SwooshCloudflare.Subdomains.get(zone_id, subdomain["tag"], config)

    {:ok, _} =
      SwooshCloudflare.Subdomains.update(zone_id, subdomain["tag"], config,
        drop_suppressed_recipients: true,
        preview_enabled: false
      )

    {:ok, records} = SwooshCloudflare.Subdomains.dns_records(zone_id, subdomain["tag"], config)
    {:ok, _} = SwooshCloudflare.Subdomains.delete(zone_id, subdomain["tag"], config)

The `id` argument is the subdomain `"tag"` returned by Cloudflare.

Subdomains are returned as decoded from Cloudflare, with string keys
(`"tag"`, `"name"`, `"enabled"`, `"created"`, `"modified"`, `"dkim_selector"`,
`"return_path_domain"`, `"drop_suppressed_recipients"`, `"preview_enabled"`).

The API token needs permission to edit the zone's Email Sending settings.

Errors use the same shapes as the mailer: `{:error, {status, reason, body}}`,
`{:error, {429, :rate_limited, retry_after}}`, or a network error term.

# `config`

```elixir
@type config() :: keyword()
```

# `result`

```elixir
@type result() :: {:ok, term()} | {:error, term()}
```

# `create`

```elixir
@spec create(String.t(), String.t(), config()) :: result()
```

Creates a sending subdomain with the given `name` (for example `"send.example.com"`).

# `delete`

```elixir
@spec delete(String.t(), String.t(), config()) :: result()
```

Deletes a sending subdomain by id.

# `dns_records`

```elixir
@spec dns_records(String.t(), String.t(), config()) ::
  {:ok, [map()]} | {:error, term()}
```

Fetches the DNS records required to verify a sending subdomain.

Returns `{:ok, [record]}` with each record decoded with string keys.

# `get`

```elixir
@spec get(String.t(), String.t(), config()) :: result()
```

Fetches a single sending subdomain by id.

# `list`

```elixir
@spec list(String.t(), config()) :: {:ok, [map()]} | {:error, term()}
```

Lists the sending subdomains of a zone.

# `update`

```elixir
@spec update(String.t(), String.t(), config(), keyword()) :: result()
```

Updates a sending subdomain.

Options (only given ones are sent): `:drop_suppressed_recipients` and
`:preview_enabled`, both booleans.

---

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