SwooshCloudflare.Subdomains (SwooshCloudflare v0.7.1)

Copy Markdown View Source

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.

Summary

Functions

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

Deletes a sending subdomain by id.

Fetches the DNS records required to verify a sending subdomain.

Fetches a single sending subdomain by id.

Lists the sending subdomains of a zone.

Updates a sending subdomain.

Types

config()

@type config() :: keyword()

result()

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

Functions

create(zone_id, name, config)

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

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

delete(zone_id, id, config)

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

Deletes a sending subdomain by id.

dns_records(zone_id, id, config)

@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(zone_id, id, config)

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

Fetches a single sending subdomain by id.

list(zone_id, config)

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

Lists the sending subdomains of a zone.

update(zone_id, id, config, opts)

@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.